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..86cee1cce 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,24 @@ function(_catkin_package) set(DEVELSPACE FALSE) set(INSTALLSPACE TRUE) - set(PROJECT_SPACE_DIR ${CMAKE_INSTALL_PREFIX}) + # 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 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 +446,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 +461,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 +508,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 +534,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..cb4788274 100644 --- a/cmake/templates/pkgConfig.cmake.in +++ b/cmake/templates/pkgConfig.cmake.in @@ -71,11 +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@_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 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@"