HDFS-16604. Install gtest via FetchContent_Declare in CMake (#4374)
Reviewed-by: Inigo Goiri <inigoiri@apache.org> Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
This commit is contained in:
parent
e85f827f0a
commit
4496e2daf6
|
@ -1,33 +0,0 @@
|
||||||
#
|
|
||||||
# Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
# or more contributor license agreements. See the NOTICE file
|
|
||||||
# distributed with this work for additional information
|
|
||||||
# regarding copyright ownership. The ASF licenses this file
|
|
||||||
# to you under the Apache License, Version 2.0 (the
|
|
||||||
# "License"); you may not use this file except in compliance
|
|
||||||
# with the License. You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
#
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
|
||||||
|
|
||||||
project(googletest-download NONE)
|
|
||||||
|
|
||||||
include(ExternalProject)
|
|
||||||
ExternalProject_Add(googletest
|
|
||||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
|
||||||
GIT_TAG release-1.10.0
|
|
||||||
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
|
|
||||||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
|
|
||||||
CONFIGURE_COMMAND ""
|
|
||||||
BUILD_COMMAND ""
|
|
||||||
INSTALL_COMMAND ""
|
|
||||||
TEST_COMMAND ""
|
|
||||||
)
|
|
|
@ -52,31 +52,20 @@ find_package(Threads)
|
||||||
|
|
||||||
include(CheckCXXSourceCompiles)
|
include(CheckCXXSourceCompiles)
|
||||||
include(CheckSymbolExists)
|
include(CheckSymbolExists)
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
# Download and build gtest
|
# Install googletest
|
||||||
configure_file(CMakeLists-gtest.txt.in googletest-download/CMakeLists.txt)
|
# As per the approach documented in the GoogleTest repo -
|
||||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
# https://github.com/google/googletest/blob/e649993a402d96afe25fbf3413749adf0f2947f6/googletest/README.md#incorporating-into-an-existing-cmake-project
|
||||||
RESULT_VARIABLE result
|
FetchContent_Declare(
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
|
googletest
|
||||||
if(result)
|
URL https://github.com/google/googletest/archive/703bd9caab50b139428cea1aaff9974ebee5742e.zip
|
||||||
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
)
|
||||||
endif()
|
# The commit SHA 703bd9caab50b139428cea1aaff9974ebee5742e in the URL above corresponds to the
|
||||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
# tag release-1.10.0 in the googletest repository.
|
||||||
RESULT_VARIABLE result
|
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
|
|
||||||
if(result)
|
|
||||||
message(FATAL_ERROR "Build step for googletest failed: ${result}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Prevent overriding the parent project's compiler/linker
|
|
||||||
# settings on Windows
|
|
||||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
|
FetchContent_MakeAvailable(googletest)
|
||||||
# Add googletest directly to our build. This defines
|
|
||||||
# the gtest and gtest_main targets.
|
|
||||||
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
|
|
||||||
EXCLUDE_FROM_ALL)
|
|
||||||
|
|
||||||
# Check if thread_local is supported
|
# Check if thread_local is supported
|
||||||
unset (THREAD_LOCAL_SUPPORTED CACHE)
|
unset (THREAD_LOCAL_SUPPORTED CACHE)
|
||||||
|
|
Loading…
Reference in New Issue