From 1470c64377bfd29d434261208cd91b001b17c3f4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 18 Jul 2016 10:26:44 +0200 Subject: Add standard static/shared macros for imported installed libraries --- build2/cxx/link.cxx | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- build2/utility.cxx | 4 ++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/build2/cxx/link.cxx b/build2/cxx/link.cxx index 25e3650..7111aa5 100644 --- a/build2/cxx/link.cxx +++ b/build2/cxx/link.cxx @@ -4,7 +4,7 @@ #include -#include // exit() +#include // exit() #include @@ -384,6 +384,53 @@ namespace build2 if (a == nullptr && s == nullptr) return nullptr; + // Add the "using static/shared library" macro (used, for example, to + // handle DLL export). The absence of either of these macros would mean + // some other build system that cannot distinguish between the two. + // + auto add_macro = [] (target& t, const char* suffix) + { + // If there is already a value, don't add anything, we don't want to + // be accumulating defines nor messing with custom values. + // + auto p (t.vars.insert ("cxx.export.poptions")); + + if (p.second) + { + // The "standard" macro name will be LIB_{STATIC,SHARED}, + // where is the target name. Here we want to strike a balance + // between being unique and not too noisy. + // + string d ("-DLIB"); + + //@@ CASE + + auto upcase = [] (char c) + { + const unsigned char shift ('a' - 'A'); + return c >= 'a' && c <='z' ? c - shift : c; + }; + + transform (t.name.begin (), + t.name.end (), + back_inserter (d), + upcase); + + d += '_'; + d += suffix; + + strings o; + o.push_back (move (d)); + p.first.get () = move (o); + } + }; + + if (a != nullptr) + add_macro (*a, "STATIC"); + + if (s != nullptr) + add_macro (*s, "SHARED"); + if (l) { // Enter the target group. diff --git a/build2/utility.cxx b/build2/utility.cxx index 5fcdebf..15a0aee 100644 --- a/build2/utility.cxx +++ b/build2/utility.cxx @@ -185,7 +185,7 @@ namespace build2 bool find_option (const char* option, const strings& strs, bool) { - //@@ TODO ignore case + //@@ CASE ignore case for (const string& s: strs) { @@ -199,7 +199,7 @@ namespace build2 bool find_option (const char* option, const cstrings& cstrs, bool) { - //@@ TODO ignore case + //@@ CASE ignore case for (const char* s: cstrs) { -- cgit v1.1