diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fdbd086..680953f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,6 +159,10 @@ include(${CMAKE_SOURCE_DIR}/cmake/need_fmt.cmake) include(${CMAKE_SOURCE_DIR}/cmake/need_range_v3.cmake) include(${CMAKE_SOURCE_DIR}/cmake/need_phmap.cmake) +if(WITH_TESTS) + include(${CMAKE_SOURCE_DIR}/cmake/need_gtest.cmake) +endif() + find_package(Boost ${BOOST_REQUIRED_VERSION} REQUIRED COMPONENTS chrono iostreams program_options) if(STATIC_BUILD_DO_NOT_USE) @@ -221,31 +225,6 @@ include(${CMAKE_SOURCE_DIR}/cmake/thrift_library.cmake) include(${CMAKE_SOURCE_DIR}/cmake/folly.cmake) include(${CMAKE_SOURCE_DIR}/cmake/thrift.cmake) -if(WITH_TESTS) - if(PREFER_SYSTEM_GTEST) - find_package(GTest ${GOOGLETEST_REQUIRED_VERSION} CONFIG) - add_library(gtest ALIAS GTest::gtest) - add_library(gtest_main ALIAS GTest::gtest_main) - add_library(gmock ALIAS GTest::gmock) - add_library(gmock_main ALIAS GTest::gmock_main) - endif() - - if(NOT GTest_FOUND) - FetchContent_Declare( - googletest - GIT_REPOSITORY ${GOOGLETEST_GIT_REPO} - GIT_TAG v${GOOGLETEST_PREFERRED_VERSION} - EXCLUDE_FROM_ALL - ) - # For Windows: Prevent overriding the parent project's compiler/linker settings - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(googletest) - endif() - - enable_testing() - include(GoogleTest) -endif() - if(ENABLE_RICEPP) # TODO: support FetchContent add_subdirectory(ricepp) diff --git a/cmake/need_gtest.cmake b/cmake/need_gtest.cmake new file mode 100644 index 00000000..fbe74db2 --- /dev/null +++ b/cmake/need_gtest.cmake @@ -0,0 +1,42 @@ +# +# Copyright (c) Marcus Holland-Moritz +# +# This file is part of dwarfs. +# +# dwarfs is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# dwarfs is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# dwarfs. If not, see . +# + +cmake_minimum_required(VERSION 3.28.0) + +if(PREFER_SYSTEM_GTEST) + find_package(GTest ${GOOGLETEST_REQUIRED_VERSION} CONFIG) + add_library(gtest ALIAS GTest::gtest) + add_library(gtest_main ALIAS GTest::gtest_main) + add_library(gmock ALIAS GTest::gmock) + add_library(gmock_main ALIAS GTest::gmock_main) +endif() + +if(NOT GTest_FOUND) + FetchContent_Declare( + googletest + GIT_REPOSITORY ${GOOGLETEST_GIT_REPO} + GIT_TAG v${GOOGLETEST_PREFERRED_VERSION} + EXCLUDE_FROM_ALL + ) + # For Windows: Prevent overriding the parent project's compiler/linker settings + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) +endif() + +enable_testing() +include(GoogleTest)