From 7cb1415530a6e9d531a3f11d3cefb7a9f3f1195d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 8 Aug 2013 01:53:02 +0000 Subject: pass compiler defines such as __FLT_MIN__ to smatch and sparse (they fail without them). --- build_files/cmake/cmake_static_check_smatch.py | 4 +++- build_files/cmake/cmake_static_check_sparse.py | 4 +++- build_files/cmake/project_source_info.py | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) (limited to 'build_files') diff --git a/build_files/cmake/cmake_static_check_smatch.py b/build_files/cmake/cmake_static_check_smatch.py index 2cf07b093fb..ad8b872b22c 100644 --- a/build_files/cmake/cmake_static_check_smatch.py +++ b/build_files/cmake/cmake_static_check_smatch.py @@ -44,6 +44,7 @@ USE_QUIET = (os.environ.get("QUIET", None) is not None) def main(): source_info = project_source_info.build_info(use_cxx=False, ignore_prefix_list=CHECKER_IGNORE_PREFIX) + source_defines = project_source_info.build_defines_as_args() check_commands = [] for c, inc_dirs, defs in source_info: @@ -52,7 +53,8 @@ def main(): CHECKER_ARGS + [c] + [("-I%s" % i) for i in inc_dirs] + - [("-D%s" % d) for d in defs] + [("-D%s" % d) for d in defs] + + source_defines ) check_commands.append((c, cmd)) diff --git a/build_files/cmake/cmake_static_check_sparse.py b/build_files/cmake/cmake_static_check_sparse.py index 8a3fb477239..ff6b1af98b7 100644 --- a/build_files/cmake/cmake_static_check_sparse.py +++ b/build_files/cmake/cmake_static_check_sparse.py @@ -42,6 +42,7 @@ USE_QUIET = (os.environ.get("QUIET", None) is not None) def main(): source_info = project_source_info.build_info(use_cxx=False, ignore_prefix_list=CHECKER_IGNORE_PREFIX) + source_defines = project_source_info.build_defines_as_args() check_commands = [] for c, inc_dirs, defs in source_info: @@ -50,7 +51,8 @@ def main(): CHECKER_ARGS + [c] + [("-I%s" % i) for i in inc_dirs] + - [("-D%s" % d) for d in defs] + [("-D%s" % d) for d in defs] + + source_defines ) check_commands.append((c, cmd)) diff --git a/build_files/cmake/project_source_info.py b/build_files/cmake/project_source_info.py index 90e240c35ef..b28c8208d44 100644 --- a/build_files/cmake/project_source_info.py +++ b/build_files/cmake/project_source_info.py @@ -171,6 +171,26 @@ def build_info(use_c=True, use_cxx=True, ignore_prefix_list=None): return source +def build_defines_as_source(): + """ + Returns a string formatted as an include: + '#defines A=B\n#define....' + """ + import subprocess + # works for both gcc and clang + cmd = (cmake_cache_var("CMAKE_C_COMPILER"), "-dM", "-E", "-") + return subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stdin=subprocess.DEVNULL, + ).stdout.read().strip().decode('ascii') + + +def build_defines_as_args(): + return [("-D" + "=".join(l.split(maxsplit=2)[1:])) + for l in build_defines_as_source().split("\n") + if l.startswith('#define')] + + # could be moved elsewhere!, this just happens to be used by scripts that also # use this module. def queue_processes(process_funcs, job_total=-1): -- cgit v1.2.3