Skip to content

Commit

Permalink
Fix assumptions that CMAKE_INSTALL_*DIR variables are relative
Browse files Browse the repository at this point in the history
The CMAKE_INSTALL_*DIR variables are allowed to be absolute paths, which allows
libraries and headers to be installed into separate prefixes. This means they
cannot be naively concatenated with CMAKE_INSTALL_PREFIX. If an absolute path
is needed, CMAKE_INSTALL_FULL_*DIR should be used, while more complicated
handling is required to keep ${prefix} interpolation in pkg-config files in
the case where CMAKE_INSTALL_*DIR is relative.

Signed-off-by: Ben Wolsieffer <[email protected]>
  • Loading branch information
lopsided98 committed Oct 19, 2022
1 parent 4d6942f commit 3ff967e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ install(
COMPONENT dev)

# Generate Pkg-Config file
if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
set(CYCLONEDDS_PKG_CONFIG_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
else()
set(CYCLONEDDS_PKG_CONFIG_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(CYCLONEDDS_PKG_CONFIG_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
else()
set(CYCLONEDDS_PKG_CONFIG_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
endif()
configure_file(
"PkgConfig.pc.in"
"${PROJECT_NAME}.pc"
Expand Down
4 changes: 2 additions & 2 deletions PkgConfig.pc.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
prefix=@CMAKE_INSTALL_PREFIX@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=@CYCLONEDDS_PKG_CONFIG_INCLUDEDIR@
libdir=@CYCLONEDDS_PKG_CONFIG_LIBDIR@

Name: @PROJECT_NAME@
Description: Eclipse Cyclone DDS library
Expand Down
4 changes: 2 additions & 2 deletions ports/freertos-posix/freertos-sim.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
set(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@")
set(CMAKE_CXX_COMPILER "@CMAKE_CXX_COMPILER@")

set(include_path "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@")
set(library_path "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@")
set(include_path "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
set(library_path "@CMAKE_INSTALL_FULL_LIBDIR@")

set(CMAKE_C_FLAGS "-I${include_path} -Dmain=@ENTRYPOINT@ -m32")
set(CMAKE_EXE_LINKER_FLAGS "-L${library_path}")
Expand Down

0 comments on commit 3ff967e

Please sign in to comment.