summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorDakota Hawkins <dakotahawkins@gmail.com>2018-07-24 15:06:55 (GMT)
committerDakota Hawkins <dakotahawkins@gmail.com>2018-08-21 17:02:09 (GMT)
commit759ef7c4e9662321548d1c30528c78ecdba2a05d (patch)
tree8123065767fdd8d9241804f032632573a2522bba /CMakeLists.txt
parentb88511ef640c046ec9c7553b383a2aba64c80967 (diff)
downloadgoogletest-759ef7c4e9662321548d1c30528c78ecdba2a05d.zip
googletest-759ef7c4e9662321548d1c30528c78ecdba2a05d.tar.gz
googletest-759ef7c4e9662321548d1c30528c78ecdba2a05d.tar.bz2
Improve CMake exported targets.refs/pull/1682/head
I _think_ this represents some of the "best practices" for exporting targets. They'll be available in a `googletest::` namespace (e.g. `googletest::gmock`) with non-namespaced `ALIAS` targets. - Added GOOGLETEST_VERSION variable - Use `CMakePackageConfigHelpers`, bump minimum CMake version to 2.8.8 Signed-off-by: Dakota Hawkins <dakotahawkins@gmail.com>
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt37
1 files changed, 27 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f8a97fa..db1b289 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,22 +1,16 @@
-cmake_minimum_required(VERSION 2.6.4)
+cmake_minimum_required(VERSION 2.8.8)
if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048)
-project( googletest-distribution )
+project(googletest-distribution)
+set(GOOGLETEST_VERSION 1.9.0)
enable_testing()
include(CMakeDependentOption)
-if (CMAKE_VERSION VERSION_LESS 2.8.5)
- set(CMAKE_INSTALL_BINDIR "bin" CACHE STRING "User executables (bin)")
- set(CMAKE_INSTALL_LIBDIR "lib${LIB_SUFFIX}" CACHE STRING "Object code libraries (lib)")
- set(CMAKE_INSTALL_INCLUDEDIR "include" CACHE STRING "C header files (include)")
- mark_as_advanced(CMAKE_INSTALL_BINDIR CMAKE_INSTALL_LIBDIR CMAKE_INSTALL_INCLUDEDIR)
-else()
- include(GNUInstallDirs)
-endif()
+include(GNUInstallDirs)
option(BUILD_GTEST "Builds the googletest subproject" OFF)
@@ -26,8 +20,31 @@ 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()