SCons: Use Variables for command line option and help output
Also add options to configure the compilers for C and C++ (no C code yet but C libraries may be added in the future, and we wouldn't to mix e.g. gcc for C and clang++ for C++).
This commit is contained in:
80
SConstruct
80
SConstruct
@@ -3,33 +3,49 @@ import os.path as path
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
platform = ARGUMENTS.get('OS', Platform())
|
||||
toolset = ARGUMENTS.get('toolset', 'default')
|
||||
sixty_four = ARGUMENTS.get('64bit', False)
|
||||
arch = 'x86_64' if sixty_four else 'x86'
|
||||
# Build options
|
||||
opts = Variables(None, ARGUMENTS)
|
||||
|
||||
if str(platform) not in ("darwin", "win32", "posix"):
|
||||
opts.Add(EnumVariable('OS', "Target platform", str(Platform()), ('darwin', 'win32', 'posix')))
|
||||
opts.Add('toolset', "Toolset to pass to the SCons builder", 'default')
|
||||
opts.Add(BoolVariable('debug', "Build with debug symbols", False))
|
||||
opts.Add(EnumVariable('bits', "Build for 32-bit or 64-bit architectures", '32', ('32', '64')))
|
||||
|
||||
# Compiler configuration
|
||||
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("CXXFLAGS", "Custom flags for the C++ compiler")
|
||||
opts.Add("CFLAGS", "Custom flags for the C compiler")
|
||||
opts.Add("LINKFLAGS", "Custom flags for the linker")
|
||||
|
||||
# Initialize environment with options and full user environment
|
||||
env = Environment(variables=opts, ENV=os.environ)
|
||||
Help(opts.GenerateHelpText(env))
|
||||
|
||||
platform = env['OS']
|
||||
toolset = env['toolset']
|
||||
arch = 'x86_64' if (env['bits'] == '64') else 'x86'
|
||||
|
||||
# Update env based on options
|
||||
env.Replace(TARGET_ARCH=arch)
|
||||
env.Replace(tools=[toolset])
|
||||
|
||||
# Check for platform support
|
||||
if platform not in ("darwin", "win32", "posix"):
|
||||
print "Sorry, your platform is not supported."
|
||||
print "Platform is:", platform
|
||||
print "Specify OS=<your-platform> if you believe this is incorrect."
|
||||
print "(Supported platforms are: darwin, win32, posix)"
|
||||
Exit(1)
|
||||
|
||||
print 'Building for:', platform
|
||||
print 'Using toolchain:', toolset
|
||||
|
||||
if toolset != 'default':
|
||||
env = Environment(TARGET_ARCH=arch,ENV=os.environ, tools = [toolset])
|
||||
else:
|
||||
env = Environment(TARGET_ARCH=arch,ENV=os.environ)
|
||||
env.VariantDir('#build/obj', 'src')
|
||||
env.VariantDir('#build/obj/test', 'test')
|
||||
|
||||
# Allow arbitrary flags
|
||||
env.Append(CXXFLAGS=os.environ.get('CXXFLAGS', ''))
|
||||
|
||||
debug = ARGUMENTS.get('debug', 0)
|
||||
if int(debug):
|
||||
if env['debug']:
|
||||
env.Append(CCFLAGS = '-g')
|
||||
|
||||
# This command generates the header with git revision information
|
||||
@@ -57,7 +73,7 @@ else:
|
||||
echo -e "\n#define GIT_REVISION \"\"\n#define GIT_TAG \"\"\n#define GIT_TAG_REVISION \"\"\n" > #TARGET
|
||||
""")
|
||||
|
||||
if str(platform) == "posix":
|
||||
if platform == "posix":
|
||||
env.Append(CXXFLAGS="-std=c++11 -stdlib=libstdc++")
|
||||
env["CC"] = 'clang'
|
||||
env["CXX"] = 'clang++'
|
||||
@@ -66,7 +82,7 @@ if str(platform) == "posix":
|
||||
"""), CPPPATH=Split("""
|
||||
/usr/include
|
||||
"""))
|
||||
if str(platform) == "darwin":
|
||||
if platform == "darwin":
|
||||
env.Append(CXXFLAGS="-std=c++11 -stdlib=libc++ -include global.hpp", RPATH='../Frameworks')
|
||||
env["CC"] = 'clang'
|
||||
env["CXX"] = 'clang++'
|
||||
@@ -147,7 +163,7 @@ if str(platform) == "darwin":
|
||||
Execute(Copy(dest_path, src_path))
|
||||
bundle_libraries_for(target, [File(check_path)], env)
|
||||
break
|
||||
elif str(platform) == "win32":
|
||||
elif platform == "win32":
|
||||
if 'msvc' in env['TOOLS']:
|
||||
env.Append(
|
||||
LINKFLAGS='/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup /MACHINE:X86',
|
||||
@@ -172,7 +188,7 @@ elif str(platform) == "win32":
|
||||
env.Append(CXXFLAGS="-include global.hpp")
|
||||
def build_app_package(env, source, build_dir, info):
|
||||
env.Install(build_dir, source)
|
||||
elif str(platform) == "posix":
|
||||
elif platform == "posix":
|
||||
env.Append(CXXFLAGS="-include global.hpp")
|
||||
def build_app_package(env, source, build_dir, info):
|
||||
env.Install(build_dir, source)
|
||||
@@ -184,7 +200,7 @@ env.Append(
|
||||
LIBPATH = ARGUMENTS.get('LIBPATH', '').split(path.pathsep),
|
||||
CPPPATH = ARGUMENTS.get('INCLUDEPATH', '').split(path.pathsep)
|
||||
)
|
||||
if str(platform) == 'darwin':
|
||||
if platform == 'darwin':
|
||||
env.Append(FRAMEWORKPATH=ARGUMENTS.get('FRAMEWORKPATH', '').split(path.pathsep))
|
||||
# If any package managers are installed, add their dirs too.
|
||||
if subprocess.call(['which', '-s', 'port']) == 0: # MacPorts
|
||||
@@ -211,7 +227,7 @@ if str(platform) == 'darwin':
|
||||
# We try to auto-detect this.
|
||||
if path.exists('deps/lib'):
|
||||
env.Append(LIBPATH='deps/lib')
|
||||
if str(platform) == 'darwin':
|
||||
if platform == 'darwin':
|
||||
env.Append(FRAMEWORKPATH='deps/lib')
|
||||
|
||||
if path.exists('deps/include'):
|
||||
@@ -243,17 +259,17 @@ if not env.GetOption('clean'):
|
||||
print "There's a problem with your compiler!"
|
||||
Exit(1)
|
||||
|
||||
if not conf.CheckLib('zlib' if (str(platform) == "win32" and 'mingw' not in env["TOOLS"]) else 'z'):
|
||||
if not conf.CheckLib('zlib' if (platform == "win32" and 'mingw' not in env["TOOLS"]) else 'z'):
|
||||
print 'zlib must be installed!'
|
||||
Exit(1)
|
||||
|
||||
def check_lib(lib, disp, suffixes=[], versions=[]):
|
||||
if str(platform) == "win32" and lib.startswith("boost"):
|
||||
if platform == "win32" and lib.startswith("boost"):
|
||||
lib = "lib" + lib
|
||||
if "mingw" in env["TOOLS"] and lib.startswith("sfml"):
|
||||
lib = "lib" + lib
|
||||
possible_names = [lib]
|
||||
if str(platform) == "win32":
|
||||
if platform == "win32":
|
||||
if 'msvc' in env['TOOLS']:
|
||||
vc_suffix = '-vc' + env['MSVC_VERSION'].replace('.','')
|
||||
possible_names.append(lib + vc_suffix)
|
||||
@@ -300,11 +316,11 @@ if not env.GetOption('clean'):
|
||||
|
||||
env.Append(CPPDEFINES="TIXML_USE_TICPP")
|
||||
|
||||
if str(platform) == "win32":
|
||||
if platform == "win32":
|
||||
# For the *resource.h headers
|
||||
env.Append(CPPPATH="#rsrc/menus")
|
||||
|
||||
if str(platform) == "darwin":
|
||||
if platform == "darwin":
|
||||
env.Append(LIBS=Split("""
|
||||
objc
|
||||
c++
|
||||
@@ -313,11 +329,11 @@ if str(platform) == "darwin":
|
||||
OpenGL
|
||||
Cocoa
|
||||
"""))
|
||||
elif str(platform) == "win32":
|
||||
elif platform == "win32":
|
||||
env.Append(LIBS=Split("""
|
||||
opengl32
|
||||
"""))
|
||||
elif str(platform) == "posix":
|
||||
elif platform == "posix":
|
||||
env.Append(LIBS=Split("""
|
||||
GL
|
||||
X11
|
||||
@@ -356,7 +372,7 @@ SConscript(["rsrc/SConscript", "doc/SConscript"])
|
||||
|
||||
# Bundle required frameworks and libraries
|
||||
|
||||
if str(platform) == "darwin":
|
||||
if platform == "darwin":
|
||||
targets = [
|
||||
"Blades of Exile",
|
||||
"BoE Character Editor",
|
||||
@@ -366,7 +382,7 @@ if str(platform) == "darwin":
|
||||
target_dir = path.join(install_dir, targ + '.app', 'Contents/Frameworks')
|
||||
binary = path.join(install_dir, targ + '.app', 'Contents/MacOS', targ)
|
||||
env.Command(Dir(target_dir), binary, [Delete(target_dir), bundle_libraries_for])
|
||||
elif str(platform) == "win32":
|
||||
elif platform == "win32":
|
||||
bundled_libs = Split("""
|
||||
libsndfile-1
|
||||
openal32
|
||||
@@ -402,10 +418,10 @@ elif str(platform) == "win32":
|
||||
# (Because the installer is an optional component.)
|
||||
open("build/Blades of Exile/VCRedistInstall.exe", 'w').close()
|
||||
|
||||
if str(platform) == "darwin":
|
||||
if platform == "darwin":
|
||||
env.VariantDir("#build/pkg", "pkg/mac")
|
||||
SConscript("build/pkg/SConscript")
|
||||
elif str(platform) == "win32" and subprocess.call(['where', '/Q', 'makensis']) == 0:
|
||||
elif platform == "win32" and subprocess.call(['where', '/Q', 'makensis']) == 0:
|
||||
env.VariantDir("#build/pkg", "pkg/win")
|
||||
SConscript("build/pkg/SConscript")
|
||||
|
||||
|
Reference in New Issue
Block a user