Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cmake installation by using GNUInstallDirs #338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 29 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,10 @@ if(UAGENT_ISOLATED_INSTALL)
endif()

include(GNUInstallDirs)
set(BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for binaries")
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Installation directory for C headers")
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Installation directory for libraries")
set(DATA_INSTALL_DIR ${CMAKE_INSTALL_DATADIR} CACHE PATH "Installation directory for data")
if(WIN32)
set(LICENSE_INSTALL_DIR . CACHE PATH "Installation directory for licenses")
else()
set(LICENSE_INSTALL_DIR ${DATA_INSTALL_DIR}/${PROJECT_NAME} CACHE PATH "Installation directory for licenses")
set(LICENSE_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME} CACHE PATH "Installation directory for licenses")
endif()

###############################################################################
Expand Down Expand Up @@ -310,7 +306,7 @@ target_include_directories(${PROJECT_NAME} BEFORE
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<TARGET_PROPERTY:fastcdr,INTERFACE_INCLUDE_DIRECTORIES>
PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/cpp>
Expand Down Expand Up @@ -397,11 +393,11 @@ install(
EXPORT
${PROJECT_NAME}Targets
RUNTIME DESTINATION
${BIN_INSTALL_DIR}
${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION
${LIB_INSTALL_DIR}
${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION
${LIB_INSTALL_DIR}
${CMAKE_INSTALL_LIBDIR}
COMPONENT
libraries
)
Expand All @@ -411,7 +407,7 @@ install(
DIRECTORY
${PROJECT_SOURCE_DIR}/include/uxr/agent/
DESTINATION
${INCLUDE_INSTALL_DIR}/uxr/agent
${CMAKE_INSTALL_INCLUDEDIR}/uxr/agent
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.h"
Expand All @@ -422,7 +418,7 @@ install(
EXPORT
${PROJECT_NAME}Targets
DESTINATION
${DATA_INSTALL_DIR}/${PROJECT_NAME}/cmake
${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake
)

# Install agent exec
Expand All @@ -433,11 +429,11 @@ if(UAGENT_BUILD_EXECUTABLE)
EXPORT
MicroXRCEAgentTargets
RUNTIME
DESTINATION ${BIN_INSTALL_DIR}
DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY
DESTINATION ${LIB_INSTALL_DIR}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE
DESTINATION ${LIB_INSTALL_DIR}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT
executables
)
Expand All @@ -453,7 +449,7 @@ install(
FILES
${PROJECT_BINARY_DIR}/include/uxr/agent/config.hpp
DESTINATION
${INCLUDE_INSTALL_DIR}/uxr/agent
${CMAKE_INSTALL_INCLUDEDIR}/uxr/agent
)

# Install licenses
Expand All @@ -473,12 +469,12 @@ configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/packaging/Config.cmake.in
${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION
${DATA_INSTALL_DIR}/${PROJECT_NAME}/cmake
${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake
PATH_VARS
BIN_INSTALL_DIR
INCLUDE_INSTALL_DIR
LIB_INSTALL_DIR
DATA_INSTALL_DIR
CMAKE_INSTALL_BINDIR
CMAKE_INSTALL_INCLUDEDIR
CMAKE_INSTALL_LIBDIR
CMAKE_INSTALL_DATADIR
)

write_basic_package_version_file(
Expand All @@ -494,7 +490,7 @@ install(
${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}Config.cmake
${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION
${DATA_INSTALL_DIR}/${PROJECT_NAME}/cmake
${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake
)

# Install default profile XML.
Expand All @@ -503,23 +499,25 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
FILES
${PROJECT_SOURCE_DIR}/agent.refs
DESTINATION
${BIN_INSTALL_DIR}
${CMAKE_INSTALL_BINDIR}
)
endif()

# Install dependencies.
if(EXISTS ${CMAKE_BINARY_DIR}/temp_install/)
file(GLOB _deps RELATIVE ${CMAKE_BINARY_DIR}/temp_install ${CMAKE_BINARY_DIR}/temp_install/*)
foreach(_d ${_deps})
install(
DIRECTORY
${CMAKE_BINARY_DIR}/temp_install/${_d}$<IF:$<BOOL:${UAGENT_ISOLATED_INSTALL}>,,/>
DESTINATION
${CMAKE_INSTALL_PREFIX}$<IF:$<BOOL:${UAGENT_ISOLATED_INSTALL}>,/../,>
COMPONENT
${_d}
USE_SOURCE_PERMISSIONS
)
if(UAGENT_ISOLATED_INSTALL)
install(
DIRECTORY
${CMAKE_BINARY_DIR}/temp_install/${_d}$<IF:$<BOOL:${UAGENT_ISOLATED_INSTALL}>,,/>
DESTINATION
${CMAKE_INSTALL_PREFIX}$<IF:$<BOOL:${UAGENT_ISOLATED_INSTALL}>,/../,>
COMPONENT
${_d}
USE_SOURCE_PERMISSIONS
)
endif()
endforeach()
endif()

Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ RUN apt-get install -y gradle
RUN apt-get clean

# Prepare Micro XRCE-DDS Agent workspace
RUN mkdir -p /agent/build
RUN mkdir -p /agent
ADD . /agent/

# Build Micro XRCE-DDS Agent and install
RUN cd /agent/build && \
cmake -DCMAKE_INSTALL_PREFIX=../install \
.. &&\
make -j $(nproc) && make install
RUN cd /agent && \
cmake -B build && \
cmake --build build -j $(nproc) && \
cmake --install build --prefix install

# Prepare Micro XRCE-DDS Agent artifacts
RUN cd /agent && \
Expand Down
8 changes: 4 additions & 4 deletions cmake/packaging/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ set(@PROJECT_NAME@_VERSION @PROJECT_VERSION@)
@PACKAGE_INIT@

if(MSVC OR MSVC_IDE)
set_and_check(@PROJECT_NAME@_BIN_DIR "@PACKAGE_BIN_INSTALL_DIR@")
set_and_check(@PROJECT_NAME@_BIN_DIR "@PACKAGE_CMAKE_INSTALL_BINDIR@")
endif()
set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(@PROJECT_NAME@_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@")
set_and_check(@PROJECT_NAME@_DATA_DIR "@PACKAGE_DATA_INSTALL_DIR@")
set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(@PROJECT_NAME@_LIB_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@")
set_and_check(@PROJECT_NAME@_DATA_DIR "@PACKAGE_CMAKE_INSTALL_DATADIR@")

foreach(d @_deps@)
list(GET d 0 _name)
Expand Down
8 changes: 4 additions & 4 deletions cmake/packaging/eProsimaPackaging.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ if(NOT((MSVC OR MSVC_IDE) AND EPROSIMA_INSTALLER))
include(CMakePackageConfigHelpers)
configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/packaging/Config.cmake.in
${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${LIB_INSTALL_DIR}${DIR_EXTENSION}/${PROJECT_NAME}/cmake
PATH_VARS BIN_INSTALL_DIR INCLUDE_INSTALL_DIR LIB_INSTALL_DIR
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}${DIR_EXTENSION}/${PROJECT_NAME}/cmake
PATH_VARS CMAKE_INSTALL_BINDIR CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
)
write_basic_package_version_file(${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES ${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}Config.cmake
${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${LIB_INSTALL_DIR}${DIR_EXTENSION}/${PROJECT_NAME}/cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}${DIR_EXTENSION}/${PROJECT_NAME}/cmake
COMPONENT cmake
)
endif()
Expand All @@ -64,7 +64,7 @@ set(CPACK_COMPONENTS_ALL ${CPACK_COMPONENTS_ALL} cmake)
if(WIN32)
if(EPROSIMA_INSTALLER_MINION)
install(FILES ${PROJECT_SOURCE_DIR}/cmake/packaging/windows/${PROJECT_NAME}Config.cmake
DESTINATION ${LIB_INSTALL_DIR}/${PROJECT_NAME}/cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake
COMPONENT cmake
)
endif()
Expand Down