Finish 3rd example
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -37,4 +37,5 @@
|
||||
helloworld*
|
||||
env.txt
|
||||
build/
|
||||
install/
|
||||
|
||||
|
||||
6
execEx/03/SConscript
Normal file
6
execEx/03/SConscript
Normal file
@@ -0,0 +1,6 @@
|
||||
Import('env')
|
||||
|
||||
prog = env.Program(target='helloworld',
|
||||
source=['main.cpp', 'foo.cpp'])
|
||||
|
||||
env.Install(env.installDir, prog)
|
||||
87
execEx/03/SConstruct
Normal file
87
execEx/03/SConstruct
Normal file
@@ -0,0 +1,87 @@
|
||||
|
||||
import os
|
||||
|
||||
Help("""
|
||||
|
||||
This is the third scons example. In this example we see more things that we
|
||||
can do with scons. Namely: arguments, variant build directory, and install.
|
||||
|
||||
One can add the help for the expected build arguments using this help
|
||||
function call
|
||||
|
||||
DEBUG=1,0 - enable debug build, default 1
|
||||
ASSERT=1,0 - enable run time assertion, default 1 in DEBUG=1 and 0 otherwise
|
||||
COMPILER=compilerName - compiler name
|
||||
BUILDNAME=buildName - build name
|
||||
|
||||
""")
|
||||
|
||||
#
|
||||
# Processing arguments
|
||||
#
|
||||
debugArg = ARGUMENTS.get('DEBUG', '1')
|
||||
if debugArg not in ['0', '1']:
|
||||
raise RuntimeError('Check the DEBUG input argument.')
|
||||
|
||||
assertArg = '1' if debugArg == '1' else ARGUMENTS.get('ASSERT', '0')
|
||||
if assertArg not in ['0', '1']:
|
||||
raise RuntimeError('Check the ASSERT input argument.')
|
||||
|
||||
compilerName = ARGUMENTS.get('COMPILER', '')
|
||||
buildName = ARGUMENTS.get('BUILDNAME', 'default')
|
||||
|
||||
#
|
||||
# Initializing the environment
|
||||
#
|
||||
env = Environment(CC='clang',
|
||||
CXX='clang++')
|
||||
ccFlags = []
|
||||
linkFlags = []
|
||||
if compilerName == 'gcc':
|
||||
env.Replace(CC='gcc',
|
||||
CXX='g++')
|
||||
ccFlags = ["-std=c++1z", "-Wall", "-Wuninitialized", "-Wunused", "-Wconversion", "-fpermissive"]
|
||||
if debugArg == '0':
|
||||
ccFlags += ["-O3"]
|
||||
linkFlags = ["-Wl,--export-dynamic"]
|
||||
else:
|
||||
ccFlags += ["-g", "-O0"]
|
||||
linkFlags = ["-g"]
|
||||
else:
|
||||
ccFlags = ["-std=c++1z", "-Wall", "-Wuninitialized", "-Wunused", "-Wconversion", "-fpermissive"]
|
||||
if debugArg == '0':
|
||||
ccFlags += ["-O3"]
|
||||
linkFlags = ["-Wl,--export-dynamic"]
|
||||
else:
|
||||
ccFlags += ["-g", "-O0"]
|
||||
linkFlags = ["-g"]
|
||||
|
||||
env['CPPFLAGS'] = ccFlags
|
||||
env['LINKFLAGS'] = linkFlags
|
||||
|
||||
cppDefine = {}
|
||||
|
||||
if assertArg == '0':
|
||||
cppDefine['NDEBUG'] = None
|
||||
|
||||
env['CPPDEFINES'] = cppDefine
|
||||
|
||||
#
|
||||
# Paths setup
|
||||
#
|
||||
|
||||
env.srcDir = Dir('#').abspath
|
||||
|
||||
env.buildDir = os.path.join(env.srcDir, 'build', buildName)
|
||||
env.installDir = os.path.join(env.srcDir, 'install', buildName)
|
||||
|
||||
VariantDir(variant_dir=env.buildDir,
|
||||
src_dir=env.srcDir,
|
||||
duplicate=0)
|
||||
|
||||
#
|
||||
# Add build targets
|
||||
#
|
||||
|
||||
SConscript(os.path.join(env.buildDir, 'SConscript'),
|
||||
exports={'env' : env})
|
||||
@@ -1,52 +0,0 @@
|
||||
|
||||
import os
|
||||
|
||||
Help("""
|
||||
|
||||
This is the third scons example. In this example we see more things that we
|
||||
can do with scons. Namely: arguments, variant build directory, and install.
|
||||
|
||||
One can add the help for the expected build arguments using this help
|
||||
function call
|
||||
|
||||
DEBUG=1,0 - enable debug build, default 1
|
||||
ASSERT=1,0 - enable run time assertion, default 1 in DEBUG=1 and 0 otherwise
|
||||
COMPILER=compilerName - compiler name
|
||||
BUILDNAME=buildName - build name
|
||||
|
||||
""")
|
||||
|
||||
#
|
||||
# Processing arguments
|
||||
#
|
||||
debugArg = ARGUMENTS.get('DEBUG', '1')
|
||||
if debugArg not in ['0', '1']:
|
||||
raise RuntimeError('Check the DEBUG input argument.')
|
||||
|
||||
assertArg = '1' if debugArg == '1' else ARGUMENTS.get('ASSERT', '0')
|
||||
if assertArg not in ['0', '1']:
|
||||
raise RuntimeError('Check the ASSERT input argument.')
|
||||
|
||||
compilerName = ARGUMENTS.get('COMPILER', '')
|
||||
buildName = ARGUMENTS.get('BUILDNAME', 'default')
|
||||
|
||||
#
|
||||
# Initializing the environment
|
||||
#
|
||||
env = Environment(CC='clang',
|
||||
CXX='clang')
|
||||
|
||||
if compilerName == 'gcc':
|
||||
env.Replace(CC='gcc')
|
||||
env.Replace(CXX='g++')
|
||||
|
||||
srcDir = Dir('#').abspath
|
||||
|
||||
buildDir =
|
||||
|
||||
|
||||
#
|
||||
# Add build targets
|
||||
#
|
||||
env.Program(target='helloworld',
|
||||
source=['main.cpp', 'foo.cpp'])
|
||||
Reference in New Issue
Block a user