diff --git a/conan/tools/meson/meson.py b/conan/tools/meson/meson.py index 1f99ade0efc..17fa5924100 100644 --- a/conan/tools/meson/meson.py +++ b/conan/tools/meson/meson.py @@ -46,8 +46,7 @@ def configure(self, reconfigure=False): else: # extra native file for cross-building scenarios cmd += f' --native-file "{native}"' cmd += ' "{}" "{}"'.format(build_folder, source_folder) - # Issue related: https://github.com/mesonbuild/meson/issues/12880 - cmd += ' --prefix=/' # this must be an absolute path, otherwise, meson complains + cmd += f" --prefix={self._prefix}" self._conanfile.output.info("Meson configure cmd: {}".format(cmd)) self._conanfile.run(cmd) @@ -112,3 +111,30 @@ def _install_verbosity(self): # so it's a bit backwards verbosity = self._conanfile.conf.get("tools.build:verbosity", choices=("quiet", "verbose")) return "--quiet" if verbosity else "" + + @property + def _prefix(self): + """Generate a valid ``--prefix`` argument value for meson. + For conan, the prefix must be similar to the Unix root directory ``/``. + + The result of this function should be passed to + ``meson setup --prefix={self._prefix} ...`` + + Python 3.13 changed the semantics of ``/`` on the Windows ntpath module, + it is now special-cased as a relative directory. + Thus, ``os.path.isabs("/")`` is true on Linux but false on Windows. + So for Windows, an equivalent path is ``C:\\``. However, this can be + parsed wrongly in meson in specific circumstances due to the trailing + backslash. Hence, we also use forward slashes for Windows, leaving us + with ``C:/`` or similar paths. + + See also + -------- + * The meson issue discussing the need to set ``--prefix`` to ``/``: + `mesonbuild/meson#12880 `_ + * The cpython PR introducing the ``/`` behavior change: + `python/cpython#113829 `_ + * The issue detailing the erroneous parsing of ``\\``: + `conan-io/conan#14213 `_ + """ + return os.path.abspath("/").replace("\\", "/")