mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 20:41:04 -04:00
build: factor out gtest loading
This commit is contained in:
parent
f3455f18d9
commit
2b334d0b88
@ -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_range_v3.cmake)
|
||||||
include(${CMAKE_SOURCE_DIR}/cmake/need_phmap.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)
|
find_package(Boost ${BOOST_REQUIRED_VERSION} REQUIRED COMPONENTS chrono iostreams program_options)
|
||||||
|
|
||||||
if(STATIC_BUILD_DO_NOT_USE)
|
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/folly.cmake)
|
||||||
include(${CMAKE_SOURCE_DIR}/cmake/thrift.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)
|
if(ENABLE_RICEPP)
|
||||||
# TODO: support FetchContent
|
# TODO: support FetchContent
|
||||||
add_subdirectory(ricepp)
|
add_subdirectory(ricepp)
|
||||||
|
42
cmake/need_gtest.cmake
Normal file
42
cmake/need_gtest.cmake
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
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)
|
Loading…
x
Reference in New Issue
Block a user