blob: 4d5c10a055fd40386b3379469c4d5233cc185acd [file] [log] [blame]
# 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.
project( gtest VERSION 1.8.1 LANGUAGES NONE )
set( SHA256 927827c183d01734cc5cfef85e0ff3f5a92ffe6188e0d18e909c5efebf28a0c7 )
include(ExternalProject)
ExternalProject_Add( ${PROJECT_NAME}-extern
URL "https://github.com/google/googletest/archive/release-${PROJECT_VERSION}.zip"
URL_HASH SHA256=${SHA256}
CMAKE_ARGS
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=$<CONFIG>
-Dgtest_force_shared_crt:BOOL=ON
)
ExternalProject_Get_Property( ${PROJECT_NAME}-extern INSTALL_DIR )
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 /D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING")
endif()
include(GNUInstallDirs)
function(ADD_GTEST_LIBRARY)
set(options)
set(oneValueArgs)
set(multiValueArgs DEPENDENCIES)
cmake_parse_arguments(PARSE_ARGV 1 args "${options}" "${oneValueArgs}" "${multiValueArgs}")
set(args_NAME ${ARGV0})
set(target "GTest_${args_NAME}")
add_library(${target} INTERFACE)
target_include_directories(${target} SYSTEM INTERFACE
$<BUILD_INTERFACE:${INSTALL_DIR}/${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(${target} INTERFACE
${INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${args_NAME}$<$<CONFIG:Debug>:d>${CMAKE_STATIC_LIBRARY_SUFFIX}
${args_DEPENDENCIES}
)
add_library(GTest::${args_NAME} ALIAS ${target})
add_dependencies(${target} ${PROJECT_NAME}-extern)
endfunction()
find_package(Threads REQUIRED)
add_gtest_library(gtest DEPENDENCIES Threads::Threads)
add_gtest_library(gtest_main DEPENDENCIES GTest::gtest)
add_gtest_library(gmock DEPENDENCIES GTest::gtest)
add_gtest_library(gmock_main DEPENDENCIES GTest::gmock)