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 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'build2/cxx/link.cxx') 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. -- cgit v1.1