Repository: mesonbuild/meson

Issue:
Computation of PACKAGE_PREFIX_DIR in Config.cmake file on Windows uses \..\.. instead of ../../
**Describe the bug**
Generating a CMake Config file on Windows results in @PACKAGE_INIT@ macro generating the wrong cmake code, which prevents correct computation of the PACKAGE_PREFIX_DIR variable.

**To Reproduce**
meson.build:
```
project('test', 'c')

cmake_mod = import('cmake')

conf = configuration_data()
cmake_mod.configure_package_config_file(
  name: 'myProject',
  input: 'myProject.cmake.in',
  configuration: conf)
```
myProject.cmake.in:
```
@PACKAGE_INIT@
```
execute:
```sh
$ meson build
$ cat build\myProjectConfig.cmake

####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was C:\Users\Riccardo\source\repos\test\myProject.cmake.in ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/..\..\.." ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()
```

####################################################################################

**Expected behavior**
```
$ cat build\myProjectConfig.cmake

####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was C:\Users\Riccardo\source\repos\test\myProject.cmake.in ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()
```
```

**system parameters**
* Is this a [cross build](https://mesonbuild.com/Cross-compilation.html) or just a plain native build (for the same computer)? native
* what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.) Windows 10
* what Python version are you using e.g. 3.10.0
* what `meson --version` 0.60.2
* what `ninja --version` if it's a Ninja build 1.8.2



Discussion:
Duplicate of https://github.com/mesonbuild/meson/issues/6955

Resolving patch:
diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py
--- a/mesonbuild/modules/cmake.py
+++ b/mesonbuild/modules/cmake.py
@@ -391,7 +391,8 @@ def configure_package_config_file(self, state: ModuleState, args: TYPE_var, kwar
         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)


Test patch:
diff --git a/test cases/cmake/26 cmake package prefix dir/cmakePackagePrefixDirConfig.cmake.in b/test cases/cmake/26 cmake package prefix dir/cmakePackagePrefixDirConfig.cmake.in
new file mode 100644
--- /dev/null
+++ b/test cases/cmake/26 cmake package prefix dir/cmakePackagePrefixDirConfig.cmake.in	
@@ -0,0 +1 @@
+@PACKAGE_INIT@
diff --git a/test cases/cmake/26 cmake package prefix dir/meson.build b/test cases/cmake/26 cmake package prefix dir/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/cmake/26 cmake package prefix dir/meson.build	
@@ -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)')
diff --git a/test cases/cmake/26 cmake package prefix dir/test.json b/test cases/cmake/26 cmake package prefix dir/test.json
new file mode 100644
--- /dev/null
+++ b/test cases/cmake/26 cmake package prefix dir/test.json	
@@ -0,0 +1,5 @@
+{
+  "installed": [
+    {"type": "file", "file": "usr/lib/cmake/cmakePackagePrefixDir/cmakePackagePrefixDirConfig.cmake"}
+  ]
+}