Commit 80ecdb59 authored by Martin Heistermann's avatar Martin Heistermann
Browse files

CMake: fetch gtest

parent 049d6fd4
Pipeline #18208 failed with stage
in 4 minutes and 8 seconds
......@@ -10,41 +10,51 @@ if (NOT TARGET OpenVolumeMesh::OpenVolumeMesh)
find_package(OpenVolumeMesh REQUIRED)
endif()
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
)
if(WIN32)
# avoid linking errors, cf https://stackoverflow.com/questions/12540970/how-to-make-gtest-build-mdd-instead-of-mtd-by-default-using-cmake
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()
FetchContent_MakeAvailable(googletest)
set(TARGET_NAME "${OVM_TARGET_PREFIX}unittests")
enable_testing()
find_package(GTest)
if(GTEST_FOUND)
include(GoogleTest)
add_executable(${TARGET_NAME} ${SOURCE_FILES})
target_link_libraries(${TARGET_NAME}
OpenVolumeMesh::OpenVolumeMesh
GTest::GTest
GTest::Main
)
gtest_add_tests(TARGET ${TARGET_NAME}
EXTRA_ARGS "--gtest_color=yes;--gtest_output=xml"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests"
)
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/TestFiles/"
DESTINATION "${CMAKE_BINARY_DIR}/Unittests"
)
set_target_properties(${TARGET_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Unittests
)
#[[=
if ( WIN32 )
add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/unittests.exe
${CMAKE_BINARY_DIR}/Unittests/unittests.exe)
endif()
=]]
include(GoogleTest)
add_executable(${TARGET_NAME} ${SOURCE_FILES})
target_link_libraries(${TARGET_NAME}
OpenVolumeMesh::OpenVolumeMesh
gtest gtest_main
)
gtest_add_tests(TARGET ${TARGET_NAME}
EXTRA_ARGS "--gtest_color=yes;--gtest_output=xml"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests"
)
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/TestFiles/"
DESTINATION "${CMAKE_BINARY_DIR}/Unittests"
)
set_target_properties(${TARGET_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Unittests
)
#[[=
if ( WIN32 )
add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/unittests.exe
${CMAKE_BINARY_DIR}/Unittests/unittests.exe)
endif()
=]]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment