diff --git a/CMakeLists.txt b/CMakeLists.txt index 05849677d6..0c4b3f5a9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,8 @@ if (EXIV2_TEAM_PACKAGING) include(cmake/packaging.cmake) endif() +join_paths(libdir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_LIBDIR}") +join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") configure_file(cmake/exiv2.pc.in exiv2.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/exiv2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/cmake/JoinPaths.cmake b/cmake/JoinPaths.cmake new file mode 100644 index 0000000000..cfd54c9c98 --- /dev/null +++ b/cmake/JoinPaths.cmake @@ -0,0 +1,24 @@ +# This module provides function for joining paths +# known from from most languages +# +# Original license: +# 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() diff --git a/cmake/exiv2.pc.in b/cmake/exiv2.pc.in index 9018472be8..cea7604229 100644 --- a/cmake/exiv2.pc.in +++ b/cmake/exiv2.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} -libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ -includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ +libdir=@libdir_for_pc_file@ +includedir=@includedir_for_pc_file@ Name: exiv2 Description: @PROJECT_DESCRIPTION@ diff --git a/cmake/mainSetup.cmake b/cmake/mainSetup.cmake index d8d7c30b93..1c2ffe3981 100644 --- a/cmake/mainSetup.cmake +++ b/cmake/mainSetup.cmake @@ -5,6 +5,7 @@ include(GNUInstallDirs) include(CheckFunctionExists) include(GenerateExportHeader) include(CMakeDependentOption) +include(cmake/JoinPaths.cmake) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) @@ -27,7 +28,7 @@ if (UNIX) set(CMAKE_MACOSX_RPATH ON) set(CMAKE_INSTALL_RPATH "@loader_path") else() - set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}") + join_paths(CMAKE_INSTALL_RPATH "$ORIGIN" ".." "${CMAKE_INSTALL_LIBDIR}") endif() endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index efabea7e09..b910b86777 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -207,7 +207,8 @@ if( EXIV2_ENABLE_NLS ) target_include_directories(exiv2lib PRIVATE ${Intl_INCLUDE_DIRS}) target_include_directories(exiv2lib_int PRIVATE ${Intl_INCLUDE_DIRS}) # Definition needed for translations - target_compile_definitions(exiv2lib PUBLIC EXV_LOCALEDIR="/../${CMAKE_INSTALL_LOCALEDIR}") + join_paths(EXV_LOCALEDIR ".." "${CMAKE_INSTALL_LOCALEDIR}") + target_compile_definitions(exiv2lib PUBLIC EXV_LOCALEDIR="${EXV_LOCALEDIR}") endif() if( ICONV_FOUND ) diff --git a/src/exiv2.cpp b/src/exiv2.cpp index 5d2bc12a3b..2be1974d66 100644 --- a/src/exiv2.cpp +++ b/src/exiv2.cpp @@ -40,7 +40,7 @@ int main(int argc, char* const argv[]) #ifdef EXV_ENABLE_NLS setlocale(LC_ALL, ""); - const std::string localeDir = Exiv2::getProcessPath() + EXV_LOCALEDIR; + const std::string localeDir = EXV_LOCALEDIR[0] == '/' ? EXV_LOCALEDIR : (Exiv2::getProcessPath() + EXV_SEPARATOR_STR + EXV_LOCALEDIR); bindtextdomain(EXV_PACKAGE_NAME, localeDir.c_str()); textdomain(EXV_PACKAGE_NAME); #endif diff --git a/src/types.cpp b/src/types.cpp index 961ffb9fcd..5d07fa4b27 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -815,7 +815,7 @@ const char* _exvGettext(const char* str) if (!exvGettextInitialized) { // bindtextdomain(EXV_PACKAGE_NAME, EXV_LOCALEDIR); - const std::string localeDir = Exiv2::getProcessPath() + EXV_LOCALEDIR; + const std::string localeDir = EXV_LOCALEDIR[0] == '/' ? EXV_LOCALEDIR : (Exiv2::getProcessPath() + EXV_SEPARATOR_STR + EXV_LOCALEDIR); bindtextdomain(EXV_PACKAGE_NAME, localeDir.c_str()); #ifdef EXV_HAVE_BIND_TEXTDOMAIN_CODESET bind_textdomain_codeset(EXV_PACKAGE_NAME, "UTF-8");