@@ -15,7 +15,6 @@ from types import ModuleType
15
15
16
16
from SCons import __version__ as scons_raw_version
17
17
from SCons .Builder import ListEmitter
18
- from SCons .Util import CLVar
19
18
20
19
# Explicitly resolve the helper modules, this is done to avoid clash with
21
20
# modules of the same name that might be randomly added (e.g. someone adding
@@ -451,7 +450,7 @@ env.Prepend(CPPPATH=["#"])
451
450
452
451
# Allow marking includes as external/system to avoid raising warnings.
453
452
env ["_CCCOMCOM" ] += " $_CPPEXTINCFLAGS"
454
- env ["CPPEXTPATH" ] = CLVar ( "" )
453
+ env ["CPPEXTPATH" ] = []
455
454
if env .scons_version < (4 , 2 ):
456
455
env ["_CPPEXTINCFLAGS" ] = "${_concat(EXTINCPREFIX, CPPEXTPATH, EXTINCSUFFIX, __env__, RDirs, TARGET, SOURCE)}"
457
456
else :
@@ -727,78 +726,75 @@ elif methods.using_clang(env) or methods.using_emcc(env):
727
726
# Set optimize and debug_symbols flags.
728
727
# "custom" means do nothing and let users set their own optimization flags.
729
728
# Needs to happen after configure to have `env.msvc` defined.
729
+ env .AppendUnique (CCFLAGS = ["$OPTIMIZELEVEL" ])
730
730
if env .msvc :
731
731
if env ["debug_symbols" ]:
732
- env .Append (CCFLAGS = ["/Zi" , "/FS" ])
733
- env .Append (LINKFLAGS = ["/DEBUG:FULL" ])
732
+ env .AppendUnique (CCFLAGS = ["/Zi" , "/FS" ])
733
+ env .AppendUnique (LINKFLAGS = ["/DEBUG:FULL" ])
734
734
else :
735
- env .Append (LINKFLAGS = ["/DEBUG:NONE" ])
735
+ env .AppendUnique (LINKFLAGS = ["/DEBUG:NONE" ])
736
736
737
737
if env ["optimize" ].startswith ("speed" ):
738
- env . Append ( CCFLAGS = [ " /O2"])
739
- env .Append (LINKFLAGS = ["/OPT:REF" ])
738
+ env [ "OPTIMIZELEVEL" ] = " /O2"
739
+ env .AppendUnique (LINKFLAGS = ["/OPT:REF" ])
740
740
if env ["optimize" ] == "speed_trace" :
741
- env .Append (LINKFLAGS = ["/OPT:NOICF" ])
741
+ env .AppendUnique (LINKFLAGS = ["/OPT:NOICF" ])
742
742
elif env ["optimize" ].startswith ("size" ):
743
- env . Append ( CCFLAGS = [ " /O1"])
744
- env .Append (LINKFLAGS = ["/OPT:REF" ])
743
+ env [ "OPTIMIZELEVEL" ] = " /O1"
744
+ env .AppendUnique (LINKFLAGS = ["/OPT:REF" ])
745
745
if env ["optimize" ] == "size_extra" :
746
- env .Append (CPPDEFINES = ["SIZE_EXTRA" ])
746
+ env .AppendUnique (CPPDEFINES = ["SIZE_EXTRA" ])
747
747
elif env ["optimize" ] == "debug" or env ["optimize" ] == "none" :
748
- env . Append ( CCFLAGS = [ " /Od"])
748
+ env [ "OPTIMIZELEVEL" ] = " /Od"
749
749
else :
750
750
if env ["debug_symbols" ]:
751
751
if env ["platform" ] == "windows" :
752
752
if methods .using_clang (env ):
753
- env .Append (CCFLAGS = ["-gdwarf-4" ]) # clang dwarf-5 symbols are broken on Windows.
753
+ env .AppendUnique (CCFLAGS = ["-gdwarf-4" ]) # clang dwarf-5 symbols are broken on Windows.
754
754
else :
755
- env .Append (CCFLAGS = ["-gdwarf-5" ]) # For gcc, only dwarf-5 symbols seem usable by libbacktrace.
755
+ env .AppendUnique (CCFLAGS = ["-gdwarf-5" ]) # For gcc, only dwarf-5 symbols seem usable by libbacktrace.
756
756
else :
757
757
# Adding dwarf-4 explicitly makes stacktraces work with clang builds,
758
758
# otherwise addr2line doesn't understand them
759
- env .Append (CCFLAGS = ["-gdwarf-4" ])
759
+ env .AppendUnique (CCFLAGS = ["-gdwarf-4" ])
760
760
if methods .using_emcc (env ):
761
761
# Emscripten only produces dwarf symbols when using "-g3".
762
- env .Append (CCFLAGS = ["-g3" ])
762
+ env .AppendUnique (CCFLAGS = ["-g3" ])
763
763
# Emscripten linker needs debug symbols options too.
764
- env .Append (LINKFLAGS = ["-gdwarf-4" ])
765
- env .Append (LINKFLAGS = ["-g3" ])
764
+ env .AppendUnique (LINKFLAGS = ["-gdwarf-4" ])
765
+ env .AppendUnique (LINKFLAGS = ["-g3" ])
766
766
elif env .dev_build :
767
- env .Append (CCFLAGS = ["-g3" ])
767
+ env .AppendUnique (CCFLAGS = ["-g3" ])
768
768
else :
769
- env .Append (CCFLAGS = ["-g2" ])
769
+ env .AppendUnique (CCFLAGS = ["-g2" ])
770
770
if env ["debug_paths_relative" ]:
771
771
# Remap absolute paths to relative paths for debug symbols.
772
772
project_path = Dir ("#" ).abspath
773
- env .Append (CCFLAGS = [f"-ffile-prefix-map={ project_path } =." ])
773
+ env .AppendUnique (CCFLAGS = [f"-ffile-prefix-map={ project_path } =." ])
774
774
else :
775
775
if methods .is_apple_clang (env ):
776
776
# Apple Clang, its linker doesn't like -s.
777
- env .Append (LINKFLAGS = ["-Wl,-S" , "-Wl,-x" , "-Wl,-dead_strip" ])
777
+ env .AppendUnique (LINKFLAGS = ["-Wl,-S" , "-Wl,-x" , "-Wl,-dead_strip" ])
778
778
else :
779
- env .Append (LINKFLAGS = ["-s" ])
779
+ env .AppendUnique (LINKFLAGS = ["-s" ])
780
780
781
781
# Linker needs optimization flags too, at least for Emscripten.
782
782
# For other toolchains, this _may_ be useful for LTO too to disambiguate.
783
+ env .AppendUnique (LINKFLAGS = ["$OPTIMIZELEVEL" ])
783
784
784
785
if env ["optimize" ] == "speed" :
785
- env .Append (CCFLAGS = ["-O3" ])
786
- env .Append (LINKFLAGS = ["-O3" ])
786
+ env ["OPTIMIZELEVEL" ] = "-O3"
787
787
# `-O2` is friendlier to debuggers than `-O3`, leading to better crash backtraces.
788
788
elif env ["optimize" ] == "speed_trace" :
789
- env .Append (CCFLAGS = ["-O2" ])
790
- env .Append (LINKFLAGS = ["-O2" ])
789
+ env ["OPTIMIZELEVEL" ] = "-O2"
791
790
elif env ["optimize" ].startswith ("size" ):
792
- env .Append (CCFLAGS = ["-Os" ])
793
- env .Append (LINKFLAGS = ["-Os" ])
791
+ env ["OPTIMIZELEVEL" ] = "-Os"
794
792
if env ["optimize" ] == "size_extra" :
795
- env .Append (CPPDEFINES = ["SIZE_EXTRA" ])
793
+ env .AppendUnique (CPPDEFINES = ["SIZE_EXTRA" ])
796
794
elif env ["optimize" ] == "debug" :
797
- env .Append (CCFLAGS = ["-Og" ])
798
- env .Append (LINKFLAGS = ["-Og" ])
795
+ env ["OPTIMIZELEVEL" ] = "-Og"
799
796
elif env ["optimize" ] == "none" :
800
- env .Append (CCFLAGS = ["-O0" ])
801
- env .Append (LINKFLAGS = ["-O0" ])
797
+ env ["OPTIMIZELEVEL" ] = "-O0"
802
798
803
799
# Needs to happen after configure to handle "auto".
804
800
if env ["lto" ] != "none" :
@@ -839,6 +835,7 @@ elif env.msvc:
839
835
env .Append (CXXFLAGS = ["/EHsc" ])
840
836
841
837
# Configure compiler warnings
838
+ env .AppendUnique (CCFLAGS = ["$WARNLEVEL" ])
842
839
if env .msvc and not methods .using_clang (env ): # MSVC
843
840
# Disable warnings which we don't plan to fix.
844
841
disabled_warnings = [
@@ -856,19 +853,23 @@ if env.msvc and not methods.using_clang(env): # MSVC
856
853
]
857
854
858
855
if env ["warnings" ] == "extra" :
859
- env .Append (CCFLAGS = ["/W4" ] + disabled_warnings )
856
+ env ["WARNLEVEL" ] = "/W4"
857
+ env .AppendUnique (CCFLAGS = disabled_warnings )
860
858
elif env ["warnings" ] == "all" :
859
+ env ["WARNLEVEL" ] = "/W3"
861
860
# C4458 is like -Wshadow. Part of /W4 but let's apply it for the default /W3 too.
862
- env .Append (CCFLAGS = ["/W3" , "/w34458" ] + disabled_warnings )
861
+ env .AppendUnique (CCFLAGS = ["/w34458" ] + disabled_warnings )
863
862
elif env ["warnings" ] == "moderate" :
864
- env .Append (CCFLAGS = ["/W2" ] + disabled_warnings )
863
+ env ["WARNLEVEL" ] = "/W2"
864
+ env .AppendUnique (CCFLAGS = disabled_warnings )
865
865
else : # 'no'
866
+ env ["WARNLEVEL" ] = "/w"
866
867
# C4267 is particularly finicky & needs to be explicitly disabled.
867
- env .Append (CCFLAGS = ["/w" , "/wd4267" ])
868
+ env .AppendUnique (CCFLAGS = ["/wd4267" ])
868
869
869
870
if env ["werror" ]:
870
- env .Append (CCFLAGS = ["/WX" ])
871
- env .Append (LINKFLAGS = ["/WX" ])
871
+ env .AppendUnique (CCFLAGS = ["/WX" ])
872
+ env .AppendUnique (LINKFLAGS = ["/WX" ])
872
873
873
874
else : # GCC, Clang
874
875
common_warnings = []
@@ -887,45 +888,47 @@ else: # GCC, Clang
887
888
# for putting them in `Set` or `Map`. We don't mind about unreliable ordering.
888
889
common_warnings += ["-Wno-ordered-compare-function-pointers" ]
889
890
890
- # clang-cl will interpret `-Wall` as `-Weverything`, workaround with compatibility cast
891
- W_ALL = "-Wall" if not env .msvc else "-W3"
891
+ # clang-cl will interpret `-Wall` as `-Weverything`, workaround with compatibility cast.
892
+ env [ "WARNLEVEL" ] = "-Wall" if not env .msvc else "-W3"
892
893
893
894
if env ["warnings" ] == "extra" :
894
- env .Append (CCFLAGS = [W_ALL , "-Wextra" , "-Wwrite-strings" , "-Wno-unused-parameter" ] + common_warnings )
895
- env .Append (CXXFLAGS = ["-Wctor-dtor-privacy" , "-Wnon-virtual-dtor" ])
895
+ env .AppendUnique (CCFLAGS = ["-Wextra" , "-Wwrite-strings" , "-Wno-unused-parameter" ] + common_warnings )
896
+ env .AppendUnique (CXXFLAGS = ["-Wctor-dtor-privacy" , "-Wnon-virtual-dtor" ])
896
897
if methods .using_gcc (env ):
897
- env .Append (
898
+ env .AppendUnique (
898
899
CCFLAGS = [
899
900
"-Walloc-zero" ,
900
901
"-Wduplicated-branches" ,
901
902
"-Wduplicated-cond" ,
902
903
"-Wstringop-overflow=4" ,
903
904
]
904
905
)
905
- env .Append (CXXFLAGS = ["-Wplacement-new=1" , "-Wvirtual-inheritance" ])
906
+ env .AppendUnique (CXXFLAGS = ["-Wplacement-new=1" , "-Wvirtual-inheritance" ])
906
907
# Need to fix a warning with AudioServer lambdas before enabling.
907
908
# if cc_version_major != 9: # GCC 9 had a regression (GH-36325).
908
909
# env.Append(CXXFLAGS=["-Wnoexcept"])
909
910
if cc_version_major >= 9 :
910
- env .Append (CCFLAGS = ["-Wattribute-alias=2" ])
911
+ env .AppendUnique (CCFLAGS = ["-Wattribute-alias=2" ])
911
912
if cc_version_major >= 11 : # Broke on MethodBind templates before GCC 11.
912
- env .Append (CCFLAGS = ["-Wlogical-op" ])
913
+ env .AppendUnique (CCFLAGS = ["-Wlogical-op" ])
913
914
elif methods .using_clang (env ) or methods .using_emcc (env ):
914
- env .Append (CCFLAGS = ["-Wimplicit-fallthrough" ])
915
+ env .AppendUnique (CCFLAGS = ["-Wimplicit-fallthrough" ])
915
916
elif env ["warnings" ] == "all" :
916
- env .Append (CCFLAGS = [ W_ALL ] + common_warnings )
917
+ env .AppendUnique (CCFLAGS = common_warnings )
917
918
elif env ["warnings" ] == "moderate" :
918
- env .Append (CCFLAGS = [W_ALL , "-Wno-unused" ] + common_warnings )
919
+ env .AppendUnique (CCFLAGS = ["-Wno-unused" ] + common_warnings )
919
920
else : # 'no'
920
- env . Append ( CCFLAGS = [ " -w"])
921
+ env [ "WARNLEVEL" ] = " -w"
921
922
922
923
if env ["werror" ]:
923
- env .Append (CCFLAGS = ["-Werror" ])
924
+ env .AppendUnique (CCFLAGS = ["-Werror" ])
924
925
925
926
# Configure external includes.
926
927
if env .msvc :
927
- if cc_version_major < 16 or (cc_version_major == 16 and cc_version_minor < 10 ):
928
- env .AppendUnique (CCFLAGS = ["/experimental:external" ])
928
+ if not methods .using_clang (env ):
929
+ if cc_version_major < 16 or (cc_version_major == 16 and cc_version_minor < 10 ):
930
+ env .AppendUnique (CCFLAGS = ["/experimental:external" ])
931
+ env .AppendUnique (CCFLAGS = ["/external:anglebrackets" ])
929
932
env .AppendUnique (CCFLAGS = ["/external:W0" ])
930
933
env ["EXTINCPREFIX" ] = "/external:I"
931
934
env ["EXTINCSUFFIX" ] = ""
0 commit comments