|
| 1 | +# |
| 2 | +# CMake Install Google Test by Parra Studios |
| 3 | +# CMake script to install Google Test library. |
| 4 | +# |
| 5 | +# Copyright (C) 2016 - 2019 Vicente Eduardo Ferrer Garcia <[email protected]> |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +# you may not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# |
| 19 | + |
| 20 | +# The following variables are set: |
| 21 | +# |
| 22 | +# GTEST_INCLUDE_DIRS - A list of directories where the Google Test headers are located. |
| 23 | +# GTEST_LIBRARIES - A list of directories where the Google Test libraries are located. |
| 24 | + |
| 25 | +if(NOT GTEST_FOUND OR USE_BUNDLED_GTEST) |
| 26 | + if(NOT GTEST_VERSION OR USE_BUNDLED_GTEST) |
| 27 | + set(GTEST_VERSION 1.8.1) |
| 28 | + endif() |
| 29 | + |
| 30 | + find_package(Threads REQUIRED) |
| 31 | + |
| 32 | + if(MINGW) |
| 33 | + set(GTEST_DISABLE_PTHREADS ON) |
| 34 | + else() |
| 35 | + set(GTEST_DISABLE_PTHREADS OFF) |
| 36 | + endif() |
| 37 | + |
| 38 | + # Import Google Test Framework |
| 39 | + ExternalProject_Add(GoogleTest |
| 40 | + GIT_REPOSITORY https://github.com/google/googletest.git |
| 41 | + GIT_TAG release-${GTEST_VERSION} |
| 42 | + CMAKE_ARGS -Dgmock_build_tests=OFF |
| 43 | + -Dgtest_build_samples=OFF |
| 44 | + -Dgtest_build_tests=OFF |
| 45 | + -Dgtest_disable_pthreads=${GTEST_DISABLE_PTHREADS} |
| 46 | + -Dgtest_force_shared_crt=ON |
| 47 | + -Dgtest_hide_internal_symbols=OFF |
| 48 | + -DINSTALL_GTEST=OFF |
| 49 | + -DBUILD_GMOCK=ON |
| 50 | + PREFIX "${CMAKE_CURRENT_BINARY_DIR}" |
| 51 | + UPDATE_COMMAND "" |
| 52 | + INSTALL_COMMAND "" |
| 53 | + TEST_COMMAND "" |
| 54 | + ) |
| 55 | + |
| 56 | + # Google Test include and binary directories |
| 57 | + ExternalProject_Get_Property(GoogleTest source_dir binary_dir) |
| 58 | + |
| 59 | + set(GTEST_INCLUDE_DIR "${source_dir}/googletest/include") |
| 60 | + set(GMOCK_INCLUDE_DIR "${source_dir}/googlemock/include") |
| 61 | + set(GTEST_LIBS_DIR "${binary_dir}/googlemock/gtest") |
| 62 | + set(GMOCK_LIBS_DIR "${binary_dir}/googlemock") |
| 63 | + |
| 64 | + if(MSVC) |
| 65 | + set(GTEST_LIB_SUFFIX "lib") |
| 66 | + else() |
| 67 | + set(GTEST_LIB_SUFFIX "a") |
| 68 | + endif() |
| 69 | + |
| 70 | + # Define Paths |
| 71 | + set(GTEST_INCLUDE_DIRS |
| 72 | + "${GTEST_INCLUDE_DIR}" |
| 73 | + "${GMOCK_INCLUDE_DIR}" |
| 74 | + ) |
| 75 | + |
| 76 | + set(GTEST_LIBRARIES |
| 77 | + "${GTEST_LIBS_DIR}/libgtest.${GTEST_LIB_SUFFIX}" |
| 78 | + "${GMOCK_LIBS_DIR}/libgmock.${GTEST_LIB_SUFFIX}" |
| 79 | + "${CMAKE_THREAD_LIBS_INIT}" |
| 80 | + ) |
| 81 | + |
| 82 | + set(GTEST_FOUND TRUE) |
| 83 | + |
| 84 | + mark_as_advanced(GTEST_INCLUDE_DIRS GTEST_LIBRARIES) |
| 85 | + |
| 86 | + message(STATUS "Install Google Test v${GTEST_VERSION}") |
| 87 | +endif () |
0 commit comments