diff options
author | Stefano Soffia <stefano.soffia.it@gmail.com> | 2017-12-01 11:48:46 (GMT) |
---|---|---|
committer | Stefano Soffia <stefano.soffia@utrc.utc.com> | 2018-08-22 15:27:11 (GMT) |
commit | aff0379441a392d618ec87b6d55a29070e97eaf1 (patch) | |
tree | b05386583bc0615c2e9fa66088f23f894a89c72b /googletest | |
parent | 880896c6f4814f4c7798355a652dc6167be2b75f (diff) | |
download | googletest-aff0379441a392d618ec87b6d55a29070e97eaf1.zip googletest-aff0379441a392d618ec87b6d55a29070e97eaf1.tar.gz googletest-aff0379441a392d618ec87b6d55a29070e97eaf1.tar.bz2 |
Install CMake export filesrefs/pull/1338/head
Rework of the closed pull request #768
Diffstat (limited to 'googletest')
-rw-r--r-- | googletest/CMakeLists.txt | 77 | ||||
-rw-r--r-- | googletest/cmake/Config.cmake.in | 9 | ||||
-rw-r--r-- | googletest/cmake/internal_utils.cmake | 35 |
3 files changed, 72 insertions, 49 deletions
diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index 3ab964f..2ac9aa0 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -85,10 +85,30 @@ include(cmake/internal_utils.cmake) config_compiler_and_linker() # Defined in internal_utils.cmake. +# Create the CMake package file descriptors. +if (INSTALL_GTEST) + include(CMakePackageConfigHelpers) + set(cmake_package_name GTest) + set(targets_export_name ${cmake_package_name}Targets CACHE INTERNAL "") + set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated" CACHE INTERNAL "") + set(cmake_files_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${cmake_package_name}") + set(version_file "${generated_dir}/${cmake_package_name}ConfigVersion.cmake") + write_basic_package_version_file(${version_file} COMPATIBILITY AnyNewerVersion) + install(EXPORT ${targets_export_name} + NAMESPACE ${cmake_package_name}:: + DESTINATION ${cmake_files_install_dir}) + set(config_file "${generated_dir}/${cmake_package_name}Config.cmake") + configure_package_config_file("${gtest_SOURCE_DIR}/cmake/Config.cmake.in" + "${config_file}" INSTALL_DESTINATION ${cmake_files_install_dir}) + install(FILES ${version_file} ${config_file} + DESTINATION ${cmake_files_install_dir}) +endif() + # Where Google Test's .h files can be found. -include_directories( +set(gtest_build_include_dirs "${gtest_SOURCE_DIR}/include" "${gtest_SOURCE_DIR}") +include_directories(${gtest_build_include_dirs}) # Summary of tuple support for Microsoft Visual Studio: # Compiler version(MS) version(cmake) Support @@ -112,62 +132,23 @@ endif() # aggressive about warnings. cxx_library(gtest "${cxx_strict}" src/gtest-all.cc) cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) -target_link_libraries(gtest_main gtest) - # If the CMake version supports it, attach header directory information # to the targets for when we are part of a parent build (ie being pulled # in via add_subdirectory() rather than being a standalone build). if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") - target_include_directories(gtest SYSTEM - INTERFACE - $<BUILD_INTERFACE:${gtest_SOURCE_DIR}/include> - $<BUILD_INTERFACE:${gtest_SOURCE_DIR}> - $<INSTALL_INTERFACE:include>) - target_include_directories(gtest_main SYSTEM - INTERFACE - $<BUILD_INTERFACE:${gtest_SOURCE_DIR}/include> - $<BUILD_INTERFACE:${gtest_SOURCE_DIR}> - $<INSTALL_INTERFACE:include>) + target_include_directories(gtest SYSTEM INTERFACE + "$<BUILD_INTERFACE:${gtest_build_include_dirs}>" + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) + target_include_directories(gtest_main SYSTEM INTERFACE + "$<BUILD_INTERFACE:${gtest_build_include_dirs}>" + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) endif() +target_link_libraries(gtest_main PUBLIC gtest) ######################################################################## # # Install rules -if(INSTALL_GTEST) - install(TARGETS gtest - EXPORT gtestConfigInternal - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") - install(EXPORT gtestConfigInternal - DESTINATION "${INSTALL_CMAKE_DIR}" - NAMESPACE googletest_) - install(TARGETS gtest_main - EXPORT gtest_mainConfigInternal - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") - install(EXPORT gtest_mainConfigInternal - DESTINATION "${INSTALL_CMAKE_DIR}" - NAMESPACE googletest_) - set(googletest_install_targets - ${googletest_install_targets} gtest gtest_main PARENT_SCOPE) - - install(DIRECTORY "${gtest_SOURCE_DIR}/include/gtest" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") - - # configure and install pkgconfig files - configure_file( - cmake/gtest.pc.in - "${gtest_BINARY_DIR}/gtest.pc" - @ONLY) - configure_file( - cmake/gtest_main.pc.in - "${gtest_BINARY_DIR}/gtest_main.pc" - @ONLY) - install(FILES "${gtest_BINARY_DIR}/gtest.pc" "${gtest_BINARY_DIR}/gtest_main.pc" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") -endif() +install_project(gtest gtest_main) ######################################################################## # diff --git a/googletest/cmake/Config.cmake.in b/googletest/cmake/Config.cmake.in new file mode 100644 index 0000000..12be449 --- /dev/null +++ b/googletest/cmake/Config.cmake.in @@ -0,0 +1,9 @@ +@PACKAGE_INIT@ +include(CMakeFindDependencyMacro) +if (@GTEST_HAS_PTHREAD@) + set(THREADS_PREFER_PTHREAD_FLAG @THREADS_PREFER_PTHREAD_FLAG@) + find_dependency(Threads) +endif() + +include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") +check_required_components("@project_name@") diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 566c02f..94702de 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -171,9 +171,18 @@ function(cxx_library_with_type name type cxx_flags) set_target_properties(${name} PROPERTIES COMPILE_DEFINITIONS "GTEST_CREATE_SHARED_LIBRARY=1") + if (NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") + target_compile_definitions(${name} INTERFACE + $<INSTALL_INTERFACE:GTEST_LINKED_AS_SHARED_LIBRARY=1>) + endif() endif() if (DEFINED GTEST_HAS_PTHREAD) - target_link_libraries(${name} ${CMAKE_THREAD_LIBS_INIT}) + if ("${CMAKE_VERSION}" VERSION_LESS "3.1.0") + set(threads_spec ${CMAKE_THREAD_LIBS_INIT}) + else() + set(threads_spec Threads::Threads) + endif() + target_link_libraries(${name} PUBLIC ${threads_spec}) endif() endfunction() @@ -283,3 +292,27 @@ function(py_test name) endif (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.1) endif(PYTHONINTERP_FOUND) endfunction() + +# install_project(targets...) +# +# Installs the specified targets and configures the associated pkgconfig files. +function(install_project) + if(INSTALL_GTEST) + install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + # Install the project targets. + install(TARGETS ${ARGN} + EXPORT ${targets_export_name} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + # Configure and install pkgconfig files. + foreach(t ${ARGN}) + set(configured_pc "${generated_dir}/${t}.pc") + configure_file("${PROJECT_SOURCE_DIR}/cmake/${t}.pc.in" + "${configured_pc}" @ONLY) + install(FILES "${configured_pc}" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + endforeach() + endif() +endfunction() |