[CMake] install EXPORT uses absolute paths on Windows, making libraries not relocatable
Wojciech Mamrak
wmamrak at gmail.com
Sat Sep 12 09:04:12 EDT 2015
Hello,
based on both wiki and this presentation:
https://archive.fosdem.org/2013/schedule/event/moderncmake/attachments/slides/258/export/events/attachments/moderncmake/slides/258/cmake_fosdem_2013.pdf
I have made this simple example. Its purpose is to test installing
projects and importing them by other projects.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.3)
add_library(foo main.cpp)
if (NOT DEFINED INSTALL_LIBDIR)
set(INSTALL_LIBDIR "" CACHE PATH "Output directory for libraries")
endif()
set(CMAKECONFIG_INSTALL_DIR "${INSTALL_LIBDIR}/CMake")
include(CMakePackageConfigHelpers)
configure_package_config_file(FooConfig.cmake.in FooConfig.cmake
INSTALL_DESTINATION "${CMAKECONFIG_INSTALL_DIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake"
DESTINATION "${CMAKECONFIG_INSTALL_DIR}")
install(TARGETS foo
EXPORT FooTargets
ARCHIVE DESTINATION "${INSTALL_LIBDIR}")
install(EXPORT FooTargets
DESTINATION "${CMAKECONFIG_INSTALL_DIR}")
FooConfig.cmake.in:
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/FooTargets.cmake")
Assume sources are located at "G:/workspace/Foo".
I am setting INSTALL_LIBDIR to "G:/Install". Installation output:
> -- Install configuration: "Debug"
> -- Installing: G:/Install/CMake/FooConfig.cmake
> -- Installing: G:/Install/foo.lib
> -- Installing: G:/Install/CMake/FooTargets.cmake
> -- Installing: G:/Install/CMake/FooTargets-debug.cmake
The contents of FooTargets-debug.cmake seems to be problematic:
#----------------------------------------------------------------
# Generated CMake target import file for configuration "Debug".
#----------------------------------------------------------------
# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)
# Import target "foo" for configuration "Debug"
set_property(TARGET foo APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(foo PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
IMPORTED_LOCATION_DEBUG "G:/Install/foo.lib"
)
list(APPEND _IMPORT_CHECK_TARGETS foo )
list(APPEND _IMPORT_CHECK_FILES_FOR_foo "G:/Install/foo.lib" )
# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
Notice the absolute paths, which make this code not relocatable. I
would like to be able to copy the install tree to some other machine
and point CMAKE_PREFIX_PATH to that new location. How can I achieve
this?
regards
More information about the CMake
mailing list