diff --git a/CMakeLists.txt b/CMakeLists.txt index 4879d514..eddde1f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,6 +135,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 00000000..cfd54c9c --- /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 9018472b..cea76042 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 5bcc3fa5..fcaa21fa 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) @@ -23,7 +24,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 c3da2dc7..affb73ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -215,7 +215,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 a7c542ec..0754cd78 100644 --- a/src/exiv2.cpp +++ b/src/exiv2.cpp @@ -132,7 +132,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 17ab051e..1a70c66a 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -729,7 +729,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");