Skip to content

Commit

Permalink
Add CMAKE_C_FLAGS for clang-3
Browse files Browse the repository at this point in the history
  • Loading branch information
sfodagain committed Jun 7, 2024
1 parent e553722 commit 32bfc12
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
34 changes: 33 additions & 1 deletion builder/actions/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# SPDX-License-Identifier: Apache-2.0.

import os
import pprint
import re
import shutil
from collections import defaultdict
from functools import lru_cache, partial
from pathlib import Path

Expand Down Expand Up @@ -100,6 +102,28 @@ def _project_dirs(env, project):
return source_dir, build_dir, install_dir


def _merge_cmake_lang_flags(cmake_args):
print("=== _merge_cmake_lang_flags: cmake args")
pprint.pprint(cmake_args, indent=4, depth=4)
pattern = re.compile(r'''-D(CMAKE_C(?:XX)?_FLAGS)=["']?([^"']+)''')

new_cmake_args = []

cmake_lang_flags = defaultdict(list)
for arg in cmake_args:
m = pattern.match(arg)
if m:
cmake_lang_flags[m.group(1)].append(m.group(2))
else:
new_cmake_args.append(arg)

pprint.pprint(cmake_lang_flags, indent=4, depth=4)

for (k, v) in cmake_lang_flags.items():
new_cmake_args.append('-D{}={}'.format(k, ' '.join(v)))

return new_cmake_args

def _build_project(env, project, cmake_extra, build_tests=False, args_transformer=None, coverage=False):
sh = env.shell
config = project.get_config(env.spec)
Expand Down Expand Up @@ -135,6 +159,7 @@ def _build_project(env, project, cmake_extra, build_tests=False, args_transforme

# Set compiler flags
compiler_flags = []
c_path = None
if toolchain.compiler != 'default' and toolchain.compiler != 'msvc' and not toolchain.cross_compile:
c_path = toolchain.compiler_path()
cxx_path = toolchain.cxx_compiler_path()
Expand Down Expand Up @@ -177,6 +202,13 @@ def _build_project(env, project, cmake_extra, build_tests=False, args_transforme
else:
raise Exception('--coverage only support GCC as compiler. Current compiler is: {}'.format(c_path))

# If there are multiple of the same -DCMAKE_<LANG>_FLAGS arguments, CMake takes only the last one.
# Since -DCMAKE_<LANG>_FLAGS can be set in multiple places (e.g. in a default config for a specific platform or
# compiler, in a user project's config, in this Python module, etc.), we should merge language flags into one per
# language.
cmake_args = _merge_cmake_lang_flags(cmake_args)
print("=== _build_project: cmake_args: {}".format(cmake_args))

# Allow caller to programmatically tweak the cmake_args,
# as a last resort in case data merging wasn't working out
if args_transformer:
Expand All @@ -199,7 +231,7 @@ def _build_project(env, project, cmake_extra, build_tests=False, args_transforme

# build & install
sh.exec(*toolchain.shell_env, cmake, "--build", project_build_dir, "--config",
build_config, "--target", "install", working_dir=working_dir, check=True)
build_config, "--verbose", "--target", "install", working_dir=working_dir, check=True)


class CMakeBuild(Action):
Expand Down
3 changes: 2 additions & 1 deletion builder/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ class PKG_TOOLS(Enum):
'c': "clang-3.9",
'cxx': "clang++-3.9",
# specific version number in use
'releases': ['3.9']
'releases': ['3.9'],
'cmake_args': ['-DCMAKE_C_FLAGS=-Wno-missing-field-initializers'],
},
'6': {
'c': "clang-6.0",
Expand Down

0 comments on commit 32bfc12

Please sign in to comment.