From 0d1894736e2af5f377966ce499faa461a3c45774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Mon, 8 Jan 2024 18:09:04 +0100 Subject: [PATCH] SCons: Fix `CCFLAGS`, `LINKFLAGS`, etc. command line overrides Also adds `CPPDEFINES` which allows passing new pre-processor defines, letting SCons handle passing `-D` or `/D` based on the compiler. --- SConstruct | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/SConstruct b/SConstruct index 47a039fb148..b7809dfe42a 100644 --- a/SConstruct +++ b/SConstruct @@ -259,13 +259,16 @@ opts.Add(BoolVariable("builtin_zlib", "Use the built-in zlib library", True)) opts.Add(BoolVariable("builtin_zstd", "Use the built-in Zstd library", True)) # Compilation environment setup -opts.Add("CXX", "C++ compiler") -opts.Add("CC", "C compiler") -opts.Add("LINK", "Linker") -opts.Add("CCFLAGS", "Custom flags for both the C and C++ compilers") -opts.Add("CFLAGS", "Custom flags for the C compiler") -opts.Add("CXXFLAGS", "Custom flags for the C++ compiler") -opts.Add("LINKFLAGS", "Custom flags for the linker") +# CXX, CC, and LINK directly set the equivalent `env` values (which may still +# be overridden for a specific platform), the lowercase ones are appended. +opts.Add("CXX", "C++ compiler binary") +opts.Add("CC", "C compiler binary") +opts.Add("LINK", "Linker binary") +opts.Add("cppdefines", "Custom defines for the pre-processor") +opts.Add("ccflags", "Custom flags for both the C and C++ compilers") +opts.Add("cxxflags", "Custom flags for the C++ compiler") +opts.Add("cflags", "Custom flags for the C compiler") +opts.Add("linkflags", "Custom flags for the linker") # Update the environment to have all above options defined # in following code (especially platform and custom_modules). @@ -507,21 +510,11 @@ if selected_platform in platform_list: env.extra_suffix += "." + env["extra_suffix"] # Environment flags - CCFLAGS = env.get("CCFLAGS", "") - env["CCFLAGS"] = "" - env.Append(CCFLAGS=str(CCFLAGS).split()) - - CFLAGS = env.get("CFLAGS", "") - env["CFLAGS"] = "" - env.Append(CFLAGS=str(CFLAGS).split()) - - CXXFLAGS = env.get("CXXFLAGS", "") - env["CXXFLAGS"] = "" - env.Append(CXXFLAGS=str(CXXFLAGS).split()) - - LINKFLAGS = env.get("LINKFLAGS", "") - env["LINKFLAGS"] = "" - env.Append(LINKFLAGS=str(LINKFLAGS).split()) + env.Append(CPPDEFINES=env.get("cppdefines", "").split()) + env.Append(CCFLAGS=env.get("ccflags", "").split()) + env.Append(CXXFLAGS=env.get("cxxflags", "").split()) + env.Append(CFLAGS=env.get("cflags", "").split()) + env.Append(LINKFLAGS=env.get("linkflags", "").split()) # Feature build profile disabled_classes = []