diff --git a/IlmBase/config/CMakeLists.txt b/IlmBase/config/CMakeLists.txt index dfebb43bd0..8b0eae7fcb 100644 --- a/IlmBase/config/CMakeLists.txt +++ b/IlmBase/config/CMakeLists.txt @@ -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) @@ -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}") string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) set(LIB_SUFFIX_DASH ${ILMBASE_LIB_SUFFIX}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}) if(TARGET Threads::Threads) diff --git a/OpenEXR/config/CMakeLists.txt b/OpenEXR/config/CMakeLists.txt index 039190cd90..d13ee16ee9 100644 --- a/OpenEXR/config/CMakeLists.txt +++ b/OpenEXR/config/CMakeLists.txt @@ -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) @@ -75,8 +76,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}") string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) set(LIB_SUFFIX_DASH ${OPENEXR_LIB_SUFFIX}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}) if(TARGET Threads::Threads) diff --git a/cmake/JoinPaths.cmake b/cmake/JoinPaths.cmake new file mode 100644 index 0000000000..b5bc2e57f8 --- /dev/null +++ b/cmake/JoinPaths.cmake @@ -0,0 +1,23 @@ +# This module provides function for joining paths +# known from from most languages +# +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenEXR Project. +# 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()