From 192a6920342257d2feca3e35c9c4a8b44a792b32 Mon Sep 17 00:00:00 2001 From: Robert Marki Date: Mon, 25 Apr 2016 11:55:03 +0200 Subject: [PATCH] Generate package config files in cmake's current binary directory Generate the config files of the package in CMAKE_CURRENT_BINARY_DIR instead of CMAKE_BINARY_DIR because the later will refer to the main project's binary directory if the library is included in the project using the add_subdirectory command. --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75caa9a2..4ae1d8bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,15 +33,15 @@ target_link_libraries(${JSON_UNITTEST_TARGET_NAME} ${JSON_TARGET_NAME}) # generate a config and config version file for the package include(CMakePackageConfigHelpers) configure_package_config_file("cmake/config.cmake.in" - "${CMAKE_BINARY_DIR}/${JSON_CONFIG_FILENAME}" + "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}" INSTALL_DESTINATION ${JSON_CONFIG_DESTINATION}) -write_basic_package_version_file("${CMAKE_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}" +write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion) # export the library target and store build directory in package registry export(TARGETS ${JSON_TARGET_NAME} - FILE "${CMAKE_BINARY_DIR}/${JSON_TARGETS_FILENAME}") + FILE "${CMAKE_CURRENT_BINARY_DIR}/${JSON_TARGETS_FILENAME}") export(PACKAGE ${JSON_PACKAGE_NAME}) # install library target and config files @@ -52,6 +52,6 @@ install(FILES "src/json.hpp" install(EXPORT ${JSON_PACKAGE_NAME} FILE ${JSON_TARGETS_FILENAME} DESTINATION ${JSON_CONFIG_DESTINATION}) -install(FILES "${CMAKE_BINARY_DIR}/${JSON_CONFIG_FILENAME}" - "${CMAKE_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}" +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}" + "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}" DESTINATION ${JSON_CONFIG_DESTINATION})