Scons
Scons¶
- SCons is a software construction tool that can be used as an alternative to traditional build systems like Make and CMake.
- It is a Python-based build tool that provides a convenient and flexible way to define and manage the build process for software projects, including C++ programs.
Scons VS cmake¶
- 基于python语言的构建工具,对开发者来说过度自然,简单,no need to learn domain-specific language like cmake
其余cmake有的, Scons 也有。
- cross-paltform,
- SCons has built-in support for dynamic dependency analysis, meaning it can automatically detect changes in source files and rebuild only what's necessary. This can result in faster builds for large projects.
Project structure¶
- Sconstructpython file as compile entry
framework grammar¶
- add option for sconscommand
AddOption('--buildDir', 
   dest='buildDir', 
   type='string', 
   default="build/", 
   # default=False,
   nargs=1, 
   action='store', # meaning save the string
   # or action='store', meaning True or false
   metavar='DIR', 
   help='Base build directory'
)
baseBuildDir = GetOption('buildDir') 
- add sub scons config file and build result path using variant_dir
- achive debug mode
using scons debug=1 command.
main construct grammar¶
- Define the Build Environment:
   In the SConstructfile, define the build environment by creating anEnvironmentobject. You can specify compiler options, flags, include paths, library paths, and other build settings within this object.
env = Environment(CXX='g++', CCFLAGS=['-O2', '-Wall'], CPPPATH=['include'], LIBPATH=['lib'])
 libEnv = env.Clone()
- Specify Source Files and Targets:
   Define the source files for your C++ program and specify the target(s) you want to build using the Program()function.
source_files = ['main.cpp', 'util.cpp', 'other.cpp']
# or select the src files 
Object('hello.cpp')
program = env.Program(target='my_program', source=source_files)
In this example, main.cpp, util.cpp, and other.cpp are the source files, and my_program is the name of the target executable.
- static or dynamic lib
# static
Library("t", Glob("src/*.cpp"))
# dynamic
source = Glob("src/*.cpp")
SharedLibrary("t", source)
Program(["hello.cpp"], LIBS=["t"], LIBPATH=".")
- 
execute command during compilation 
- 
this is usually to print info 
- The command is executed when any of the specified dependencies (allSrcs, ".git/index", or "SConstruct") change.
env.Command(
 target='bar.out',
 source='bar.in',
 action=["rm -f $TARGET", "$BAR_BUILD < $SOURCES > $TARGET"],
 ENV={'PATH': '/usr/local/bin/'},
)
env.Command(
   versionFile, 
   allSrcs + [".git/index" "SConstruct"],                                                 
   'printf "#define ZSIM_BUILDDATE \\"`date "+%Y-%m-%d %T"`\\"\\n#define ZSIM_BUILDVERSION \\"`python misc/getver.py`\\"" >>' + versionFile) 
Command¶
scons-project analysis¶
TODO: multipim how to add a singel head file during compilation process.
需要进一步的研究学习¶
暂无
遇到的问题¶
暂无
开题缘由、总结、反思、吐槽~~¶
参考文献¶
上面回答部分来自ChatGPT-3.5,没有进行正确性的交叉校验。
https://scons.org/doc/production/PDF/scons-man.pdf