aboutsummaryrefslogtreecommitdiff
path: root/build2/cxx/link.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-07-18 10:26:44 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-07-18 10:26:44 +0200
commit1470c64377bfd29d434261208cd91b001b17c3f4 (patch)
treebd5895127a68016478e23f8f25e78891227a325c /build2/cxx/link.cxx
parentcab2e9ebc2b9985ae0a2e5d6971ace170c2d5651 (diff)
Add standard static/shared macros for imported installed libraries
Diffstat (limited to 'build2/cxx/link.cxx')
-rw-r--r--build2/cxx/link.cxx49
1 files changed, 48 insertions, 1 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 <build2/cxx/link>
-#include <cstdlib> // exit()
+#include <cstdlib> // exit()
#include <butl/path-map>
@@ -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<NAME>_{STATIC,SHARED},
+ // where <name> 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.