[CMake] Create relocatable package with proper autogenerated config cmake
drgutek@o2.pl
drgutek at o2.pl
Thu Aug 17 09:25:24 EDT 2017
Hi, 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. I
got a suggesion on StackOverflow to use . (a dot) as my DESTINATION.
This worked partially, in the way that I no longer have absolute
_IMPORT_PREFIX. Unfortunately, the produced paths are still invalid: The
generated ATargets.cmake contains: get_filename_component(_IMPORT "${CMAKE_CURRENT_LIST_FILE}" PATH) get_filename_component(_IMPORT "${_IMPORT_PREFIX}" PATH) and the second line above is not necessary, it trims the path too much by one folder. Do you have any ideas how to solve it? Best regards, Piotr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170817/fc12e63f/attachment.html>
More information about the CMake
mailing list