diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2023-11-29 09:51:43 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2023-11-29 10:31:50 +0200 |
commit | a738555f02626685f119fe332d4e2e6e9f2581f4 (patch) | |
tree | 7748b525814eae24678787ebe577659be99aad7d /libbuild2/cxx | |
parent | cd95d24f6dc412feb4a46ccfe588bf180cf69ade (diff) |
Add rule for extracting C and C++ predefs
Diffstat (limited to 'libbuild2/cxx')
-rw-r--r-- | libbuild2/cxx/init.cxx | 47 | ||||
-rw-r--r-- | libbuild2/cxx/init.hxx | 12 |
2 files changed, 49 insertions, 10 deletions
diff --git a/libbuild2/cxx/init.cxx b/libbuild2/cxx/init.cxx index 8948e6a..626c795 100644 --- a/libbuild2/cxx/init.cxx +++ b/libbuild2/cxx/init.cxx @@ -957,16 +957,53 @@ namespace build2 return true; } + bool + predefs_init (scope& rs, + scope& bs, + const location& loc, + bool, + bool, + module_init_extra&) + { + tracer trace ("cxx::predefs_init"); + l5 ([&]{trace << "for " << bs;}); + + // We only support root loading (which means there can only be one). + // + if (rs != bs) + fail (loc) << "cxx.predefs module must be loaded in project root"; + + module* mod (rs.find_module<module> ("cxx")); + + if (mod == nullptr) + fail (loc) << "cxx.predefs module must be loaded after cxx module"; + + // Register the cxx.predefs rule. + // + // Why invent a separate module instead of just always registering it in + // the cxx module? The reason is performance: this rule will be called + // for every C++ header. + // + cc::predefs_rule& r (*mod); + + rs.insert_rule<hxx> (perform_update_id, r.rule_name, r); + rs.insert_rule<hxx> (perform_clean_id, r.rule_name, r); + rs.insert_rule<hxx> (configure_update_id, r.rule_name, r); + + return true; + } + static const module_functions mod_functions[] = { // NOTE: don't forget to also update the documentation in init.hxx if // changing anything here. - {"cxx.guess", nullptr, guess_init}, - {"cxx.config", nullptr, config_init}, - {"cxx.objcxx", nullptr, objcxx_init}, - {"cxx", nullptr, init}, - {nullptr, nullptr, nullptr} + {"cxx.guess", nullptr, guess_init}, + {"cxx.config", nullptr, config_init}, + {"cxx.objcxx", nullptr, objcxx_init}, + {"cxx.predefs", nullptr, predefs_init}, + {"cxx", nullptr, init}, + {nullptr, nullptr, nullptr} }; const module_functions* diff --git a/libbuild2/cxx/init.hxx b/libbuild2/cxx/init.hxx index 0e42cbe..5b80fdc 100644 --- a/libbuild2/cxx/init.hxx +++ b/libbuild2/cxx/init.hxx @@ -19,11 +19,13 @@ namespace build2 // // Submodules: // - // `cxx.guess` -- registers and sets some variables. - // `cxx.config` -- loads cxx.guess and sets more variables. - // `cxx` -- loads cxx.config and registers target types and rules. - // `cxx.objcxx` -- registers mm{} target type and enables Objective-C++ - // compilation. + // `cxx.guess` -- registers and sets some variables. + // `cxx.config` -- loads cxx.guess and sets more variables. + // `cxx` -- loads cxx.config and registers target types and rules. + // `cxx.objcxx` -- registers mm{} target type and enables Objective-C++ + // compilation. + // `cxx.predefs` -- registers rule for generating a C++ header with + // predefined compiler macros. Must be loaded after cxx. // extern "C" LIBBUILD2_CXX_SYMEXPORT const module_functions* build2_cxx_load (); |