Skip to content

Commit bb54051

Browse files
committed
dlopen: make sure lib is built before running test
1 parent 4d11a0f commit bb54051

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

doc/modules/ROOT/examples/shared_libs/CMakeLists.txt

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ message(STATUS "Boost.OpenMethod: building shared library examples")
77

88
add_compile_definitions(BOOST_OPENMETHOD_ENABLE_RUNTIME_CHECKS)
99

10+
# All targets output to the same directory so that executables can locate shared
11+
# libraries via boost::dll::program_location().parent_path().
12+
set(shared_libs_output_dir "${CMAKE_CURRENT_BINARY_DIR}")
13+
14+
# Helper: add a CTest fixture that builds a CMake target, so that `ctest` alone
15+
# (without a prior `cmake --build`) still works.
16+
function(openmethod_shared_libs_build_fixture target)
17+
add_test(NAME ${target}-build
18+
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}"
19+
--target ${target} --config $<CONFIG>)
20+
set_tests_properties(${target}-build PROPERTIES FIXTURES_SETUP ${target}-fixture)
21+
endfunction()
22+
1023
# ------------------------------------------------------------------------------
1124
# static linking
1225

@@ -15,21 +28,38 @@ target_link_libraries(boost_openmethod-shared Boost::openmethod)
1528
set_target_properties(boost_openmethod-shared PROPERTIES
1629
ENABLE_EXPORTS ON
1730
OUTPUT_NAME shared
31+
LIBRARY_OUTPUT_DIRECTORY "${shared_libs_output_dir}"
32+
RUNTIME_OUTPUT_DIRECTORY "${shared_libs_output_dir}"
1833
)
1934

2035
add_executable(boost_openmethod-static static_main.cpp)
2136
target_link_libraries(boost_openmethod-static Boost::openmethod Boost::dll boost_openmethod-shared)
22-
add_test(NAME boost_openmethod-static COMMAND boost_openmethod-static)
37+
set_target_properties(boost_openmethod-static PROPERTIES
38+
RUNTIME_OUTPUT_DIRECTORY "${shared_libs_output_dir}"
39+
)
40+
openmethod_shared_libs_build_fixture(boost_openmethod-static)
41+
add_test(NAME boost_openmethod-static
42+
COMMAND "${shared_libs_output_dir}/boost_openmethod-static")
43+
set_tests_properties(boost_openmethod-static PROPERTIES
44+
FIXTURES_REQUIRED boost_openmethod-static-fixture)
2345

2446
# ------------------------------------------------------------------------------
2547
# dynamic loading, direct virtual_ptrs
2648

2749
add_executable(boost_openmethod-dynamic dynamic_main.cpp)
28-
set_target_properties(boost_openmethod-dynamic PROPERTIES ENABLE_EXPORTS ON)
50+
set_target_properties(boost_openmethod-dynamic PROPERTIES
51+
ENABLE_EXPORTS ON
52+
RUNTIME_OUTPUT_DIRECTORY "${shared_libs_output_dir}"
53+
)
2954
target_link_libraries(boost_openmethod-dynamic Boost::openmethod Boost::dll)
3055
add_dependencies(boost_openmethod-dynamic boost_openmethod-shared)
3156
if (NOT WIN32)
32-
add_test(NAME boost_openmethod-dynamic COMMAND boost_openmethod-dynamic)
57+
openmethod_shared_libs_build_fixture(boost_openmethod-shared)
58+
openmethod_shared_libs_build_fixture(boost_openmethod-dynamic)
59+
add_test(NAME boost_openmethod-dynamic
60+
COMMAND "${shared_libs_output_dir}/boost_openmethod-dynamic")
61+
set_tests_properties(boost_openmethod-dynamic PROPERTIES
62+
FIXTURES_REQUIRED "boost_openmethod-shared-fixture;boost_openmethod-dynamic-fixture")
3363
endif()
3464

3565
# ------------------------------------------------------------------------------
@@ -42,14 +72,23 @@ target_link_libraries(boost_openmethod-indirect_shared PRIVATE Boost::openmethod
4272
set_target_properties(boost_openmethod-indirect_shared PROPERTIES
4373
ENABLE_EXPORTS ON
4474
OUTPUT_NAME indirect_shared
75+
LIBRARY_OUTPUT_DIRECTORY "${shared_libs_output_dir}"
76+
RUNTIME_OUTPUT_DIRECTORY "${shared_libs_output_dir}"
4577
)
4678

4779
add_executable(boost_openmethod-indirect indirect_main.cpp)
4880
target_compile_definitions(
4981
boost_openmethod-indirect PUBLIC BOOST_OPENMETHOD_DEFAULT_REGISTRY=indirect_registry)
50-
set_target_properties(boost_openmethod-indirect PROPERTIES ENABLE_EXPORTS ON)
82+
set_target_properties(boost_openmethod-indirect PROPERTIES
83+
ENABLE_EXPORTS ON
84+
RUNTIME_OUTPUT_DIRECTORY "${shared_libs_output_dir}"
85+
)
5186
target_link_libraries(boost_openmethod-indirect PRIVATE Boost::openmethod Boost::dll)
5287
add_dependencies(boost_openmethod-indirect boost_openmethod-indirect_shared)
5388
if (NOT WIN32)
54-
add_test(NAME boost_openmethod-indirect COMMAND boost_openmethod-indirect)
89+
openmethod_shared_libs_build_fixture(boost_openmethod-indirect)
90+
add_test(NAME boost_openmethod-indirect
91+
COMMAND "${shared_libs_output_dir}/boost_openmethod-indirect")
92+
set_tests_properties(boost_openmethod-indirect PROPERTIES
93+
FIXTURES_REQUIRED boost_openmethod-indirect-fixture)
5594
endif()

0 commit comments

Comments
 (0)