I have created cmake target, say A
, and want to install it and create a Config file, so that the installed package could be relocatable. My code is:
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ??? )
Here, I am having a problem with the proper destination. I want the Config file to be installed where ${CMAKE_INSTALL_PREFIX}
points to. But when I put ${CMAKE_INSTALL_PREFIX}
at ???
, my resulting ATargets.cmake
file contains the line:
set(_IMPORT_PREFIX "C:/Libraries/...")
which is the actual value of ${CMAKE_INSTALL_PREFIX}
. This _IMPORT_PREFIX
is later prepended to the parameters of set_target_properties()
command inside the auto-generated ATargets.cmake
, resulting in hard coded paths, valid only on the installation system.
I tried to use some generator expressions like <$IMPORT_PREFIX>
in place of ???
, but this gave me an error at cmake generation. I also tried to omit DESTINATION
which in my opinion should place the file in the location relative to ${CMAKE_INSTALL_PREFIX}
, but cmake complained about it too.
Can you please help me with this issue?