Skip to content

Commit 48e406a

Browse files
committed
Rename the top-level unit test target name
1 parent 4238234 commit 48e406a

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

CMake/ystdlib-cpp-helpers.cmake

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# NAMESPACE::NAME. Libraries with multiple levels of namespace nesting are currently not supported.
33
#
44
# If `BUILD_TESTING` is ON, build the unit tests specific to the current library, and link this
5-
# library against the global unit test target for the entire `ystdlib-cpp`.
5+
# library against the unified unit test target for the entire `ystdlib-cpp`.
66
#
77
# @param NAME
88
# @param NAMESPACE
@@ -60,13 +60,12 @@ function(cpp_library)
6060
${CMAKE_BINARY_DIR}/testbin
6161
)
6262

63-
if(BUILD_GLOBAL_TESTING)
64-
target_sources(${GLOBAL_UNIT_TEST_TARGET} PRIVATE ${arg_cpp_lib_TESTS})
65-
target_link_libraries(
66-
${GLOBAL_UNIT_TEST_TARGET}
67-
PRIVATE
68-
${arg_cpp_lib_NAMESPACE}::${arg_cpp_lib_NAME}
69-
)
70-
endif()
63+
# Link against unified unit test
64+
target_sources(${UNIFIED_UNIT_TEST_TARGET} PRIVATE ${arg_cpp_lib_TESTS})
65+
target_link_libraries(
66+
${UNIFIED_UNIT_TEST_TARGET}
67+
PRIVATE
68+
${arg_cpp_lib_NAMESPACE}::${arg_cpp_lib_NAME}
69+
)
7170
endif()
7271
endfunction()

CMakeLists.txt

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,32 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS
1212
)
1313

1414
option(BUILD_TESTING "If ON, unit tests will be built." ON)
15-
option(BUILD_GLOBAL_TESTING "If ON, the global unit test will be built." ON)
16-
17-
find_package(Catch2 3.8.0 REQUIRED)
18-
if(Catch2_FOUND)
19-
message(STATUS "Found Catch2 ${Catch2_VERSION}.")
20-
else()
21-
message(FATAL_ERROR "Could not find libraries for Catch2.")
22-
endif()
2315

2416
# Import CMake helper functions
2517
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/CMake)
26-
include(ystdlib-cpp-helpers)
2718

2819
if(BUILD_TESTING)
29-
# Set up the global unit test target
30-
if(BUILD_GLOBAL_TESTING)
31-
set(GLOBAL_UNIT_TEST_TARGET "unit-test-all")
32-
add_executable(${GLOBAL_UNIT_TEST_TARGET})
33-
target_link_libraries(${GLOBAL_UNIT_TEST_TARGET} PRIVATE Catch2::Catch2WithMain)
34-
target_compile_features(${GLOBAL_UNIT_TEST_TARGET} PRIVATE cxx_std_20)
35-
set_property(
36-
TARGET
37-
${GLOBAL_UNIT_TEST_TARGET}
38-
PROPERTY
39-
RUNTIME_OUTPUT_DIRECTORY
40-
${CMAKE_BINARY_DIR}/testbin
41-
)
20+
find_package(Catch2 3.8.0 REQUIRED)
21+
if(Catch2_FOUND)
22+
message(STATUS "Found Catch2 ${Catch2_VERSION}.")
23+
else()
24+
message(FATAL_ERROR "Could not find libraries for Catch2.")
4225
endif()
26+
27+
# Set up the unified unit test target
28+
set(UNIFIED_UNIT_TEST_TARGET "unit-test-all")
29+
add_executable(${UNIFIED_UNIT_TEST_TARGET})
30+
target_link_libraries(${UNIFIED_UNIT_TEST_TARGET} PRIVATE Catch2::Catch2WithMain)
31+
target_compile_features(${UNIFIED_UNIT_TEST_TARGET} PRIVATE cxx_std_20)
32+
set_property(
33+
TARGET
34+
${UNIFIED_UNIT_TEST_TARGET}
35+
PROPERTY
36+
RUNTIME_OUTPUT_DIRECTORY
37+
${CMAKE_BINARY_DIR}/testbin
38+
)
4339
endif()
4440

41+
include(ystdlib-cpp-helpers)
42+
4543
add_subdirectory(src/ystdlib)

0 commit comments

Comments
 (0)