Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MesonToolchain reads conf tools.build:defines #16172

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions conan/tools/meson/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,12 @@ def _get_extra_flags(self):
exelinkflags = self._conanfile.conf.get("tools.build:exelinkflags", default=[], check_type=list)
linker_scripts = self._conanfile.conf.get("tools.build:linker_scripts", default=[], check_type=list)
linker_script_flags = ['-T"' + linker_script + '"' for linker_script in linker_scripts]
defines = [f"-D{d}" for d in self._conanfile.conf.get("tools.build:defines", default=[], check_type=list)]
return {
"cxxflags": cxxflags,
"cflags": cflags,
"ldflags": sharedlinkflags + exelinkflags + linker_script_flags
"ldflags": sharedlinkflags + exelinkflags + linker_script_flags,
"defines": defines
}

@staticmethod
Expand All @@ -377,13 +379,13 @@ def _sanitize_format(v):
apple_flags = self.apple_isysroot_flag + self.apple_arch_flag + self.apple_min_version_flag
extra_flags = self._get_extra_flags()

self.c_args.extend(apple_flags + extra_flags["cflags"])
self.cpp_args.extend(apple_flags + extra_flags["cxxflags"])
self.c_args.extend(apple_flags + extra_flags["cflags"] + extra_flags["defines"])
self.cpp_args.extend(apple_flags + extra_flags["cxxflags"] + extra_flags["defines"])
self.c_link_args.extend(apple_flags + extra_flags["ldflags"])
self.cpp_link_args.extend(apple_flags + extra_flags["ldflags"])
# Objective C/C++
self.objc_args.extend(self.c_args)
self.objcpp_args.extend(self.cpp_args)
self.objc_args.extend(self.c_args + extra_flags["defines"])
self.objcpp_args.extend(self.cpp_args + extra_flags["defines"])
# These link_args have already the LDFLAGS env value so let's add only the new possible ones
self.objc_link_args.extend(apple_flags + extra_flags["ldflags"])
self.objcpp_link_args.extend(apple_flags + extra_flags["ldflags"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ def test_extra_flags_via_conf():
tools.build:cflags=["-flag3", "-flag4"]
tools.build:sharedlinkflags+=["-flag5"]
tools.build:exelinkflags+=["-flag6"]
# Issue related: https://github.com/conan-io/conan/issues/16169
tools.build:defines=["define1=0"]
""")
t = TestClient()
t.save({"conanfile.txt": "[generators]\nMesonToolchain",
"profile": profile})

t.run("install . -pr:h=profile -pr:b=profile")
content = t.load(MesonToolchain.native_filename)
assert "cpp_args = ['-flag0', '-other=val', '-flag1', '-flag2', '-D_GLIBCXX_USE_CXX11_ABI=0']" in content
assert "c_args = ['-flag0', '-other=val', '-flag3', '-flag4']" in content
assert "cpp_args = ['-flag0', '-other=val', '-flag1', '-flag2', '-Ddefine1=0', '-D_GLIBCXX_USE_CXX11_ABI=0']" in content
assert "c_args = ['-flag0', '-other=val', '-flag3', '-flag4', '-Ddefine1=0']" in content
assert "c_link_args = ['-flag0', '-other=val', '-flag5', '-flag6']" in content
assert "cpp_link_args = ['-flag0', '-other=val', '-flag5', '-flag6']" in content

Expand Down