Skip to content

Commit 32bfc12

Browse files
committed
Add CMAKE_C_FLAGS for clang-3
1 parent e553722 commit 32bfc12

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

builder/actions/cmake.py

+33-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# SPDX-License-Identifier: Apache-2.0.
33

44
import os
5+
import pprint
56
import re
67
import shutil
8+
from collections import defaultdict
79
from functools import lru_cache, partial
810
from pathlib import Path
911

@@ -100,6 +102,28 @@ def _project_dirs(env, project):
100102
return source_dir, build_dir, install_dir
101103

102104

105+
def _merge_cmake_lang_flags(cmake_args):
106+
print("=== _merge_cmake_lang_flags: cmake args")
107+
pprint.pprint(cmake_args, indent=4, depth=4)
108+
pattern = re.compile(r'''-D(CMAKE_C(?:XX)?_FLAGS)=["']?([^"']+)''')
109+
110+
new_cmake_args = []
111+
112+
cmake_lang_flags = defaultdict(list)
113+
for arg in cmake_args:
114+
m = pattern.match(arg)
115+
if m:
116+
cmake_lang_flags[m.group(1)].append(m.group(2))
117+
else:
118+
new_cmake_args.append(arg)
119+
120+
pprint.pprint(cmake_lang_flags, indent=4, depth=4)
121+
122+
for (k, v) in cmake_lang_flags.items():
123+
new_cmake_args.append('-D{}={}'.format(k, ' '.join(v)))
124+
125+
return new_cmake_args
126+
103127
def _build_project(env, project, cmake_extra, build_tests=False, args_transformer=None, coverage=False):
104128
sh = env.shell
105129
config = project.get_config(env.spec)
@@ -135,6 +159,7 @@ def _build_project(env, project, cmake_extra, build_tests=False, args_transforme
135159

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

205+
# If there are multiple of the same -DCMAKE_<LANG>_FLAGS arguments, CMake takes only the last one.
206+
# Since -DCMAKE_<LANG>_FLAGS can be set in multiple places (e.g. in a default config for a specific platform or
207+
# compiler, in a user project's config, in this Python module, etc.), we should merge language flags into one per
208+
# language.
209+
cmake_args = _merge_cmake_lang_flags(cmake_args)
210+
print("=== _build_project: cmake_args: {}".format(cmake_args))
211+
180212
# Allow caller to programmatically tweak the cmake_args,
181213
# as a last resort in case data merging wasn't working out
182214
if args_transformer:
@@ -199,7 +231,7 @@ def _build_project(env, project, cmake_extra, build_tests=False, args_transforme
199231

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

204236

205237
class CMakeBuild(Action):

builder/core/data.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ class PKG_TOOLS(Enum):
509509
'c': "clang-3.9",
510510
'cxx': "clang++-3.9",
511511
# specific version number in use
512-
'releases': ['3.9']
512+
'releases': ['3.9'],
513+
'cmake_args': ['-DCMAKE_C_FLAGS=-Wno-missing-field-initializers'],
513514
},
514515
'6': {
515516
'c': "clang-6.0",

0 commit comments

Comments
 (0)