diff --git a/conan/tools/meson/meson.py b/conan/tools/meson/meson.py index 4827ea3ec41..2d7317b80f0 100644 --- a/conan/tools/meson/meson.py +++ b/conan/tools/meson/meson.py @@ -47,7 +47,7 @@ def configure(self, reconfigure=False): cmd += "".join([f'{cmd_param} "{meson_option}"' for meson_option in meson_filenames]) cmd += ' "{}" "{}"'.format(build_folder, source_folder) if self._conanfile.package_folder: - cmd += ' -Dprefix="{}"'.format(self._conanfile.package_folder) + cmd += ' -Dprefix="{}"'.format(self._conanfile.package_folder.replace("\\", "/")) if reconfigure: cmd += ' --reconfigure' self._conanfile.output.info("Meson configure cmd: {}".format(cmd)) diff --git a/conan/tools/meson/toolchain.py b/conan/tools/meson/toolchain.py index e9b77d8e4ba..d4cec0da483 100644 --- a/conan/tools/meson/toolchain.py +++ b/conan/tools/meson/toolchain.py @@ -32,11 +32,6 @@ class MesonToolchain(object): [constants] preprocessor_definitions = [{% for it, value in preprocessor_definitions.items() -%} '-D{{ it }}="{{ value}}"'{%- if not loop.last %}, {% endif %}{% endfor %}] - # Constants to be overridden by conan_meson_deps_flags.ini (if exists) - deps_c_args = [] - deps_c_link_args = [] - deps_cpp_args = [] - deps_cpp_link_args = [] [project options] {% for it, value in project_options.items() -%} @@ -69,16 +64,16 @@ class MesonToolchain(object): {% if backend %}backend = '{{backend}}' {% endif %} {% if pkg_config_path %}pkg_config_path = '{{pkg_config_path}}'{% endif %} # C/C++ arguments - c_args = {{c_args}} + preprocessor_definitions + deps_c_args - c_link_args = {{c_link_args}} + deps_c_link_args - cpp_args = {{cpp_args}} + preprocessor_definitions + deps_cpp_args - cpp_link_args = {{cpp_link_args}} + deps_cpp_link_args + c_args = {{c_args}} + preprocessor_definitions + c_link_args = {{c_link_args}} + cpp_args = {{cpp_args}} + preprocessor_definitions + cpp_link_args = {{cpp_link_args}} {% if is_apple_system %} # Objective-C/C++ arguments - objc_args = {{objc_args}} + preprocessor_definitions + deps_c_args - objc_link_args = {{objc_link_args}} + deps_c_link_args - objcpp_args = {{objcpp_args}} + preprocessor_definitions + deps_cpp_args - objcpp_link_args = {{objcpp_link_args}} + deps_cpp_link_args + objc_args = {{objc_args}} + preprocessor_definitions + objc_link_args = {{objc_link_args}} + objcpp_args = {{objcpp_args}} + preprocessor_definitions + objcpp_link_args = {{objcpp_link_args}} {% endif %} {% for context, values in cross_build.items() %} diff --git a/conans/test/functional/toolchains/meson/test_meson.py b/conans/test/functional/toolchains/meson/test_meson.py index 3a846b87e35..52c9cf02fc1 100644 --- a/conans/test/functional/toolchains/meson/test_meson.py +++ b/conans/test/functional/toolchains/meson/test_meson.py @@ -235,3 +235,64 @@ def build(self): # Checking the order of the appended user file (the order matters) match = re.search(r"meson setup --native-file .* --native-file \"myfilename\.ini\"", client.out) assert match + + +@pytest.mark.tool("meson") +@pytest.mark.skipif(platform.system() != "Windows", reason="Only for Windows") +@pytest.mark.skipif(sys.version_info.minor < 8, reason="Latest Meson versions needs Python >= 3.8") +def test_meson_using_prefix_path_in_application(): + """ + Issue related https://github.com/conan-io/conan/issues/14213 + """ + meson_build = textwrap.dedent(""" + project('myhello ', 'c') + executable('myhello', 'src/main.c', install: true) + + prefix_dir = get_option('prefix') + cfg_var = configuration_data() + cfg_var.set_quoted('MYHELLO_PREFIX', prefix_dir) + + config_file = configure_file( + configuration: cfg_var, + output: 'config.h' + ) + """) + main_c = textwrap.dedent(""" + #include + + int main(void) { + return 0; + } + + char *issue_func() { + return (MYHELLO_PREFIX); + } + """) + conanfile = textwrap.dedent(""" + from conan import ConanFile + from conan.tools.meson import Meson + from conan.tools.layout import basic_layout + + class myhelloConan(ConanFile): + name = "demo" + version = "0.1" + settings = "os", "compiler", "build_type", "arch" + exports_sources = "meson.build", "*.c" + package_type = "application" + generators = "MesonToolchain" + + def layout(self): + basic_layout(self) + + def build(self): + meson = Meson(self) + meson.configure() + meson.build() + """) + client = TestClient() + client.save({"conanfile.py": conanfile, + "src/main.c": main_c, + "meson.build": meson_build}) + client.run("build .") + assert "unrecognized character escape sequence" not in str(client.out) # if Visual + assert "unknown escape sequence" not in str(client.out) # if mingw