Skip to content

Commit

Permalink
cmake: Fix paths in .pc files
Browse files Browse the repository at this point in the history
It is not generally true that `CMAKE_INSTALL_<dir>` variables are relative paths:

https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files

With 0b26a9d,
CMake concatenates ${prefix} with the GNUInstallDirs variables, which leads to
`includedir=${prefix}/nix/store/x6wqbsys0px1xjpy17h01f0aqwj7khvg-openexr-2.5.2-dev/include`,
when the variables are absolute.

Let's join them properly as paths, not strings.

Signed-off-by: Jan Tojnar <[email protected]>
  • Loading branch information
jtojnar committed Aug 11, 2020
1 parent a5d0323 commit 6442fb7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 3 additions & 2 deletions IlmBase/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckLibraryExists)
include(CheckStructHasMember)
include(../../cmake/JoinPaths.cmake)

check_include_files(ucontext.h ILMBASE_HAVE_UCONTEXT_H)
if(ILMBASE_HAVE_UCONTEXT_H)
Expand Down Expand Up @@ -76,8 +77,8 @@ if(ILMBASE_INSTALL_PKG_CONFIG)
function(ilmbase_pkg_config_help pcinfile)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
join_paths(libdir "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(includedir "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
set(LIB_SUFFIX_DASH ${ILMBASE_LIB_SUFFIX})
if(TARGET Threads::Threads)
# hrm, can't use properties as they end up as generator expressions
Expand Down
5 changes: 3 additions & 2 deletions OpenEXR/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include(CheckSymbolExists)
include(CheckLibraryExists)
include(CheckStructHasMember)
include(CheckCXXSourceCompiles)
include(../../cmake/JoinPaths.cmake)

if (NOT CMAKE_CROSSCOMPILING AND EXISTS "/proc/self/exe")
set(OPENEXR_IMF_HAVE_LINUX_PROCFS TRUE)
Expand Down Expand Up @@ -76,8 +77,8 @@ if(OPENEXR_INSTALL_PKG_CONFIG)
function(openexr_pkg_config_help pcinfile)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
join_paths(libdir "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(includedir "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
set(LIB_SUFFIX_DASH ${OPENEXR_LIB_SUFFIX})
if(TARGET Threads::Threads)
# hrm, can't use properties as they end up as generator expressions
Expand Down
23 changes: 23 additions & 0 deletions cmake/JoinPaths.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This module provides function for joining paths
# known from from most languages
#
# SPDX-License-Identifier: (MIT OR CC0-1.0)
# Copyright 2020 Jan Tojnar
# https://github.com/jtojnar/cmake-snips
#
# Modelled after Python’s os.path.join
# https://docs.python.org/3.7/library/os.path.html#os.path.join
# Windows not supported
function(join_paths joined_path first_path_segment)
set(temp_path "${first_path_segment}")
foreach(current_segment IN LISTS ARGN)
if(NOT ("${current_segment}" STREQUAL ""))
if(IS_ABSOLUTE "${current_segment}")
set(temp_path "${current_segment}")
else()
set(temp_path "${temp_path}/${current_segment}")
endif()
endif()
endforeach()
set(${joined_path} "${temp_path}" PARENT_SCOPE)
endfunction()

0 comments on commit 6442fb7

Please sign in to comment.