Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Apr 9, 2024
1 parent ce4f5df commit 2a87015
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
15 changes: 14 additions & 1 deletion conan/tools/meson/helpers.py
Expand Up @@ -2,7 +2,7 @@
from conan.tools.build.flags import cppstd_msvc_flag
from conans.model.options import _PackageOption

__all__ = ["to_meson_machine", "to_meson_value", "to_cppstd_flag"]
__all__ = ["to_meson_machine", "to_meson_value", "to_cppstd_flag", "to_cstd_flag"]

# https://mesonbuild.com/Reference-tables.html#operating-system-names
_meson_system_map = {
Expand Down Expand Up @@ -126,3 +126,16 @@ def to_cppstd_flag(compiler, compiler_version, cppstd):
return 'v%s' % flag if flag else None
else:
return _cppstd_map.get(cppstd)


def to_cstd_flag(cstd):
""" possible values
none, c89, c99, c11, c17, c18, c2x, c23, gnu89, gnu99, gnu11, gnu17, gnu18, gnu2x, gnu23
"""
_cstd_map = {
'99': "c99",
'11': "c11",
'17': "c17",
'23': "c23",
}
return _cstd_map.get(cstd, cstd)
5 changes: 5 additions & 0 deletions conan/tools/meson/toolchain.py
Expand Up @@ -73,6 +73,7 @@ class MesonToolchain(object):
{% if b_ndebug %}b_ndebug = {{b_ndebug}}{% endif %}
{% if b_staticpic %}b_staticpic = {{b_staticpic}}{% endif %}
{% if cpp_std %}cpp_std = '{{cpp_std}}' {% endif %}
{% if c_std %}c_std = '{{c_std}}' {% endif %}
{% if backend %}backend = '{{backend}}' {% endif %}
{% if pkg_config_path %}pkg_config_path = '{{pkg_config_path}}'{% endif %}
{% if build_pkg_config_path %}build.pkg_config_path = '{{build_pkg_config_path}}'{% endif %}
Expand Down Expand Up @@ -138,6 +139,9 @@ def __init__(self, conanfile, backend=None):
cppstd = self._conanfile.settings.get_safe("compiler.cppstd")
self._cpp_std = to_cppstd_flag(compiler, compiler_version, cppstd)

cstd = self._conanfile.settings.get_safe("compiler.cstd")
self._c_std = to_cstd_flag(cstd)

self._b_vscrt = None
if compiler in ("msvc", "clang"):
vscrt = msvc_runtime_flag(self._conanfile)
Expand Down Expand Up @@ -433,6 +437,7 @@ def _sanitize_format(v):
"b_ndebug": to_meson_value(self._b_ndebug), # boolean as string
# https://mesonbuild.com/Builtin-options.html#compiler-options
"cpp_std": self._cpp_std,
"c_std": self._c_std,
"c_args": to_meson_value(self._filter_list_empty_fields(self.c_args)),
"c_link_args": to_meson_value(self._filter_list_empty_fields(self.c_link_args)),
"cpp_args": to_meson_value(self._filter_list_empty_fields(self.cpp_args)),
Expand Down
1 change: 1 addition & 0 deletions conans/model/conan_file.py
Expand Up @@ -138,6 +138,7 @@ def serialize(self):
result["version"] = str(self.version) if self.version is not None else None
result["topics"] = list(self.topics) if self.topics is not None else None
result["package_type"] = str(self.package_type)
result["languages"] = self.languages

settings = self.settings
if settings is not None:
Expand Down
4 changes: 4 additions & 0 deletions conans/model/conanfile_interface.py
Expand Up @@ -100,6 +100,10 @@ def is_build_context(self):
def package_type(self):
return self._conanfile.package_type

@property
def languages(self):
return self._conanfile.languages

@property
def info(self):
return self._conanfile.info
Expand Down
Expand Up @@ -137,6 +137,7 @@ def test_correct_quotes():
compiler=gcc
compiler.version=9
compiler.cppstd=17
compiler.cstd=11
compiler.libcxx=libstdc++11
build_type=Release
""")
Expand All @@ -147,6 +148,7 @@ def test_correct_quotes():
t.run("install . -pr:h=profile -pr:b=profile")
content = t.load(MesonToolchain.native_filename)
assert "cpp_std = 'c++17'" in content
assert "c_std = 'c11'" in content
assert "backend = 'ninja'" in content
assert "buildtype = 'release'" in content

Expand Down

0 comments on commit 2a87015

Please sign in to comment.