Added Fetch_content and indented code
This commit is contained in:
@@ -66,17 +66,22 @@ unittests_vdpm.cc
|
|||||||
unittests_vector_type.cc
|
unittests_vector_type.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (NOT DEFINED OPENMESH_BUILD_UNIT_TESTS)
|
if (NOT DEFINED OPENMESH_BUILD_UNIT_TESTS)
|
||||||
set(OPENMESH_BUILD_UNIT_TESTS false CACHE BOOL "Enable or disable unit test builds in OpenMesh.")
|
set(OPENMESH_BUILD_UNIT_TESTS false CACHE BOOL "Enable or disable unit test builds in OpenMesh.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (OPENMESH_BUILD_UNIT_TESTS)
|
if (OPENMESH_BUILD_UNIT_TESTS)
|
||||||
# Search for gtest headers and libraries
|
# Fetch Gtest from github
|
||||||
find_package(GTest)
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
if(GTEST_FOUND)
|
googletest
|
||||||
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||||
|
GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 # v1.14.0
|
||||||
|
FIND_PACKAGE_ARGS NAMES GTest
|
||||||
|
)
|
||||||
|
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||||
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
@@ -85,11 +90,9 @@ if ( OPENMESH_BUILD_UNIT_TESTS )
|
|||||||
# Set correct include paths so that the compiler can find the headers
|
# Set correct include paths so that the compiler can find the headers
|
||||||
include_directories(${GTEST_INCLUDE_DIRS})
|
include_directories(${GTEST_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
# Set additional link directories
|
||||||
# set additional link directories
|
|
||||||
link_directories(${GTEST_LIBRARY_DIR})
|
link_directories(${GTEST_LIBRARY_DIR})
|
||||||
|
|
||||||
|
|
||||||
if (TARGET Eigen3::Eigen)
|
if (TARGET Eigen3::Eigen)
|
||||||
add_definitions(-DENABLE_EIGEN3_TEST)
|
add_definitions(-DENABLE_EIGEN3_TEST)
|
||||||
link_libraries(Eigen3::Eigen)
|
link_libraries(Eigen3::Eigen)
|
||||||
@@ -122,28 +125,22 @@ if ( OPENMESH_BUILD_UNIT_TESTS )
|
|||||||
set_target_properties(unittests_doublevec PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${UPCONFIG} ${OUTPUT_DIR})
|
set_target_properties(unittests_doublevec PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${UPCONFIG} ${OUTPUT_DIR})
|
||||||
endforeach ()
|
endforeach ()
|
||||||
|
|
||||||
|
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
# Link against all necessary libraries
|
# Link against all necessary libraries
|
||||||
target_link_libraries(unittests OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)
|
target_link_libraries(unittests OpenMeshCore OpenMeshTools GTest::gtest GTest::gtest_main pthread)
|
||||||
target_link_libraries(unittests_customvec OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)
|
target_link_libraries(unittests_customvec OpenMeshCore OpenMeshTools GTest::gtest GTest::gtest_main pthread)
|
||||||
target_link_libraries(unittests_doublevec OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)
|
target_link_libraries(unittests_doublevec OpenMeshCore OpenMeshTools GTest::gtest GTest::gtest_main pthread)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else()
|
else()
|
||||||
# Link against all necessary libraries
|
# Link against all necessary libraries
|
||||||
|
target_link_libraries(unittests OpenMeshCore OpenMeshTools GTest::gtest GTest::gtest_main)
|
||||||
|
target_link_libraries(unittests_customvec OpenMeshCore OpenMeshTools GTest::gtest GTest::gtest_main)
|
||||||
|
target_link_libraries(unittests_doublevec OpenMeshCore OpenMeshTools GTest::gtest GTest::gtest_main)
|
||||||
|
|
||||||
if (OPENMESH_BUILD_SHARED)
|
if (OPENMESH_BUILD_SHARED)
|
||||||
add_definitions(-DOPENMESHDLL)
|
add_definitions(-DOPENMESHDLL)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(unittests OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
|
|
||||||
target_link_libraries(unittests_customvec OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
|
|
||||||
target_link_libraries(unittests_doublevec OpenMeshCore OpenMeshTools ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
# Set compiler flags
|
# Set compiler flags
|
||||||
set_target_properties(unittests PROPERTIES COMPILE_FLAGS "-g -pedantic -Wno-long-long")
|
set_target_properties(unittests PROPERTIES COMPILE_FLAGS "-g -pedantic -Wno-long-long")
|
||||||
@@ -157,8 +154,7 @@ if ( OPENMESH_BUILD_UNIT_TESTS )
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (OPENMESH_BUILD_SHARED)
|
if (OPENMESH_BUILD_SHARED)
|
||||||
|
# Copy dlls to unittests
|
||||||
#-------- copy dlls to unittests --------
|
|
||||||
SET(OPENMESH_TARGETS "OpenMeshTools" "OpenMeshCore")
|
SET(OPENMESH_TARGETS "OpenMeshTools" "OpenMeshCore")
|
||||||
|
|
||||||
foreach (TAR ${OPENMESH_TARGETS})
|
foreach (TAR ${OPENMESH_TARGETS})
|
||||||
@@ -187,8 +183,4 @@ if ( OPENMESH_BUILD_UNIT_TESTS )
|
|||||||
add_test(NAME AllTestsIn_OpenMesh_tests WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests" COMMAND "${CMAKE_BINARY_DIR}/Unittests/unittests")
|
add_test(NAME AllTestsIn_OpenMesh_tests WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests" COMMAND "${CMAKE_BINARY_DIR}/Unittests/unittests")
|
||||||
add_test(NAME AllTestsIn_OpenMesh_tests_with_minimal_vector WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests" COMMAND "${CMAKE_BINARY_DIR}/Unittests/unittests_customvec")
|
add_test(NAME AllTestsIn_OpenMesh_tests_with_minimal_vector WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests" COMMAND "${CMAKE_BINARY_DIR}/Unittests/unittests_customvec")
|
||||||
add_test(NAME AllTestsIn_OpenMesh_tests_with_double_vector WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests" COMMAND "${CMAKE_BINARY_DIR}/Unittests/unittests_doublevec")
|
add_test(NAME AllTestsIn_OpenMesh_tests_with_double_vector WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Unittests" COMMAND "${CMAKE_BINARY_DIR}/Unittests/unittests_doublevec")
|
||||||
|
|
||||||
else(GTEST_FOUND)
|
|
||||||
message(STATUS "Google testing framework was not found, unittests disabled.")
|
|
||||||
endif(GTEST_FOUND)
|
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user