Skip to content

Commit

Permalink
tests: Extend cmake test with -Wl,--version-script
Browse files Browse the repository at this point in the history
This tests that CMake link flags marked as PRIVATE are not propagated
through the generated Meson dependency. -Wl,--version-script is used as
the "poison" here, the build ultimately fails if it appears in the
shared_library() link command.
  • Loading branch information
blue42u authored and eli-schwartz committed Jul 15, 2024
1 parent 6165db8 commit 066cf80
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test cases/cmake/2 advanced/main3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extern void slib();

int main() {
slib();
return 0;
}
2 changes: 2 additions & 0 deletions test cases/cmake/2 advanced/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ sub_sta = sub_pro.dependency('cmModLibStatic')
# Build some files
exe1 = executable('main1', ['main.cpp'], dependencies: [sub_dep])
exe2 = executable('main2', ['main.cpp'], dependencies: [sub_sta])
slib = shared_library('slib', ['slib.cpp'], dependencies: [sub_dep])
exe3 = executable('main3', ['main3.cpp'], link_with: slib)
test('test1', exe1)
test('test2', exe2)

Expand Down
14 changes: 14 additions & 0 deletions test cases/cmake/2 advanced/slib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
#include <cmMod.hpp>
#include "config.h"

#if CONFIG_OPT != 42
#error "Invalid value of CONFIG_OPT"
#endif

using namespace std;

void slib(void) {
cmModClass obj("Hello from lib");
cout << obj.getStr() << endl;
}
7 changes: 7 additions & 0 deletions test cases/cmake/2 advanced/subprojects/cmMod/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ generate_export_header(cmModLib)

set_target_properties(cmModLib PROPERTIES VERSION 1.0.1)

include(CheckLinkerFlag)
check_linker_flag(CXX "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/vers.map" HAS_VER_SCRIPT)
if(HAS_VER_SCRIPT)
target_link_options(cmModLib PRIVATE
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/vers.map")
endif()

add_executable(testEXE main.cpp "${CMAKE_CURRENT_BINARY_DIR}/config.h")

target_link_libraries(cmModLib ZLIB::ZLIB)
Expand Down
7 changes: 7 additions & 0 deletions test cases/cmake/2 advanced/subprojects/cmMod/vers.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
global:
extern "C++" {
cmModClass::*;
};
local: *;
};

0 comments on commit 066cf80

Please sign in to comment.