From a134099562d8d44bacf6d71f4425c8f5926fbb18 Mon Sep 17 00:00:00 2001 From: Mike Purvis Date: Tue, 28 Feb 2023 14:55:31 -0500 Subject: [PATCH 1/3] Use GNUInstallDirs for catkin and catkin packages. --- cmake/all.cmake | 13 ++++++----- cmake/catkin_package.cmake | 23 +++++++++++-------- cmake/templates/pkgConfig.cmake.in | 4 ++++ .../templates/python_distutils_install.sh.in | 11 ++++++--- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/cmake/all.cmake b/cmake/all.cmake index 7768f968d..ffd6d6301 100644 --- a/cmake/all.cmake +++ b/cmake/all.cmake @@ -174,13 +174,14 @@ unset(_CATKIN_CURRENT_PACKAGE) configure_shared_library_build_settings() # set global install destinations -set(CATKIN_GLOBAL_BIN_DESTINATION bin) -set(CATKIN_GLOBAL_ETC_DESTINATION etc) -set(CATKIN_GLOBAL_INCLUDE_DESTINATION include) -set(CATKIN_GLOBAL_LIB_DESTINATION lib) -set(CATKIN_GLOBAL_LIBEXEC_DESTINATION lib) +include(GNUInstallDirs) +set(CATKIN_GLOBAL_BIN_DESTINATION ${CMAKE_INSTALL_BINDIR}) +set(CATKIN_GLOBAL_ETC_DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}) +set(CATKIN_GLOBAL_INCLUDE_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +set(CATKIN_GLOBAL_LIB_DESTINATION ${CMAKE_INSTALL_LIBDIR}) +set(CATKIN_GLOBAL_LIBEXEC_DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) set(CATKIN_GLOBAL_PYTHON_DESTINATION ${PYTHON_INSTALL_DIR}) -set(CATKIN_GLOBAL_SHARE_DESTINATION share) +set(CATKIN_GLOBAL_SHARE_DESTINATION ${CMAKE_INSTALL_DATADIR}) # undefine CATKIN_ENV since it might be set in the cache from a previous build set(CATKIN_ENV "" CACHE INTERNAL "catkin environment" FORCE) diff --git a/cmake/catkin_package.cmake b/cmake/catkin_package.cmake index df36e236a..c5e3f840b 100644 --- a/cmake/catkin_package.cmake +++ b/cmake/catkin_package.cmake @@ -286,7 +286,8 @@ function(_catkin_package) set(DEVELSPACE TRUE) set(INSTALLSPACE FALSE) - set(PROJECT_SPACE_DIR ${CATKIN_DEVEL_PREFIX}) + set(PROJECT_SPACE_LIBDIR ${CATKIN_DEVEL_PREFIX}/lib) + set(PROJECT_SPACE_DATADIR ${CATKIN_DEVEL_PREFIX}/share) set(PKG_INCLUDE_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}) # absolute path to include dirs and validate that they are existing either absolute or relative to packages source @@ -314,8 +315,8 @@ function(_catkin_package) # prepend library path of this workspace set(PKG_CONFIG_LIB_PATHS ${lib_paths}) - list(INSERT PKG_CONFIG_LIB_PATHS 0 ${PROJECT_SPACE_DIR}/lib) - set(PKG_CMAKE_DIR ${PROJECT_SPACE_DIR}/share/${PROJECT_NAME}/cmake) + list(INSERT PKG_CONFIG_LIB_PATHS 0 ${PROJECT_SPACE_LIBDIR}) + set(PKG_CMAKE_DIR ${PROJECT_SPACE_DATADIR}/${PROJECT_NAME}/cmake) if("${PROJECT_NAME}" STREQUAL "catkin") set(PKG_CMAKE_DIR "${catkin_EXTRAS_DIR}") endif() @@ -400,12 +401,14 @@ function(_catkin_package) set(DEVELSPACE FALSE) set(INSTALLSPACE TRUE) - set(PROJECT_SPACE_DIR ${CMAKE_INSTALL_PREFIX}) + set(PROJECT_SPACE_LIBDIR ${CMAKE_INSTALL_PREFIX}/${CATKIN_GLOBAL_LIB_DESTINATION}) + set(PROJECT_SPACE_DATADIR ${CMAKE_INSTALL_PREFIX}/${CATKIN_GLOBAL_SHARE_DESTINATION}) set(PKG_INCLUDE_PREFIX "\\\${prefix}") # absolute path to include dir under install prefix if any include dir is set set(PROJECT_CMAKE_CONFIG_INCLUDE_DIRS "") set(PROJECT_PKG_CONFIG_INCLUDE_DIRS "") + foreach(idir ${PROJECT_INCLUDE_DIRS}) # include dirs in source / build / devel space are handled like relative ones # since these files are supposed to be installed to the include folder in install space @@ -433,9 +436,9 @@ function(_catkin_package) list_append_unique(PROJECT_PKG_CONFIG_INCLUDE_DIRS ${PROJECT_DEPENDENCIES_INCLUDE_DIRS}) endif() - # prepend library path of this workspace + # prepend installed library path of this workspace set(PKG_CONFIG_LIB_PATHS ${lib_paths}) - list(INSERT PKG_CONFIG_LIB_PATHS 0 ${PROJECT_SPACE_DIR}/lib) + list(INSERT PKG_CONFIG_LIB_PATHS 0 ${PROJECT_SPACE_LIBDIR}) # package cmake dir is the folder where the generated pkgConfig.cmake is located set(PKG_CMAKE_DIR "\${${PROJECT_NAME}_DIR}") @@ -448,7 +451,7 @@ function(_catkin_package) ${catkin_EXTRAS_DIR}/em/pkg.pc.em ${CMAKE_CURRENT_BINARY_DIR}/catkin_generated/installspace/${PROJECT_NAME}.pc) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/catkin_generated/installspace/${PROJECT_NAME}.pc - DESTINATION lib/pkgconfig + DESTINATION ${PROJECT_SPACE_LIBDIR}/pkgconfig ) endif() @@ -495,7 +498,7 @@ function(_catkin_package) endforeach() install(FILES ${installable_cfg_extras} - DESTINATION share/${PROJECT_NAME}/cmake + DESTINATION ${PROJECT_SPACE_DATADIR}/${PROJECT_NAME}/cmake ) if(NOT PROJECT_SKIP_CMAKE_CONFIG_GENERATION) @@ -521,12 +524,12 @@ function(_catkin_package) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/catkin_generated/installspace/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/catkin_generated/installspace/${PROJECT_NAME}Config-version.cmake - DESTINATION share/${PROJECT_NAME}/cmake + DESTINATION ${PROJECT_SPACE_DATADIR}/${PROJECT_NAME}/cmake ) endif() # install package.xml install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/package.xml - DESTINATION share/${PROJECT_NAME} + DESTINATION ${PROJECT_SPACE_DATADIR}/${PROJECT_NAME} ) endfunction() diff --git a/cmake/templates/pkgConfig.cmake.in b/cmake/templates/pkgConfig.cmake.in index 8740d9944..3d09cae88 100644 --- a/cmake/templates/pkgConfig.cmake.in +++ b/cmake/templates/pkgConfig.cmake.in @@ -76,6 +76,10 @@ else() set(@PROJECT_NAME@_DEVEL_PREFIX "") set(@PROJECT_NAME@_INSTALL_PREFIX @CMAKE_INSTALL_PREFIX@) set(@PROJECT_NAME@_PREFIX ${@PROJECT_NAME@_INSTALL_PREFIX}) + set(@PROJECT_NAME@_INSTALL_BINDIR @CMAKE_INSTALL_BINDIR@) + set(@PROJECT_NAME@_INSTALL_LIBDIR @CMAKE_INSTALL_LIBDIR@) + set(@PROJECT_NAME@_INSTALL_DATADIR @CMAKE_INSTALL_DATADIR@) + set(@PROJECT_NAME@_INSTALL_INCLUDEDIR @CMAKE_INSTALL_INCLUDEDIR@) endif() # warn when using a deprecated package diff --git a/cmake/templates/python_distutils_install.sh.in b/cmake/templates/python_distutils_install.sh.in index dd35f732b..bb06e11ac 100755 --- a/cmake/templates/python_distutils_install.sh.in +++ b/cmake/templates/python_distutils_install.sh.in @@ -15,8 +15,10 @@ echo_and_run() { echo "+ $@" ; "$@" ; } echo_and_run cd "@INSTALL_CMD_WORKING_DIRECTORY@" -# ensure that Python install destination exists -echo_and_run mkdir -p "$DESTDIR@CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_DIR@" +# Ensure that Python install destination exists. The .. is necessary since we +# want to use the GNUInstallDirs-aware location variable, but PYTHON_INSTALL_DIR +# already includes the "lib" prefix. +echo_and_run mkdir -p "$DESTDIR@CMAKE_INSTALL_PREFIX@/@CATKIN_GLOBAL_LIB_DESTINATION@/../@PYTHON_INSTALL_DIR@" # Note that PYTHONPATH is pulled from the environment to support installing # into one location when some dependencies were installed in another @@ -30,4 +32,7 @@ echo_and_run /usr/bin/env \ build --build-base "@CMAKE_CURRENT_BINARY_DIR@" \ install \ --root="${DESTDIR-/}" \ - @SETUPTOOLS_ARG_EXTRA@ --prefix="@CMAKE_INSTALL_PREFIX@" --install-scripts="@CMAKE_INSTALL_PREFIX@/@CATKIN_GLOBAL_BIN_DESTINATION@" + @SETUPTOOLS_ARG_EXTRA@ \ + --prefix="@CMAKE_INSTALL_PREFIX@" \ + --install-scripts="@CMAKE_INSTALL_PREFIX@/@CATKIN_GLOBAL_BIN_DESTINATION@" \ + --install-lib="@CMAKE_INSTALL_PREFIX@/@CATKIN_GLOBAL_LIB_DESTINATION@/../@PYTHON_INSTALL_DIR@" From 176b9066e6c7a97bb9b66b2e9791777ed1dc764a Mon Sep 17 00:00:00 2001 From: Mike Purvis Date: Thu, 2 Mar 2023 00:13:25 -0500 Subject: [PATCH 2/3] Accept PREFIX with absolute LIBDIR/DATADIR. --- cmake/catkin_package.cmake | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmake/catkin_package.cmake b/cmake/catkin_package.cmake index c5e3f840b..86cee1cce 100644 --- a/cmake/catkin_package.cmake +++ b/cmake/catkin_package.cmake @@ -401,8 +401,18 @@ function(_catkin_package) set(DEVELSPACE FALSE) set(INSTALLSPACE TRUE) - set(PROJECT_SPACE_LIBDIR ${CMAKE_INSTALL_PREFIX}/${CATKIN_GLOBAL_LIB_DESTINATION}) - set(PROJECT_SPACE_DATADIR ${CMAKE_INSTALL_PREFIX}/${CATKIN_GLOBAL_SHARE_DESTINATION}) + # Guarding the prefix insertion on whether the destination vars are specified as absolute + # paths permits both the GNUInstallDirs vars and CMAKE_PREFIX_PATH to be set. + if(IS_ABSOLUTE ${CATKIN_GLOBAL_LIB_DESTINATION}) + set(PROJECT_SPACE_LIBDIR ${CATKIN_GLOBAL_LIB_DESTINATION}) + else() + set(PROJECT_SPACE_LIBDIR ${CMAKE_INSTALL_PREFIX}/${CATKIN_GLOBAL_LIB_DESTINATION}) + endif() + if(IS_ABSOLUTE ${CATKIN_GLOBAL_SHARE_DESTINATION}) + set(PROJECT_SPACE_DATADIR ${CATKIN_GLOBAL_SHARE_DESTINATION}) + else() + set(PROJECT_SPACE_DATADIR ${CMAKE_INSTALL_PREFIX}/${CATKIN_GLOBAL_SHARE_DESTINATION}) + endif() set(PKG_INCLUDE_PREFIX "\\\${prefix}") # absolute path to include dir under install prefix if any include dir is set From fa0ccff2b8c9f754015a4e9efd0b25881d6269ab Mon Sep 17 00:00:00 2001 From: Mike Purvis Date: Thu, 11 May 2023 21:37:31 -0400 Subject: [PATCH 3/3] Set xxxDIR without the INSTALL_ prefix. --- cmake/templates/pkgConfig.cmake.in | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmake/templates/pkgConfig.cmake.in b/cmake/templates/pkgConfig.cmake.in index 3d09cae88..cb4788274 100644 --- a/cmake/templates/pkgConfig.cmake.in +++ b/cmake/templates/pkgConfig.cmake.in @@ -71,15 +71,19 @@ if("@DEVELSPACE@" STREQUAL "TRUE") set(@PROJECT_NAME@_DEVEL_PREFIX @CATKIN_DEVEL_PREFIX@) set(@PROJECT_NAME@_INSTALL_PREFIX "") set(@PROJECT_NAME@_PREFIX ${@PROJECT_NAME@_DEVEL_PREFIX}) + set(@PROJECT_NAME@_BINDIR ${@PROJECT_NAME@_DEVEL_PREFIX}) + set(@PROJECT_NAME@_LIBDIR ${@PROJECT_NAME@_DEVEL_PREFIX}) + set(@PROJECT_NAME@_DATADIR ${@PROJECT_NAME@_DEVEL_PREFIX}) + set(@PROJECT_NAME@_INCLUDEDIR ${@PROJECT_NAME@_DEVEL_PREFIX}) else() set(@PROJECT_NAME@_SOURCE_PREFIX "") set(@PROJECT_NAME@_DEVEL_PREFIX "") set(@PROJECT_NAME@_INSTALL_PREFIX @CMAKE_INSTALL_PREFIX@) set(@PROJECT_NAME@_PREFIX ${@PROJECT_NAME@_INSTALL_PREFIX}) - set(@PROJECT_NAME@_INSTALL_BINDIR @CMAKE_INSTALL_BINDIR@) - set(@PROJECT_NAME@_INSTALL_LIBDIR @CMAKE_INSTALL_LIBDIR@) - set(@PROJECT_NAME@_INSTALL_DATADIR @CMAKE_INSTALL_DATADIR@) - set(@PROJECT_NAME@_INSTALL_INCLUDEDIR @CMAKE_INSTALL_INCLUDEDIR@) + set(@PROJECT_NAME@_BINDIR @CMAKE_INSTALL_BINDIR@) + set(@PROJECT_NAME@_LIBDIR @CMAKE_INSTALL_LIBDIR@) + set(@PROJECT_NAME@_DATADIR @CMAKE_INSTALL_DATADIR@) + set(@PROJECT_NAME@_INCLUDEDIR @CMAKE_INSTALL_INCLUDEDIR@) endif() # warn when using a deprecated package