Check if LTO is enabled
Check if LTO is enabled Add LTO flag Added a flag to enable/disable LTO. Also pass optimization options to the linker, since older versions of gcc may not automatically use the same options for linking and compiling, and it seems likely clang doesn't do this either. m3
This commit is contained in:
parent
84ab6fabf1
commit
0d419cdc36
3 changed files with 11 additions and 4 deletions
11
SConstruct
11
SConstruct
|
@ -55,6 +55,7 @@ opts.AddVariables(
|
|||
('extra_flags_debug', 'Extra compiler and linker flags to use for debug builds', ""),
|
||||
('extra_flags_profile', 'Extra compiler and linker flags to use for profile builds', ""),
|
||||
('extra_flags_optimize', 'Extra compiler and linker flags to use for optimized builds', ""),
|
||||
EnumVariable('enable_lto', 'Whether to enable Link Time Optimization', "", ["", "yes", "no"]),
|
||||
PathVariable('bindir', 'Where to install binaries', "bin", PathVariable.PathAccept),
|
||||
('cachedir', 'Directory that contains a cache of derived files.', ''),
|
||||
PathVariable('datadir', 'read-only architecture-independent game data', "$datarootdir/$datadirname", PathVariable.PathAccept),
|
||||
|
@ -507,7 +508,13 @@ for env in [test_env, client_env, env]:
|
|||
|
||||
env["OPT_FLAGS"] = "-O2"
|
||||
env["DEBUG_FLAGS"] = Split("-O0 -DDEBUG -ggdb3")
|
||||
env["HIGH_OPT_FLAGS"] = Split("-O3 -march=native -flto")
|
||||
|
||||
if env["enable_lto"] == "yes":
|
||||
env["HIGH_OPT_COMP_FLAGS"] = "-O3 -march=native -flto"
|
||||
env["HIGH_OPT_LINK_FLAGS"] = "$HIGH_OPT_COMP_FLAGS -fuse-ld=gold"
|
||||
else:
|
||||
env["HIGH_OPT_COMP_FLAGS"] = "-O3 -march=native"
|
||||
env["HIGH_OPT_LINK_FLAGS"] = ""
|
||||
|
||||
if "clang" in env["CXX"]:
|
||||
# Silence warnings about unused -I options and unknown warning switches.
|
||||
|
@ -556,7 +563,7 @@ builds = {
|
|||
"glibcxx_debug" : dict(CPPDEFINES = Split("_GLIBCXX_DEBUG _GLIBCXX_DEBUG_PEDANTIC")),
|
||||
"release" : dict(CCFLAGS = "$OPT_FLAGS"),
|
||||
"profile" : dict(CCFLAGS = "-pg", LINKFLAGS = "-pg"),
|
||||
"optimize" : dict(CCFLAGS = Split("$HIGH_OPT_FLAGS"), LINKFLAGS=Split("-fuse-ld=gold -flto"))
|
||||
"optimize" : dict(CCFLAGS = Split("$HIGH_OPT_COMP_FLAGS"), LINKFLAGS=Split("$HIGH_OPT_LINK_FLAGS"))
|
||||
}
|
||||
builds["glibcxx_debug"].update(builds["debug"])
|
||||
build = env["build"]
|
||||
|
|
|
@ -625,7 +625,7 @@ def error_action(target, source, env):
|
|||
raise UserError, "Target disabled because its prerequisites are not met"
|
||||
|
||||
def WesnothProgram(env, target, source, can_build, **kw):
|
||||
if env["build"] == "optimize":
|
||||
if env["build"] == "optimize" and env["enable_lto"] == "yes":
|
||||
env["AR"] = 'gcc-ar'
|
||||
env["RANLIB"] = 'gcc-ranlib'
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ env_lua = env.Clone(
|
|||
CPPPATH = ["$CPPPATH", Dir(".").srcnode()],
|
||||
CPPDEFINES = ["$CPPDEFINES", env["PLATFORM"] != "win32" and "LUA_USE_POSIX" or []])
|
||||
|
||||
if env_lua["build"] == "optimize":
|
||||
if env_lua["build"] == "optimize" and env_lua["enable_lto"] == "yes":
|
||||
env_lua["AR"] = 'gcc-ar'
|
||||
env_lua["RANLIB"] = 'gcc-ranlib'
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue