Skip to content

Commit 9a2f298

Browse files
committed
Make tests conditional only for static build
1 parent 82c2dd9 commit 9a2f298

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ else()
1919
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
2020
endif()
2121

22-
include(CTest)
2322
include(FetchContent)
2423
include(GNUInstallDirs)
2524

@@ -30,13 +29,17 @@ FetchContent_Declare(
3029
)
3130
FetchContent_MakeAvailable(pugixml)
3231

33-
FetchContent_Declare(
34-
Catch2
35-
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
36-
GIT_TAG v3.4.0
37-
)
38-
FetchContent_MakeAvailable(Catch2)
39-
include(Catch)
32+
# Only include testing dependencies if BUILD_TESTING is ON and BUILD_SHARED_LIBS is OFF
33+
if(BUILD_TESTING AND NOT BUILD_SHARED_LIBS)
34+
include(CTest)
35+
FetchContent_Declare(
36+
Catch2
37+
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
38+
GIT_TAG v3.4.0
39+
)
40+
FetchContent_MakeAvailable(Catch2)
41+
include(Catch)
42+
endif()
4043

4144
set(SOURCES
4245
src/Geometries/Arc.cpp
@@ -70,9 +73,12 @@ target_include_directories(
7073
$<BUILD_INTERFACE:${pugixml_SOURCE_DIR}/src>
7174
)
7275

73-
add_executable(tests tests/test.cpp)
74-
target_link_libraries(tests PRIVATE OpenDrive Catch2::Catch2WithMain)
75-
catch_discover_tests(tests WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)
76+
# Only build tests if BUILD_TESTING is ON and BUILD_SHARED_LIBS is OFF
77+
if(BUILD_TESTING AND NOT BUILD_SHARED_LIBS)
78+
add_executable(tests tests/test.cpp)
79+
target_link_libraries(tests PRIVATE OpenDrive Catch2::Catch2WithMain)
80+
catch_discover_tests(tests WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)
81+
endif()
7682

7783
install(
7884
TARGETS OpenDrive
@@ -89,4 +95,4 @@ install(
8995
)
9096
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
9197
install(TARGETS OpenDrive EXPORT OpenDriveConfig)
92-
install(EXPORT OpenDriveConfig NAMESPACE OpenDrive:: DESTINATION cmake)
98+
install(EXPORT OpenDriveConfig NAMESPACE OpenDrive:: DESTINATION cmake)

0 commit comments

Comments
 (0)