Also support default_library='both' to make library() build both shared and static libraries. Closes #484pull/2711/head
parent
809f018333
commit
68f9846b7c
8 changed files with 140 additions and 9 deletions
@ -0,0 +1,9 @@ |
||||
## Building both shared and static libraries |
||||
|
||||
A new function `both_libraries()` has been added to build both shared and static |
||||
libraries at the same time. Source files will be compiled only once and object |
||||
files will be reused to build both shared and static libraries, unless |
||||
`b_staticpic` user option or `pic` argument are set to false in which case |
||||
sources will be compiled twice. |
||||
|
||||
The returned `buildtarget` object always represents the shared library. |
@ -0,0 +1,7 @@ |
||||
#include "mylib.h" |
||||
|
||||
DO_EXPORT int retval = 42; |
||||
|
||||
DO_EXPORT int func() { |
||||
return retval; |
||||
} |
@ -0,0 +1,8 @@ |
||||
#include "mylib.h" |
||||
|
||||
DO_IMPORT int func(); |
||||
DO_IMPORT int retval; |
||||
|
||||
int main(int argc, char **arg) { |
||||
return func() == retval ? 0 : 1; |
||||
} |
@ -0,0 +1,12 @@ |
||||
project('both libraries linking test', 'c') |
||||
|
||||
both_libs = both_libraries('mylib', 'libfile.c') |
||||
exe_shared = executable('prog-shared', 'main.c', link_with : both_libs.get_shared_lib()) |
||||
exe_static = executable('prog-static', 'main.c', |
||||
c_args : ['-DSTATIC_COMPILATION'], |
||||
link_with : both_libs.get_static_lib()) |
||||
exe_both = executable('prog-both', 'main.c', link_with : both_libs) |
||||
|
||||
test('runtest-shared', exe_shared) |
||||
test('runtest-static', exe_static) |
||||
test('runtest-both', exe_both) |
@ -0,0 +1,13 @@ |
||||
#pragma once |
||||
|
||||
#ifdef _WIN32 |
||||
#ifdef STATIC_COMPILATION |
||||
#define DO_IMPORT extern |
||||
#else |
||||
#define DO_IMPORT __declspec(dllimport) |
||||
#endif |
||||
#define DO_EXPORT __declspec(dllexport) |
||||
#else |
||||
#define DO_IMPORT extern |
||||
#define DO_EXPORT |
||||
#endif |
Loading…
Reference in new issue