In general, relative parameters of type PATH
, like "lib" or "source/include" are resolved in CMake to an absolute path using current value of variables, like for instance: ${CMAKE_INSTALL_PREFIX}
in case of command INSTALL
. This, however, does not work if I would like to use empty relative path (or not set it at all), so that the resulting absolute path was equal to ${CMAKE_INSTALL_PREFIX}
- CMake generator would complain about non existing DESTINATION
, although there is no reason why it couldn't be resolved.
I know two workarounds to this issue, but the both have their flaws which prevent me from achieving my goal:
- Use
${CMAKE_INSTALL_PREFIX}
as theDESTINATION
value. This correctly resolved the path, but in case ofINSTALL(EXPORT)
, paths in generatedTarget.cmake
are absolute, which makes the package not relocatable. Use
.
as theDESTINATION
. This at least generates relative paths insideTarget.cmake
, but the paths are incorrect..
is apparently considered as a regular folder, and in the process ofTarget.cmake
generation, when_IMPORT_PREFIX
is determined, CMake strips one folder component too much:# Compute the installation prefix relative to this file. get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
Is there any other workaround? Do you think that lack of empty relative paths could be considered a bug?