Skip to content

Commit

Permalink
[SCons] Create buildutils.compiler_flag_list
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Aug 25, 2022
1 parent 7f309cd commit 60b3fb6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
14 changes: 4 additions & 10 deletions platform/posix/SConscript
Expand Up @@ -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)
Expand Down
17 changes: 1 addition & 16 deletions samples/cxx/SConscript
Expand Up @@ -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"]])
Expand Down
23 changes: 22 additions & 1 deletion site_scons/buildutils.py
Expand Up @@ -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, \
Expand Down Expand Up @@ -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}"'
Expand Down

0 comments on commit 60b3fb6

Please sign in to comment.