Skip to content

Commit e1788a8

Browse files
committed
allow unit tests in shared library builds
The test sources must be compiled with a special define and require optimisation in order to be able to run. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent 9412d1a commit e1788a8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ target_link_libraries(test-target PRIVATE
4949
${PROJECT_NAME}
5050
)
5151

52+
# for the SHARED_LIBRARY build we need some special flags enabled
53+
# We also allow our users to override our selection by defining their own
54+
# `CMAKE_C_FLAGS` on generation-phase. CMake itself doesn't allow a user
55+
# to override settings defined in the CMakeLists.txt so we append it manually
56+
# again even though CMake prepended it already.
57+
target_compile_options(test-target BEFORE PRIVATE
58+
$<$<STREQUAL:$<TARGET_PROPERTY:${PROJECT_NAME},TYPE>,SHARED_LIBRARY>:-O1 -DLTM_TEST_DYNAMIC>
59+
${CMAKE_C_FLAGS}
60+
)
61+
target_link_options(test-target BEFORE PRIVATE
62+
$<$<STREQUAL:$<TARGET_PROPERTY:${PROJECT_NAME},TYPE>,SHARED_LIBRARY>:-O1>
63+
)
64+
5265
#-----------------------------------------------------------------------------
5366
# demo target
5467
#-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)