File tree Expand file tree Collapse file tree 4 files changed +33
-7
lines changed Expand file tree Collapse file tree 4 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -33,3 +33,29 @@ function(cpp_library)
3333 target_compile_features (${arg_cpp_lib_NAME} INTERFACE cxx_std_20)
3434 add_library (${arg_cpp_lib_NAMESPACE} ::${arg_cpp_lib_NAME} ALIAS ${arg_cpp_lib_NAME} )
3535endfunction ()
36+
37+ # Adds the current C++ library's unit test source files and dependencies to global list variables
38+ # used to build the Catch2 unit test target.
39+ # NOTE: There's no need to specify Catch2 related dependencies.
40+ #
41+ # @param SRCS
42+ # @param DEPS
43+ function (cpp_test)
44+ set (options "" )
45+ set (oneValueArgs "" )
46+ set (multiValueArgs
47+ SRCS
48+ DEPS
49+ )
50+ cmake_parse_arguments (arg_cpp_test "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
51+
52+ file (RELATIVE_PATH SRC_DIR "${PROJECT_SOURCE_DIR} " "${CMAKE_CURRENT_LIST_DIR} " )
53+
54+ foreach (SRC_FILE IN LISTS arg_cpp_test_SRCS)
55+ list (APPEND SOURCE_FILES_unitTest ${SRC_DIR} /${SRC_FILE} )
56+ endforeach ()
57+ set (SOURCE_FILES_unitTest "${SOURCE_FILES_unitTest} " CACHE INTERNAL "" )
58+
59+ list (APPEND LIB_DEPS_unitTest "${arg_cpp_test_DEPS} " )
60+ set (LIB_DEPS_unitTest "${LIB_DEPS_unitTest} " CACHE INTERNAL "" )
61+ endfunction ()
Original file line number Diff line number Diff line change @@ -22,14 +22,13 @@ endif()
2222list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} /CMake)
2323include (ystdlib-cpp-helpers)
2424
25+ # Initiate unit test global list variables
26+ set (SOURCE_FILES_unitTest "" CACHE INTERNAL "" )
27+ set (LIB_DEPS_unitTest "Catch2::Catch2WithMain" CACHE INTERNAL "" )
28+
2529add_subdirectory (src/ystdlib)
2630
2731add_executable (unitTest)
28- target_sources (unitTest PRIVATE src/main.cpp)
29- target_link_libraries (
30- unitTest
31- PRIVATE
32- ystdlib::testlib
33- Catch2::Catch2WithMain
34- )
32+ target_sources (unitTest PRIVATE ${SOURCE_FILES_unitTest} )
33+ target_link_libraries (unitTest PRIVATE ${LIB_DEPS_unitTest} )
3534target_compile_features (unitTest PRIVATE cxx_std_20)
Original file line number Diff line number Diff line change 11cpp_library(NAME testlib NAMESPACE ystdlib)
2+ cpp_test(SRCS test -hello.cpp DEPS ystdlib::testlib)
File renamed without changes.
You can’t perform that action at this time.
0 commit comments