[CMake] Making the export function output relative paths

John van der Burg buckshag at gmail.com
Wed May 6 18:10:32 EDT 2015


Hi,

I'm trying to get my head around CMake config files to use in combination
with find_package.
So currently I have a given library target setup.

Then I call a configure_package_config_file to generate some
TargetConfig.cmake.
After that I call an export on the target.

The files are generated fine, and it looks fine, except for one thing,
which is that the libraries it imports use absolute paths.
The export command generates the cmake file which imports targets, but it
does it like this, using absolute paths:

set_target_properties(MCore PROPERTIES
  IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
  IMPORTED_LOCATION_PROFILE *"C:/Test/Lib/MCore_Debug.lib"*
  )

As I cannot ship the config files using absolute paths I need to make them
use relative paths. However I cannot get the export command to output a
relative path.

Does anyone know how I should do this? Or using some prefix variable and
then relative to that.

I currently export like this:
--------------
configure_package_config_file( "MCoreConfig.cmake.in"
"${CMAKE_BINARY_DIR}/MCoreConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
PATH_VARS INCLUDE_DIR CONF_RELATIVE_DIR CUSTOM_ROOT)

export( TARGETS MCore FILE "${CMAKE_BINARY_DIR}/MCoreTargets.cmake" )
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/MCoreConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/MCoreTargets.cmake" DESTINATION
"${CUSTOM_ROOT}/CMake" )
-----------
I basically need everything relative to the ${CUSTOM_ROOT} folder.

Any hints/help would be appreciated :)

Thanks,
- John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150507/16bf916a/attachment.html>


More information about the CMake mailing list