From aa06a4761e24e59ceaa00e81be450b4d9a0c4d26 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 27 Jul 2020 18:15:18 -0400 Subject: [PATCH] cmake: install pkg-config file relative to current_binary_dir When the testsuite is enabled, the "cmake_add_subdirectory" test adds a second copy of the project into the build configuration, and the project files are installed twice. This becomes super problematic when it tries to install a file from CMAKE_BINARY_DIR which is only available in CMAKE_CURRENT_BINARY_DIR and bombs out with the following error message: ``` [...] -- Installing: /usr/lib/cmake/nlohmann_json/nlohmann_jsonTargets.cmake CMake Error at test/cmake_add_subdirectory/nlohmann_json/cmake_install.cmake:73 (file): file INSTALL cannot find "......./nlohmann-json/builddir/test/cmake_add_subdirectory/nlohmann_json.pc": No such file or directory. Call Stack (most recent call first): test/cmake_add_subdirectory/cmake_install.cmake:47 (include) test/cmake_install.cmake:49 (include) cmake_install.cmake:94 (include) ``` --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5d0ae34..1afcc257 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,7 +157,7 @@ endif() DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR} ) install( - FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc" + FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" DESTINATION lib/pkgconfig ) endif()