Skip to content

Commit

Permalink
MesonToolchain reads conf tools.build:defines (#16172)
Browse files Browse the repository at this point in the history
* MesonToolchain reads conf tools.build:defines

* renamed test define var
  • Loading branch information
franramirez688 authored Apr 29, 2024
1 parent e8d22ce commit 2326609
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
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

0 comments on commit 2326609

Please sign in to comment.