diff --git a/platform/posix/SConscript b/platform/posix/SConscript index 0d55079b4c..90cc845456 100644 --- a/platform/posix/SConscript +++ b/platform/posix/SConscript @@ -83,16 +83,10 @@ if localenv["package_build"]: # conda package for now. # Users should compile against their local SDKs, which should be backwards # compatible with the SDK used for building. - cc_flags = [] - for flag in localenv["CCFLAGS"]: - if not flag.startswith(("-isysroot", "-mmacosx", "/App")): - cc_flags.append(flag) - localenv["CCFLAGS"] = cc_flags - cc_flags = [] - for flag in localenv["CXXFLAGS"]: - if not flag.startswith(("-isysroot", "-mmacosx", "/App")): - cc_flags.append(flag) - localenv["CXXFLAGS"] = cc_flags + excludes = ( + "-isysroot", "-mmacosx", "-march", "-mtune", "-fdebug-prefix-map") + localenv["CCFLAGS"] = compiler_flag_list(localenv["CCFLAGS"], excludes) + localenv["CXXFLAGS"] = compiler_flag_list(localenv["CXXFLAGS"], excludes) mak = build(localenv.SubstFile('Cantera.mak', 'Cantera.mak.in')) install('$inst_incdir', mak) diff --git a/samples/cxx/SConscript b/samples/cxx/SConscript index a6a3de0a6b..bd0d98c973 100644 --- a/samples/cxx/SConscript +++ b/samples/cxx/SConscript @@ -59,24 +59,9 @@ set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}) # conda package for now. # Users should compile against their local SDKs, which should be backwards # compatible with the SDK used for building. - def split_compiler_flags(flags, excludes=[]): - """ - Separate concatenated compiler flags in flag list. - Entries listed in 'exclude' are omitted. - """ - flags = " ".join(flags) - flags = f" {flags}".split(" -")[1:] - # split concatenated entries - flags = [f"-{flag}" for flag in flags] - cc_flags = [] - for flag in flags: - if not flag.startswith(excludes) and flag not in cc_flags: - cc_flags.append(flag) - return cc_flags - excludes = ( "-isysroot", "-mmacosx", "-march", "-mtune", "-fdebug-prefix-map") - cc_flags = split_compiler_flags(localenv["CCFLAGS"] + localenv["CXXFLAGS"], + cc_flags = compiler_flag_list(localenv["CCFLAGS"] + localenv["CXXFLAGS"], excludes) else: incdirs.extend([localenv["sundials_include"], localenv["boost_inc_dir"]]) diff --git a/site_scons/buildutils.py b/site_scons/buildutils.py index 2c5eb5c1b8..899b743a73 100644 --- a/site_scons/buildutils.py +++ b/site_scons/buildutils.py @@ -25,7 +25,7 @@ "logger", "remove_directory", "remove_file", "test_results", "add_RegressionTest", "get_command_output", "listify", "which", "ConfigBuilder", "multi_glob", "get_spawn", "quoted", - "get_pip_install_location") + "get_pip_install_location", "compiler_flag_list") if TYPE_CHECKING: from typing import Iterable, TypeVar, Union, List, Dict, Tuple, Optional, \ @@ -1092,6 +1092,27 @@ def add_RegressionTest(env: "SCEnvironment") -> None: ) +def compiler_flag_list( + flags: "Union[str, Iterable]", + excludes: "Optional[Iterable]" = [] + ) -> "List[str]": + """ + Separate concatenated compiler flags in ``flags``. + Entries listed in ``excludes`` are omitted. + """ + if not isinstance(flags, str): + flags = " ".join(flags) + # split concatenated entries + flags = f" {flags}".split(" -")[1:] + flags = [f"-{flag}" for flag in flags] + cc_flags = [] + excludes = tuple(excludes) + for flag in flags: + if not flag.startswith(excludes) and flag not in cc_flags: + cc_flags.append(flag) + return cc_flags + + def quoted(s: str) -> str: """Return the given string wrapped in double quotes.""" return f'"{s}"'