On 21/07/14 14:23, Stephen Kelly wrote: > Can you give a more-concrete example of what the problem is?
I have a project that is similar to this small example: --- CMakeLists.txt cmake_minimum_required(VERSION 2.8.12) project(FOO NONE) set(FOO_VERSION 0.0.1) include(${CMAKE_CURRENT_LIST_DIR}/CMakePackageConfigHelpers.cmake) set(FOO_INSTALL_CMAKE_DIR "share/FOO/cmake") set(FOO_BUILD_ABSOLUTE_DIR "${CMAKE_BINARY_DIR}/share/FOO/absolute") set(FOO_INSTALL_ABSOLUTE_DIR "${CMAKE_INSTALL_PREFIX}/share/FOO/absolute") set(FOO_BUILD_RELATIVE_DIR "share/FOO/relative") set(FOO_INSTALL_RELATIVE_DIR "share/FOO/relative") #--------- BUILD TREE set(FOO_ABSOLUTE_DIR ${FOO_BUILD_ABSOLUTE_DIR}) set(FOO_RELATIVE_DIR ${FOO_BUILD_RELATIVE_DIR}) # FOOConfig.cmake (build tree) configure_package_config_file(FOOConfig.cmake.in "FOOConfig.cmake" INSTALL_DESTINATION "${CMAKE_BINARY_DIR}" PATH_VARS FOO_ABSOLUTE_DIR FOO_RELATIVE_DIR NO_CHECK_REQUIRED_COMPONENTS_MACRO BUILD_TREE) #--------- INSTALLED set(FOO_ABSOLUTE_DIR ${FOO_INSTALL_ABSOLUTE_DIR}) set(FOO_RELATIVE_DIR ${FOO_INSTALL_RELATIVE_DIR}) # FOOConfig.cmake (installed) configure_package_config_file(FOOConfig.cmake.in "FOOConfigInstall.cmake" INSTALL_DESTINATION "${FOO_INSTALL_CMAKE_DIR}" PATH_VARS FOO_ABSOLUTE_DIR FOO_RELATIVE_DIR NO_CHECK_REQUIRED_COMPONENTS_MACRO) install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/FOOConfigInstall.cmake DESTINATION ${FOO_INSTALL_CMAKE_DIR} RENAME FOOConfig.cmake) --- FOOConfig.cmake.in set(FOO_VERSION @FOO_VERSION@) @PACKAGE_INIT@ set_and_check(FOO_ABSOLUTE_DIR "@PACKAGE_FOO_ABSOLUTE_DIR@") set_and_check(FOO_RELATIVE_DIR "@PACKAGE_FOO_RELATIVE_DIR@") The project is supposed to work both from build tree (using export(TARGETS)) and from the install tree (using install(EXPORT)). The file FOOConfigInstall.cmake is perfect and can be relocated as expected. The file FOOConfig.cmake for the build tree contains --- [...] get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../usr/local" ABSOLUTE) [...] set_and_check(FOO_ABSOLUTE_DIR "<absolute path to build directory>/share/FOO/absolute") set_and_check(FOO_RELATIVE_DIR "${PACKAGE_PREFIX_DIR}/share/FOO/relative") --- in PACKAGE_PREFIX_DIR, obviously, the length list of "/.." depends on the folder where the package is built. "/usr/local" is the prefix and it makes no sense in the file for the build directory. The path passed using a variable containing an _absolute path_ is _correct_, but it uses the absolute path to the build directory. The path passed using a variable containing a _relative path_ is _wrong_ and it contains a path relative to the install directory. If the package was not installed this path is invalid. This means that all the paths should be passed as absolute paths or the generated file will be invalid. With my patch applied and passing "BUILD_TREE" to the configure_package_config_file call, the generated file becomes: --- [...] get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/" ABSOLUTE) [...] set_and_check(FOO_ABSOLUTE_DIR "${PACKAGE_PREFIX_DIR}/share/FOO/absolute") set_and_check(FOO_RELATIVE_DIR "${PACKAGE_PREFIX_DIR}/share/FOO/relative") --- This removes all the absolute paths from the file (This is not necessary for using the package in the build tree, since I believe that it's not going to be relocated, but I still think it is a good thing), and very important, it allows you to pass relative paths as PATH_VARS and get the same behaviour in both cases. Cheers, Daniele -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers