Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,19 @@ if(UNITS_BUILD_FUZZ_TARGETS)
add_subdirectory(FuzzTargets)
elseif(UNITS_ENABLE_TESTS AND NOT CMAKE_VERSION VERSION_LESS 3.13)
include(updateGitSubmodules)
enable_testing()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/ThirdParty/googletest/CMakeLists.txt")
submod_update(ThirdParty/googletest)
if(UNITS_ENABLE_SUBMODULE_UPDATE)
enable_testing()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/ThirdParty/googletest/CMakeLists.txt")
submod_update(ThirdParty/googletest)
endif()
else()
include(FindPkgConfig)
find_package(GTest REQUIRED)
pkg_check_modules(GMock gmock REQUIRED)
endif()
if(BUILD_TESTING)
add_subdirectory(test)
endif()

elseif(UNITS_ENABLE_TESTS)
message(WARNING "UNITS unit tests only supported under cmake 3.13 or greater")
endif()
Expand Down
36 changes: 22 additions & 14 deletions config/AddGoogletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,26 @@ set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS
CACHE INTERNAL ""
)

add_subdirectory(
${CMAKE_SOURCE_DIR}/ThirdParty/googletest ${CMAKE_BINARY_DIR}/ThirdParty/googletest
EXCLUDE_FROM_ALL
)

if(NOT MSVC)
target_compile_options(gtest PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions")
target_compile_options(gmock PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions")
target_compile_options(
gtest_main PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions"
)
target_compile_options(
gmock_main PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions"
if(NOT GTest_FOUND)
add_subdirectory(
${CMAKE_SOURCE_DIR}/ThirdParty/googletest
${CMAKE_BINARY_DIR}/ThirdParty/googletest EXCLUDE_FROM_ALL
)

if(NOT MSVC)
target_compile_options(
gtest PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions"
)
target_compile_options(
gmock PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions"
)
target_compile_options(
gtest_main PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions"
)
target_compile_options(
gmock_main PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions"
)
endif()
endif()

if(GOOGLE_TEST_INDIVIDUAL)
Expand Down Expand Up @@ -90,7 +96,9 @@ hide_variable(BUILD_GTEST)
hide_variable(INSTALL_GTEST)
hide_variable(GTEST_HAS_ABSL)

set_target_properties(gtest gtest_main gmock gmock_main PROPERTIES FOLDER "Extern")
if(NOT GTest_FOUND)
set_target_properties(gtest gtest_main gmock gmock_main PROPERTIES FOLDER "Extern")
endif()

if(MSVC)
# add_compile_options( /wd4459)
Expand Down
Loading