templates-project_setup/cpp/test/CMakeLists.txt

63 lines
2.1 KiB
CMake
Raw Normal View History

2020-07-14 07:02:35 +00:00
include(GoogleTest)
## CONFIGURE TESTING LIBRARY
# download and add googletest testing library
set(INSTALL_GTEST OFF CACHE BOOL "Install GTest")
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()
# convinience macro. Attention, the target must already exist
macro(add_gtest TESTNAME)
target_link_libraries(${TESTNAME} PUBLIC gtest gmock gtest_main)
if(GOOGLE_TEST_INDIVIDUAL)
if(CMAKE_VERSION VERSION_LESS 3.10)
gtest_add_tests(TARGET ${TESTNAME}
TEST_PREFIX "${TESTNAME}."
TEST_LIST TmpTestList)
set_tests_properties(${TmpTestList} PROPERTIES FOLDER "Tests") # for IDEs
else()
gtest_discover_tests(${TESTNAME}
TEST_PREFIX "${TESTNAME}."
PROPERTIES FOLDER "Tests")
endif()
else()
add_test(${TESTNAME} ${TESTNAME})
set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests") # for IDEs
endif()
endmacro()
# add a make target with better test output, than the standard `make test`
if(CMAKE_CONFIGURATION_TYPES)
add_custom_target(check COMMAND env GTEST_COLOR=1 ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process --output-on-failure
--build-config "$<CONFIGURATION>")
else()
add_custom_target(check COMMAND env GTEST_COLOR=1 ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process --output-on-failure)
endif()
set_target_properties(check PROPERTIES FOLDER "Scripts")
## CONFIGURE TESTS
# # add tests for convinience interfaces
# add_executable(interfacetests
# main.cpp
# template-test.cpp
# )
# add_gtest(interfacetests)
# target_include_directories(interfacetests INTERFACE ${gtest_SOURCE_DIR}/include)
# target_link_libraries(interfacetests PRIVATE main_util_v2x)
# target_link_libraries(interfacetests PRIVATE main_util_hmi)