diff options
| author | Charles Brunet <charles.brunet@optelgroup.com> | 2023-12-13 11:12:00 -0500 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2024-09-06 10:56:44 -0700 |
| commit | 0fc363021e5c2e79a68fb33e60b72b8ffd353875 (patch) | |
| tree | 84f56f6e6eb41c1d74326ae549556c8ba7a0b934 /test cases/common | |
| parent | 2d6915a5983a64b58ecafd1b1dc92e9c48579ff2 (diff) | |
| download | meson-0fc363021e5c2e79a68fb33e60b72b8ffd353875.tar.gz | |
auto select static or shared when linking both_libraries together
Diffstat (limited to 'test cases/common')
7 files changed, 79 insertions, 14 deletions
diff --git a/test cases/common/273 both libraries/meson.build b/test cases/common/273 both libraries/meson.build index b80a9ce7d..de7668ce4 100644 --- a/test cases/common/273 both libraries/meson.build +++ b/test cases/common/273 both libraries/meson.build @@ -7,38 +7,81 @@ project( expected = 0 +with_bl = both_libraries( + 'with_bl', + files('src/both_libraries.c'), + c_shared_args: ['-DEXPORT'], +) + +with_bl_dep = declare_dependency( + link_with: with_bl, +) + + +if get_option('use_dep') + lib_deps = [with_bl_dep] + lib_links = [] +else + lib_deps = [] + lib_links = [with_bl] +endif + + with_library = library( 'with_library', files('src/library.c'), c_shared_args: ['-DEXPORT'], + link_with: lib_links, + dependencies: lib_deps, ) with_library_dep = declare_dependency( link_with: with_library, ) + if get_option('default_library') == 'shared' expected += 1 + if get_option('default_both_libraries') in ['shared', 'auto'] + expected += 1 + endif elif get_option('default_library') == 'both' if get_option('default_both_libraries') in ['shared', 'auto'] + expected += 2 + endif +else + if get_option('default_both_libraries') == 'shared' expected += 1 endif endif +if get_option('use_dep') + main_deps = [with_library_dep] + main_links = [] +else + main_deps = [] + main_links = [with_library] +endif -mainlink = executable( - 'mainlink', +main = executable( + 'main', files('src/main.c'), c_args: [f'-DEXPECTED=@expected@'], - link_with: [with_library], + link_with: main_links, + dependencies: main_deps, ) -test('link with', mainlink) +test('test both libs', main) -maindep = executable( - 'maindep', - files('src/main.c'), - c_args: [f'-DEXPECTED=@expected@'], - dependencies: [with_library_dep], -) -test('use dep', maindep) + +if get_option('default_library') == 'both' and get_option('default_both_libraries') == 'auto' + # With those options, even if the both_libraries defaults to 'shared', + # 'static' version is used when linking to the static part of another both_libraries. + main_static = executable( + 'main_static', + files('src/main.c'), + c_args: [f'-DEXPECTED=0'], + link_with: with_library.get_static_lib(), + ) + test('test static', main_static) +endif diff --git a/test cases/common/273 both libraries/meson.options b/test cases/common/273 both libraries/meson.options new file mode 100644 index 000000000..2e3c357ae --- /dev/null +++ b/test cases/common/273 both libraries/meson.options @@ -0,0 +1 @@ +option('use_dep', type: 'boolean', value: false) diff --git a/test cases/common/273 both libraries/src/both_libraries.c b/test cases/common/273 both libraries/src/both_libraries.c new file mode 100644 index 000000000..ab1bd1fd9 --- /dev/null +++ b/test cases/common/273 both libraries/src/both_libraries.c @@ -0,0 +1,10 @@ +#include "both_libraries.h" + +int both_libraries_function(void) +{ +#if defined EXPORT + return 1; +#else + return 0; +#endif +} diff --git a/test cases/common/273 both libraries/src/both_libraries.h b/test cases/common/273 both libraries/src/both_libraries.h new file mode 100644 index 000000000..39c4c8430 --- /dev/null +++ b/test cases/common/273 both libraries/src/both_libraries.h @@ -0,0 +1,5 @@ +#pragma once + +#include "api.h" + +int API both_libraries_function(void); diff --git a/test cases/common/273 both libraries/src/library.c b/test cases/common/273 both libraries/src/library.c index decdb6ce9..bdd965f7f 100644 --- a/test cases/common/273 both libraries/src/library.c +++ b/test cases/common/273 both libraries/src/library.c @@ -1,10 +1,12 @@ #include "library.h" +#include "both_libraries.h" int library_function(void) { + int sum = both_libraries_function(); #if defined EXPORT - return 1; + return sum + 1; #else - return 0; + return sum; #endif } diff --git a/test cases/common/273 both libraries/src/main.c b/test cases/common/273 both libraries/src/main.c index 340322e45..1b367896d 100644 --- a/test cases/common/273 both libraries/src/main.c +++ b/test cases/common/273 both libraries/src/main.c @@ -4,5 +4,5 @@ int main(void) { int sum = library_function(); - return sum == EXPECTED ? 0 : sum; + return sum == EXPECTED ? 0 : 1; } diff --git a/test cases/common/273 both libraries/test.json b/test cases/common/273 both libraries/test.json index 08aa54790..2aba26e48 100644 --- a/test cases/common/273 both libraries/test.json +++ b/test cases/common/273 both libraries/test.json @@ -10,6 +10,10 @@ { "val": "shared" }, { "val": "static" }, { "val": "auto" } + ], + "use_dep": [ + { "val": false }, + { "val": true } ] } } |
