cmake: fix directory separators in generated packageConfig.cmake files

On windows, meson would mix posix and windows dir separators in the
computed PACKAGE_RELATIVE_PATH.

Here we force posix directory separator even on Windows. This matches
the CMake behavior and fixes interpretation of the resulting path.

Fixes #6955
Fixes #9702
pull/11583/head
Matthieu Rogez 2 years ago committed by Eli Schwartz
parent d2d31c3cc2
commit b92858a5be
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 3
      mesonbuild/modules/cmake.py
  2. 1
      test cases/cmake/26 cmake package prefix dir/cmakePackagePrefixDirConfig.cmake.in
  3. 19
      test cases/cmake/26 cmake package prefix dir/meson.build
  4. 5
      test cases/cmake/26 cmake package prefix dir/test.json

@ -391,7 +391,8 @@ class CmakeModule(ExtensionModule):
if not os.path.isabs(abs_install_dir):
abs_install_dir = os.path.join(prefix, install_dir)
PACKAGE_RELATIVE_PATH = os.path.relpath(prefix, abs_install_dir)
# path used in cmake scripts are POSIX even on Windows
PACKAGE_RELATIVE_PATH = pathlib.PurePath(os.path.relpath(prefix, abs_install_dir)).as_posix()
extra = ''
if re.match('^(/usr)?/lib(64)?/.+', abs_install_dir):
extra = PACKAGE_INIT_EXT.replace('@absInstallDir@', abs_install_dir)

@ -0,0 +1,19 @@
project('cmakePackagePrefixDir', 'c', version: '1.0.0')
cmake = import('cmake')
cmake.configure_package_config_file(
name: 'cmakePackagePrefixDir',
input: 'cmakePackagePrefixDirConfig.cmake.in',
configuration: configuration_data(),
)
# NOTE: can't use fs.read because cmakePackagePrefixDirConfig.cmake is in build_dir
python = find_program('python3')
lines = run_command(python, '-c',
'[print(line, end="") for line in open("@0@")]'.format(meson.current_build_dir() / 'cmakePackagePrefixDirConfig.cmake'), check : true,
).stdout().split('\n')
message(lines)
assert(lines[5] == 'get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)')

@ -0,0 +1,5 @@
{
"installed": [
{"type": "file", "file": "usr/lib/cmake/cmakePackagePrefixDir/cmakePackagePrefixDirConfig.cmake"}
]
}
Loading…
Cancel
Save