Skip to content

Commit

Permalink
Use GNUInstallDirs for catkin and catkin packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepurvis committed Mar 1, 2023
1 parent ff31d45 commit a134099
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
13 changes: 7 additions & 6 deletions cmake/all.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 13 additions & 10 deletions cmake/catkin_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}")

Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand All @@ -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()
4 changes: 4 additions & 0 deletions cmake/templates/pkgConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions cmake/templates/python_distutils_install.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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@"

0 comments on commit a134099

Please sign in to comment.