Skip to content

Commit

Permalink
Fix assumption that CMAKE_INSTALL_*DIR paths are relative.
Browse files Browse the repository at this point in the history
This solution uses relative paths if possible, allowing the package to be
relocatable, but still works correctly if CMAKE_INSTALL_*DIR paths are absolute.

Signed-off-by: Ben Wolsieffer <[email protected]>
  • Loading branch information
lopsided98 committed Oct 11, 2024
1 parent 7b1b3a4 commit fa89f2d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ option(APPEND_PROJECT_NAME_TO_INCLUDEDIR

if(APPEND_PROJECT_NAME_TO_INCLUDEDIR)
set(CMAKE_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
set(CMAKE_INSTALL_FULL_INCLUDEDIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${PROJECT_NAME}")
endif()

set (URDF_MAJOR_VERSION 1)
Expand All @@ -33,10 +34,15 @@ if(WIN32 AND NOT CYGWIN)
else()
set(CMAKE_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake)
endif()
string(REGEX REPLACE "[^/]+" ".." RELATIVE_PATH_CMAKE_DIR_TO_PREFIX "${CMAKE_CONFIG_INSTALL_DIR}")
string(REGEX REPLACE "[^/]+" ".." RELATIVE_PATH_LIBDIR_TO_PREFIX "${CMAKE_INSTALL_LIBDIR}")
file(RELATIVE_PATH RELATIVE_PATH_CMAKE_DIR_TO_PREFIX "${CMAKE_CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
file(RELATIVE_PATH RELATIVE_PATH_LIBDIR_TO_PREFIX "${CMAKE_INSTALL_LIBDIR}" "${CMAKE_INSTALL_PREFIX}")

set(PACKAGE_NAME ${PROJECT_NAME})
string(REPLACE
"${CMAKE_INSTALL_PREFIX}"
"\${${PROJECT_NAME}_DIR}/${RELATIVE_PATH_CMAKE_DIR_TO_PREFIX}"
cmake_conf_include_dir
"${CMAKE_INSTALL_FULL_INCLUDEDIR}")
set(cmake_conf_file "${PROJECT_NAME}-config.cmake")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/${cmake_conf_file}.in" "${CMAKE_BINARY_DIR}/${cmake_conf_file}" @ONLY)
set(cmake_conf_version_file "${PROJECT_NAME}-config-version.cmake")
Expand All @@ -56,6 +62,7 @@ install(FILES

# Make the package config file
set(PACKAGE_DESC "Unified Robot Description Format")
string(REPLACE "${CMAKE_INSTALL_PREFIX}" "\${prefix}" pkg_conf_includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
set(pkg_conf_file "urdfdom_headers.pc")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkgconfig/${pkg_conf_file}.in" "${CMAKE_BINARY_DIR}/${pkg_conf_file}" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/${pkg_conf_file}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ COMPONENT pkgconfig)
Expand Down
2 changes: 1 addition & 1 deletion cmake/pkgconfig/urdfdom_headers.pc.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file was generated by CMake for @PROJECT_NAME@
prefix=${pcfiledir}/../@RELATIVE_PATH_LIBDIR_TO_PREFIX@
exec_prefix=${prefix}
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
includedir=@pkg_conf_includedir@

Name: @PACKAGE_NAME@
Description: @PACKAGE_DESC@
Expand Down
2 changes: 1 addition & 1 deletion cmake/urdfdom_headers-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if (@PACKAGE_NAME@_CONFIG_INCLUDED)
endif()
set(@PACKAGE_NAME@_CONFIG_INCLUDED TRUE)

set(@PACKAGE_NAME@_INCLUDE_DIRS "${@PROJECT_NAME@_DIR}/@RELATIVE_PATH_CMAKE_DIR_TO_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@")
set(@PACKAGE_NAME@_INCLUDE_DIRS "@cmake_conf_include_dir@")

include("${@PACKAGE_NAME@_DIR}/@[email protected]")

Expand Down

0 comments on commit fa89f2d

Please sign in to comment.