From 23827edd998db30dd1f0d6a14f09399aa7d07b69 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 13 May 2021 15:38:53 +0200 Subject: Add ${c,cxx}.find_system_{header,library}() functions --- libbuild2/cc/functions.cxx | 84 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 2 deletions(-) (limited to 'libbuild2/cc/functions.cxx') diff --git a/libbuild2/cc/functions.cxx b/libbuild2/cc/functions.cxx index 760a332..0394524 100644 --- a/libbuild2/cc/functions.cxx +++ b/libbuild2/cc/functions.cxx @@ -53,7 +53,7 @@ namespace build2 const module* m (rs->find_module (d.x)); if (m == nullptr) - fail << f.name << " called without " << d.x << " module being loaded"; + fail << f.name << " called without " << d.x << " module loaded"; // We can assume these are present due to function's types signature. // @@ -108,7 +108,7 @@ namespace build2 const module* m (rs->find_module (d.x)); if (m == nullptr) - fail << f.name << " called without " << d.x << " module being loaded"; + fail << f.name << " called without " << d.x << " module loaded"; // We can assume these are present due to function's types signature. // @@ -226,6 +226,45 @@ namespace build2 m.append_library_options ( *static_cast (ls), r, bs, a, l, la, li); }}); + + // $.find_system_header() + // + // Return the header path if the specified header exists in one of the + // system header search directories and NULL otherwise. System header + // search directories are those that the compiler searches by default + // plus directories specified as part of the compiler mode options (but + // not *.poptions). + // + // Note that this function is not pure. + // + f.insert (".find_system_header", false). + insert ( + [] (const scope* bs, + vector_view vs, + const function_overload& f) -> value + { + const char* x (*reinterpret_cast (&f.data)); + + if (bs == nullptr) + fail << f.name << " called out of scope"; + + const scope* rs (bs->root_scope ()); + + if (rs == nullptr) + fail << f.name << " called out of project"; + + const module* m (rs->find_module (x)); + + if (m == nullptr) + fail << f.name << " called without " << x << " module loaded"; + + // We can assume the argument is present due to function's types + // signature. + // + auto r (m->find_system_header (convert (move (vs[0])))); + return r ? value (move (*r)) : value (nullptr); + }, + x); } void link_rule:: @@ -357,6 +396,47 @@ namespace build2 else fail << t << " is not an object file target"; }}); + + // $.find_system_library() + // + // Return the library path if the specified library exists in one of the + // system library search directories. System library search directories + // are those that the compiler searches by default plus directories + // specified as part of the compiler mode options (but not *.loptions). + // + // The library can be specified in the same form as expected by the + // linker (-lfoo for POSIX, foo.lib for MSVC) or as a complete name. + // + // Note that this function is not pure. + // + f.insert (".find_system_library", false). + insert ( + [] (const scope* bs, + vector_view vs, + const function_overload& f) -> value + { + const char* x (*reinterpret_cast (&f.data)); + + if (bs == nullptr) + fail << f.name << " called out of scope"; + + const scope* rs (bs->root_scope ()); + + if (rs == nullptr) + fail << f.name << " called out of project"; + + const module* m (rs->find_module (x)); + + if (m == nullptr) + fail << f.name << " called without " << x << " module loaded"; + + // We can assume the argument is present due to function's types + // signature. + // + auto r (m->find_system_library (convert (move (vs[0])))); + return r ? value (move (*r)) : value (nullptr); + }, + x); } } } -- cgit v1.1