build(tools): update mfem build and packaging tools
This commit is contained in:
@@ -87,6 +87,11 @@ def parse_args() -> argparse.Namespace:
|
||||
parser.add_argument("--cc-launcher", action="append", default=[])
|
||||
parser.add_argument("--cxx-launcher", action="append", default=[])
|
||||
parser.add_argument("--buildtype", required=True)
|
||||
parser.add_argument("--optimization", choices=("plain", "0", "g", "1", "2", "3", "s"), required=True)
|
||||
parser.add_argument("--debug", choices=("true", "false"), required=True)
|
||||
parser.add_argument("--ndebug", choices=("true", "false"), required=True)
|
||||
parser.add_argument("--compiler-syntax", choices=("gcc", "msvc"), required=True)
|
||||
parser.add_argument("--compiler-id", default="")
|
||||
parser.add_argument("--jobs", type=int, required=True)
|
||||
parser.add_argument("--host-system", required=True)
|
||||
parser.add_argument("--cross-build", choices=("true", "false"), required=True)
|
||||
@@ -288,6 +293,32 @@ def compiler_flags(build_type: str) -> str:
|
||||
}[build_type]
|
||||
|
||||
|
||||
def mfem_compile_flags(args: argparse.Namespace) -> str:
|
||||
"""Use Meson's effective options, not CMake's implicit -O3 -DNDEBUG.
|
||||
|
||||
MFEM_DEBUG is separately selected by CMAKE_BUILD_TYPE. In particular,
|
||||
debugoptimized retains symbols without enabling MFEM's expensive checks.
|
||||
"""
|
||||
if args.compiler_syntax == "msvc":
|
||||
flags = {
|
||||
"plain": [], "0": ["/Od"], "g": [], "1": ["/O1"],
|
||||
"2": ["/O2"], "3": ["/O2", "/Gw"], "s": ["/O1", "/Gw"],
|
||||
}[args.optimization].copy()
|
||||
if args.debug == "true":
|
||||
flags.append("/Zi")
|
||||
if args.ndebug == "true":
|
||||
flags.append("/DNDEBUG")
|
||||
else:
|
||||
flags = [] if args.optimization == "plain" else ["-O" + args.optimization]
|
||||
if args.optimization == "s" and args.compiler_id in {"clang", "apple-clang", "emscripten"}:
|
||||
flags = ["-Oz"]
|
||||
if args.debug == "true":
|
||||
flags.append("-g")
|
||||
if args.ndebug == "true":
|
||||
flags.append("-DNDEBUG")
|
||||
return " ".join(flags)
|
||||
|
||||
|
||||
def joined_flags(values: Sequence[str]) -> str:
|
||||
return " ".join(shlex.quote(value) for value in values)
|
||||
|
||||
@@ -1411,6 +1442,8 @@ def build_mfem(
|
||||
options = common_cmake_args(
|
||||
args, build_type, c_compiler=args.cc, cxx_compiler=args.cxx
|
||||
) + [
|
||||
f"-DCMAKE_C_FLAGS_{build_type.upper()}={mfem_compile_flags(args)}",
|
||||
f"-DCMAKE_CXX_FLAGS_{build_type.upper()}={mfem_compile_flags(args)}",
|
||||
"-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=OFF",
|
||||
"-DMFEM_ENABLE_TESTING=OFF",
|
||||
"-DMFEM_ENABLE_EXAMPLES=OFF",
|
||||
@@ -1606,6 +1639,14 @@ def validate_mfem_feature_header(
|
||||
if not header.is_file():
|
||||
raise RuntimeError("MFEM feature validation failed: _config.hpp is missing")
|
||||
text = header.read_text(encoding="utf-8")
|
||||
debug_defined = re.search(
|
||||
r"^\s*#\s*define\s+MFEM_DEBUG(?:\s|$)", text, flags=re.MULTILINE
|
||||
) is not None
|
||||
if debug_defined != (cmake_build_type(args.buildtype) == "Debug"):
|
||||
raise RuntimeError(
|
||||
"MFEM feature validation failed: MFEM_DEBUG disagrees with "
|
||||
f"Meson buildtype={args.buildtype}; rebuild the MFEM bundle"
|
||||
)
|
||||
for feature_name, macro in CMAKE_FEATURES.items():
|
||||
is_defined = re.search(
|
||||
rf"^\s*#\s*define\s+{re.escape(macro)}(?:\s|$)",
|
||||
@@ -2432,6 +2473,7 @@ def main() -> int:
|
||||
if config_file.is_file():
|
||||
old = json.loads(config_file.read_text(encoding="utf-8"))
|
||||
if old.get("fingerprint") == fingerprint and existing_libraries:
|
||||
validate_mfem_feature_header(args, features)
|
||||
if args.stamp:
|
||||
write_text_atomic(args.stamp, fingerprint + "\n")
|
||||
print("[mfem-bundle] configuration unchanged; reusing private prefix", flush=True)
|
||||
@@ -2586,6 +2628,8 @@ def main() -> int:
|
||||
"features": features,
|
||||
"compiler": compiler_identity,
|
||||
"build_type": build_type,
|
||||
"mfem_compile_flags": mfem_compile_flags(args),
|
||||
"mfem_debug": build_type == "Debug",
|
||||
"prefix": os.fspath(args.prefix),
|
||||
}
|
||||
write_text_atomic(config_file, json.dumps(manifest, indent=2, sort_keys=True) + "\n")
|
||||
|
||||
Reference in New Issue
Block a user