diff options
Diffstat (limited to 'libbuild2/cxx')
-rw-r--r-- | libbuild2/cxx/init.cxx | 79 | ||||
-rw-r--r-- | libbuild2/cxx/init.hxx | 2 | ||||
-rw-r--r-- | libbuild2/cxx/target.cxx | 28 | ||||
-rw-r--r-- | libbuild2/cxx/target.hxx | 51 |
4 files changed, 133 insertions, 27 deletions
diff --git a/libbuild2/cxx/init.cxx b/libbuild2/cxx/init.cxx index cd5169d..3ca920e 100644 --- a/libbuild2/cxx/init.cxx +++ b/libbuild2/cxx/init.cxx @@ -93,7 +93,7 @@ namespace build2 // Feature flags. // - auto& vp (rs.var_pool ()); + auto& vp (rs.var_pool (true /* public */)); // All qualified. // Similar to config.cxx.std, config.cxx.features.* overrides // cxx.features.*. @@ -194,6 +194,8 @@ namespace build2 // for this mode. So starting from 16 we only enable it in // `experimental`. // + // Note: no /std:c++23 yet as of MSVC 17.6. + // if (v16_11) o = "/std:c++20"; else if (v16_0) @@ -316,12 +318,14 @@ namespace build2 ; else { - // Translate 11 to 0x, 14 to 1y, 17 to 1z, 20 to 2a, and 23 to 2b - // for compatibility with older versions of the compilers. + // Translate 11 to 0x, 14 to 1y, 17 to 1z, 20 to 2a, 23 to 2b, and + // 26 to 2c for compatibility with older versions of the + // compilers. // o = "-std="; - if (*v == "23") o += "c++2b"; + if (*v == "26") o += "c++2c"; + else if (*v == "23") o += "c++2b"; else if (*v == "20") o += "c++2a"; else if (*v == "17") o += "c++1z"; else if (*v == "14") o += "c++1y"; @@ -469,15 +473,20 @@ namespace build2 // Enter all the variables and initialize the module data. // - auto& vp (rs.var_pool ()); + // All the variables we enter are qualified so go straight for the + // public variable pool. + // + auto& vp (rs.var_pool (true /* public */)); cc::config_data d { cc::lang::cxx, "cxx", "c++", + "obj-c++", BUILD2_DEFAULT_CXX, ".ii", + ".mii", hinters, @@ -668,6 +677,9 @@ namespace build2 vp["cc.export.libs"], vp["cc.export.impl_libs"], + vp["cc.pkconfig.include"], + vp["cc.pkconfig.lib"], + vp.insert<string> ("cxx.stdlib"), vp["cc.runtime"], @@ -733,6 +745,9 @@ namespace build2 vp.insert_alias (d.c_module_name, "cxx.module_name"); vp.insert_alias (d.c_importable, "cxx.importable"); + vp.insert_alias (d.c_pkgconfig_include, "cxx.pkgconfig.include"); + vp.insert_alias (d.c_pkgconfig_lib, "cxx.pkgconfig.lib"); + auto& m (extra.set_module (new config_module (move (d)))); m.guess (rs, loc, extra.hints); @@ -772,6 +787,10 @@ namespace build2 nullptr }; + // Note that we don't include S{} here because none of the files we + // compile can plausibly want to include .S. (Maybe in inline assember + // instrcutions?) + // static const target_type* const inc[] = { &hxx::static_type, @@ -781,6 +800,8 @@ namespace build2 &mxx::static_type, &cxx::static_type, &c::static_type, + &mm::static_type, + &m::static_type, nullptr }; @@ -805,7 +826,7 @@ namespace build2 auto& cm ( load_module<config_module> (rs, rs, "cxx.config", loc, extra.hints)); - auto& vp (rs.var_pool ()); + auto& vp (rs.var_pool (true /* public */)); // All qualified. bool modules (cast<bool> (rs["cxx.features.modules"])); @@ -823,7 +844,6 @@ namespace build2 "cxx.compile", "cxx.link", "cxx.install", - "cxx.uninstall", cm.x_info->id.type, cm.x_info->id.variant, @@ -863,12 +883,54 @@ namespace build2 inc }; - auto& m (extra.set_module (new module (move (d)))); + auto& m (extra.set_module (new module (move (d), rs))); m.init (rs, loc, extra.hints, *cm.x_info); return true; } + bool + objcxx_init (scope& rs, + scope& bs, + const location& loc, + bool, + bool, + module_init_extra&) + { + tracer trace ("cxx::objcxx_init"); + l5 ([&]{trace << "for " << bs;}); + + // We only support root loading (which means there can only be one). + // + if (rs != bs) + fail (loc) << "cxx.objcxx module must be loaded in project root"; + + module* mod (rs.find_module<module> ("cxx")); + + if (mod == nullptr) + fail (loc) << "cxx.objcxx module must be loaded after cxx module"; + + // Register the target type and "enable" it in the module. + // + // Note that we must register the target type regardless of whether the + // C++ compiler is capable of compiling Objective-C++. But we enable + // only if it is. + // + // Note: see similar code in the c module. + // + rs.insert_target_type<mm> (); + + // Note that while Objective-C++ is supported by MinGW GCC, it's + // unlikely Clang supports it when targeting MSVC or Emscripten. But + // let's keep the check simple for now. + // + if (mod->ctype == compiler_type::gcc || + mod->ctype == compiler_type::clang) + mod->x_obj = &mm::static_type; + + return true; + } + static const module_functions mod_functions[] = { // NOTE: don't forget to also update the documentation in init.hxx if @@ -876,6 +938,7 @@ namespace build2 {"cxx.guess", nullptr, guess_init}, {"cxx.config", nullptr, config_init}, + {"cxx.objcxx", nullptr, objcxx_init}, {"cxx", nullptr, init}, {nullptr, nullptr, nullptr} }; diff --git a/libbuild2/cxx/init.hxx b/libbuild2/cxx/init.hxx index 094fea4..0e42cbe 100644 --- a/libbuild2/cxx/init.hxx +++ b/libbuild2/cxx/init.hxx @@ -22,6 +22,8 @@ namespace build2 // `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. // extern "C" LIBBUILD2_CXX_SYMEXPORT const module_functions* build2_cxx_load (); diff --git a/libbuild2/cxx/target.cxx b/libbuild2/cxx/target.cxx index 982dcb4..5ead620 100644 --- a/libbuild2/cxx/target.cxx +++ b/libbuild2/cxx/target.cxx @@ -3,10 +3,6 @@ #include <libbuild2/cxx/target.hxx> -#include <libbuild2/context.hxx> - -using namespace std; - namespace build2 { namespace cxx @@ -22,7 +18,7 @@ namespace build2 &target_pattern_var<hxx_ext_def>, nullptr, &file_search, - false + target_type::flag::none }; extern const char ixx_ext_def[] = "ixx"; @@ -36,7 +32,7 @@ namespace build2 &target_pattern_var<ixx_ext_def>, nullptr, &file_search, - false + target_type::flag::none }; extern const char txx_ext_def[] = "txx"; @@ -50,7 +46,7 @@ namespace build2 &target_pattern_var<txx_ext_def>, nullptr, &file_search, - false + target_type::flag::none }; extern const char cxx_ext_def[] = "cxx"; @@ -64,7 +60,7 @@ namespace build2 &target_pattern_var<cxx_ext_def>, nullptr, &file_search, - false + target_type::flag::none }; extern const char mxx_ext_def[] = "mxx"; @@ -78,7 +74,21 @@ namespace build2 &target_pattern_var<mxx_ext_def>, nullptr, &file_search, - false + target_type::flag::none + }; + + extern const char mm_ext_def[] = "mm"; + const target_type mm::static_type + { + "mm", + &cc::static_type, + &target_factory<mm>, + nullptr, /* fixed_extension */ + &target_extension_var<mm_ext_def>, + &target_pattern_var<mm_ext_def>, + nullptr, + &file_search, + target_type::flag::none }; } } diff --git a/libbuild2/cxx/target.hxx b/libbuild2/cxx/target.hxx index cddab68..fc85f75 100644 --- a/libbuild2/cxx/target.hxx +++ b/libbuild2/cxx/target.hxx @@ -18,45 +18,58 @@ namespace build2 { using cc::h; using cc::c; + using cc::m; class LIBBUILD2_CXX_SYMEXPORT hxx: public cc::cc { public: - using cc::cc; + hxx (context& c, dir_path d, dir_path o, string n) + : cc (c, move (d), move (o), move (n)) + { + dynamic_type = &static_type; + } public: static const target_type static_type; - virtual const target_type& dynamic_type () const {return static_type;} }; class LIBBUILD2_CXX_SYMEXPORT ixx: public cc::cc { public: - using cc::cc; + ixx (context& c, dir_path d, dir_path o, string n) + : cc (c, move (d), move (o), move (n)) + { + dynamic_type = &static_type; + } public: static const target_type static_type; - virtual const target_type& dynamic_type () const {return static_type;} }; class LIBBUILD2_CXX_SYMEXPORT txx: public cc::cc { public: - using cc::cc; + txx (context& c, dir_path d, dir_path o, string n) + : cc (c, move (d), move (o), move (n)) + { + dynamic_type = &static_type; + } public: static const target_type static_type; - virtual const target_type& dynamic_type () const {return static_type;} }; class LIBBUILD2_CXX_SYMEXPORT cxx: public cc::cc { public: - using cc::cc; + cxx (context& c, dir_path d, dir_path o, string n) + : cc (c, move (d), move (o), move (n)) + { + dynamic_type = &static_type; + } public: static const target_type static_type; - virtual const target_type& dynamic_type () const {return static_type;} }; // The module interface unit is both like a header (e.g., we need to @@ -67,11 +80,29 @@ namespace build2 class LIBBUILD2_CXX_SYMEXPORT mxx: public cc::cc { public: - using cc::cc; + mxx (context& c, dir_path d, dir_path o, string n) + : cc (c, move (d), move (o), move (n)) + { + dynamic_type = &static_type; + } + + public: + static const target_type static_type; + }; + + // Objective-C++ source file. + // + class LIBBUILD2_CXX_SYMEXPORT mm: public cc::cc + { + public: + mm (context& c, dir_path d, dir_path o, string n) + : cc (c, move (d), move (o), move (n)) + { + dynamic_type = &static_type; + } public: static const target_type static_type; - virtual const target_type& dynamic_type () const {return static_type;} }; } } |