summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
blob: db1b2899e9d73a09317f4960e50ae4a0fdf261ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
cmake_minimum_required(VERSION 2.8.8)

if (POLICY CMP0048)
  cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048)

project(googletest-distribution)
set(GOOGLETEST_VERSION 1.9.0)

enable_testing()

include(CMakeDependentOption)
include(GNUInstallDirs)

option(BUILD_GTEST "Builds the googletest subproject" OFF)

#Note that googlemock target already builds googletest
option(BUILD_GMOCK "Builds the googlemock subproject" ON)

cmake_dependent_option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON "BUILD_GTEST OR BUILD_GMOCK" OFF)
cmake_dependent_option(INSTALL_GMOCK "Enable installation of googlemock. (Projects embedding googlemock may want to turn this OFF.)" ON "BUILD_GMOCK" OFF)

if(WIN32)
  set(INSTALL_CMAKE_DIR "cmake" CACHE PATH "CMake exported targets")
else()
  set(INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/gtest" CACHE PATH "CMake exported targets")
endif()

set(googletest_install_targets)
if(BUILD_GMOCK)
  add_subdirectory( googlemock )
elseif(BUILD_GTEST)
  add_subdirectory( googletest )
endif()

if(googletest_install_targets)
  include(CMakePackageConfigHelpers)
  configure_package_config_file(
    "${CMAKE_CURRENT_LIST_DIR}/cmake/googletestConfig.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/googletestConfig.cmake"
    INSTALL_DESTINATION "${INSTALL_CMAKE_DIR}")
  write_basic_package_version_file(
    ${CMAKE_CURRENT_BINARY_DIR}/googletestConfigVersion.cmake
    VERSION "${GOOGLETEST_VERSION}"
    COMPATIBILITY SameMajorVersion)
  install(FILES
    ${CMAKE_CURRENT_BINARY_DIR}/googletestConfig.cmake
    ${CMAKE_CURRENT_BINARY_DIR}/googletestConfigVersion.cmake
    DESTINATION "${INSTALL_CMAKE_DIR}")
endif()