From db292f6f0238581a489aa8cddc585129b6e920cd Mon Sep 17 00:00:00 2001 From: Marco Rebhan Date: Wed, 26 Oct 2022 20:49:52 +0200 Subject: [PATCH] Pass through absolute paths to cmake config directly The previous code concatenates includedir to _harfbuzz_prefix verbatim, which results in a wrong final include path in case includedir is an absolute path. Instead, we can let meson determine the absolute include and lib paths in advance and save them in the cmake config. This is an issue in nixpkgs, where includedir is set to the final (absolute) path of the built library in the Nix store, which causes CMake projects depending on harfbuzz to not configure. See https://github.com/NixOS/nixpkgs/issues/180054. --- src/harfbuzz-config.cmake.in | 44 +++++++----------------------------- src/meson.build | 4 ++-- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/src/harfbuzz-config.cmake.in b/src/harfbuzz-config.cmake.in index 304410d9b..0de082c2a 100644 --- a/src/harfbuzz-config.cmake.in +++ b/src/harfbuzz-config.cmake.in @@ -1,29 +1,5 @@ -# Set these variables so that the `${prefix}/lib` expands to something we can -# remove. -set(_harfbuzz_remove_string "REMOVE_ME") -set(exec_prefix "${_harfbuzz_remove_string}") -set(prefix "${_harfbuzz_remove_string}") - -# Compute the installation prefix by stripping components from our current -# location. -get_filename_component(_harfbuzz_prefix "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY) -get_filename_component(_harfbuzz_prefix "${_harfbuzz_prefix}" DIRECTORY) set(_harfbuzz_libdir "@libdir@") -string(REPLACE "${_harfbuzz_remove_string}/" "" _harfbuzz_libdir "${_harfbuzz_libdir}") -set(_harfbuzz_libdir_iter "${_harfbuzz_libdir}") -while (_harfbuzz_libdir_iter) - set(_harfbuzz_libdir_prev_iter "${_harfbuzz_libdir_iter}") - get_filename_component(_harfbuzz_libdir_iter "${_harfbuzz_libdir_iter}" DIRECTORY) - if (_harfbuzz_libdir_prev_iter STREQUAL _harfbuzz_libdir_iter) - break() - endif () - get_filename_component(_harfbuzz_prefix "${_harfbuzz_prefix}" DIRECTORY) -endwhile () -unset(_harfbuzz_libdir_iter) - -# Get the include subdir. set(_harfbuzz_includedir "@includedir@") -string(REPLACE "${_harfbuzz_remove_string}/" "" _harfbuzz_includedir "${_harfbuzz_includedir}") # Extract version information from libtool. set(_harfbuzz_version_info "@HB_LIBTOOL_VERSION_INFO@") @@ -48,29 +24,29 @@ endif () # Add the libraries. add_library(harfbuzz::harfbuzz SHARED IMPORTED) set_target_properties(harfbuzz::harfbuzz PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${_harfbuzz_prefix}/${_harfbuzz_includedir}/harfbuzz" - IMPORTED_LOCATION "${_harfbuzz_prefix}/${_harfbuzz_libdir}/libharfbuzz${_harfbuzz_lib_suffix}") + INTERFACE_INCLUDE_DIRECTORIES "${_harfbuzz_includedir}/harfbuzz" + IMPORTED_LOCATION "${_harfbuzz_libdir}/libharfbuzz${_harfbuzz_lib_suffix}") add_library(harfbuzz::icu SHARED IMPORTED) set_target_properties(harfbuzz::icu PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${_harfbuzz_prefix}/${_harfbuzz_includedir}/harfbuzz" + INTERFACE_INCLUDE_DIRECTORIES "${_harfbuzz_includedir}/harfbuzz" INTERFACE_LINK_LIBRARIES "harfbuzz::harfbuzz" - IMPORTED_LOCATION "${_harfbuzz_prefix}/${_harfbuzz_libdir}/libharfbuzz-icu${_harfbuzz_lib_suffix}") + IMPORTED_LOCATION "${_harfbuzz_libdir}/libharfbuzz-icu${_harfbuzz_lib_suffix}") add_library(harfbuzz::subset SHARED IMPORTED) set_target_properties(harfbuzz::subset PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${_harfbuzz_prefix}/${_harfbuzz_includedir}/harfbuzz" + INTERFACE_INCLUDE_DIRECTORIES "${_harfbuzz_includedir}/harfbuzz" INTERFACE_LINK_LIBRARIES "harfbuzz::harfbuzz" - IMPORTED_LOCATION "${_harfbuzz_prefix}/${_harfbuzz_libdir}/libharfbuzz-subset${_harfbuzz_lib_suffix}") + IMPORTED_LOCATION "${_harfbuzz_libdir}/libharfbuzz-subset${_harfbuzz_lib_suffix}") # Only add the gobject library if it was built. set(_harfbuzz_have_gobject "@have_gobject@") if (_harfbuzz_have_gobject) add_library(harfbuzz::gobject SHARED IMPORTED) set_target_properties(harfbuzz::gobject PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${_harfbuzz_prefix}/${_harfbuzz_includedir}/harfbuzz" + INTERFACE_INCLUDE_DIRECTORIES "${_harfbuzz_includedir}/harfbuzz" INTERFACE_LINK_LIBRARIES "harfbuzz::harfbuzz" - IMPORTED_LOCATION "${_harfbuzz_prefix}/${_harfbuzz_libdir}/libharfbuzz-gobject${_harfbuzz_lib_suffix}") + IMPORTED_LOCATION "${_harfbuzz_libdir}/libharfbuzz-gobject${_harfbuzz_lib_suffix}") endif () # Clean out variables we used in our scope. @@ -80,7 +56,3 @@ unset(_harfbuzz_revision) unset(_harfbuzz_age) unset(_harfbuzz_includedir) unset(_harfbuzz_libdir) -unset(_harfbuzz_prefix) -unset(exec_prefix) -unset(prefix) -unset(_harfbuzz_remove_string) diff --git a/src/meson.build b/src/meson.build index ba3470fff..d53e77b5f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -657,8 +657,8 @@ endif have_gobject = conf.get('HAVE_GOBJECT', 0) == 1 cmake_config = configuration_data() -cmake_config.set('libdir', '${prefix}/@0@'.format(get_option('libdir'))) -cmake_config.set('includedir', '${prefix}/@0@'.format(get_option('includedir'))) +cmake_config.set('libdir', get_option('prefix') / get_option('libdir')) +cmake_config.set('includedir', get_option('prefix') / get_option('includedir')) cmake_config.set('HB_LIBTOOL_VERSION_INFO', hb_libtool_version_info) cmake_config.set('have_gobject', '@0@'.format(have_gobject)) configure_file(input: 'harfbuzz-config.cmake.in',