Merge remote-tracking branch 'upstream/pr/1240'

* upstream/pr/1240:
  cmake: allow to use package config from build directory
This commit is contained in:
Roman Lebedev 2021-10-19 12:23:32 +03:00
commit 1e3ab7fa43
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
2 changed files with 14 additions and 2 deletions

View File

@ -1,3 +1,5 @@
@PACKAGE_INIT@
include (CMakeFindDependencyMacro) include (CMakeFindDependencyMacro)
find_dependency (Threads) find_dependency (Threads)

View File

@ -64,7 +64,7 @@ set_target_properties(benchmark_main PROPERTIES
target_link_libraries(benchmark_main PUBLIC benchmark::benchmark) target_link_libraries(benchmark_main PUBLIC benchmark::benchmark)
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") set(generated_dir "${PROJECT_BINARY_DIR}")
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
@ -74,11 +74,18 @@ set(targets_export_name "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::") set(namespace "${PROJECT_NAME}::")
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
configure_package_config_file (
${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in
${project_config}
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file( write_basic_package_version_file(
"${version_config}" VERSION ${GENERIC_LIB_VERSION} COMPATIBILITY SameMajorVersion "${version_config}" VERSION ${GENERIC_LIB_VERSION} COMPATIBILITY SameMajorVersion
) )
configure_file("${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in" "${project_config}" @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark.pc.in" "${pkg_config}" @ONLY) configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark.pc.in" "${pkg_config}" @ONLY)
if (BENCHMARK_ENABLE_INSTALL) if (BENCHMARK_ENABLE_INSTALL)
@ -114,4 +121,7 @@ if (BENCHMARK_ENABLE_INSTALL)
DIRECTORY "${PROJECT_SOURCE_DIR}/docs/" DIRECTORY "${PROJECT_SOURCE_DIR}/docs/"
DESTINATION "${CMAKE_INSTALL_DOCDIR}") DESTINATION "${CMAKE_INSTALL_DOCDIR}")
endif() endif()
export (EXPORT ${targets_export_name} NAMESPACE "${namespace}"
FILE ${generated_dir}/${targets_export_name}.cmake)
endif() endif()