From f19959de304afaff2b3d539c9bef1f493ede5fbd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 22 Nov 2022 06:27:33 +0200 Subject: Add support for Objective-C/C++ compilation in cc module --- libbuild2/c/init.cxx | 47 +++++++++++++++++++++++++++++++++++++++++++++++ libbuild2/c/init.hxx | 2 ++ libbuild2/c/target.hxx | 1 + 3 files changed, 50 insertions(+) (limited to 'libbuild2/c') diff --git a/libbuild2/c/init.cxx b/libbuild2/c/init.cxx index 0b6c85b..2dbd534 100644 --- a/libbuild2/c/init.cxx +++ b/libbuild2/c/init.cxx @@ -27,6 +27,7 @@ namespace build2 namespace c { using cc::compiler_id; + using cc::compiler_type; using cc::compiler_class; using cc::compiler_info; @@ -164,8 +165,10 @@ namespace build2 "c", "c", + "obj-c", BUILD2_DEFAULT_C, ".i", + ".mi", hinters, @@ -325,6 +328,7 @@ namespace build2 { &h::static_type, &c::static_type, + &m::static_type, nullptr }; @@ -400,6 +404,48 @@ namespace build2 return true; } + bool + objc_init (scope& rs, + scope& bs, + const location& loc, + bool, + bool, + module_init_extra&) + { + tracer trace ("c::objc_init"); + l5 ([&]{trace << "for " << bs;}); + + // We only support root loading (which means there can only be one). + // + if (rs != bs) + fail (loc) << "c.objc module must be loaded in project root"; + + module* mod (rs.find_module ("c")); + + if (mod == nullptr) + fail (loc) << "c.objc module must be loaded after c 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 cxx module. + // + rs.insert_target_type (); + + // 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 = &m::static_type; + + return true; + } + static const module_functions mod_functions[] = { // NOTE: don't forget to also update the documentation in init.hxx if @@ -408,6 +454,7 @@ namespace build2 {"c.guess", nullptr, guess_init}, {"c.config", nullptr, config_init}, {"c", nullptr, init}, + {"c.objc", nullptr, objc_init}, {nullptr, nullptr, nullptr} }; diff --git a/libbuild2/c/init.hxx b/libbuild2/c/init.hxx index 2662bb1..f324c31 100644 --- a/libbuild2/c/init.hxx +++ b/libbuild2/c/init.hxx @@ -22,6 +22,8 @@ namespace build2 // `c.guess` -- registers and sets some variables. // `c.config` -- loads c.guess and sets more variables. // `c` -- loads c.config and registers target types and rules. + // `c.objc` -- registers m{} target type and enables Objective-C + // compilation. // extern "C" LIBBUILD2_C_SYMEXPORT const module_functions* build2_c_load (); diff --git a/libbuild2/c/target.hxx b/libbuild2/c/target.hxx index 333d39f..308bda9 100644 --- a/libbuild2/c/target.hxx +++ b/libbuild2/c/target.hxx @@ -15,6 +15,7 @@ namespace build2 { using cc::h; using cc::c; + using cc::m; } } -- cgit v1.1