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
Sconstruct python file as compile entry
framework grammar
add option for scons command
1 2 3 4 5 6 7 8 9 10 11 12
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
Define the Build Environment: In the SConstruct file, define the build environment by creating an Environment object. You can specify compiler options, flags, include paths, library paths, and other build settings within this object.
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.
1 2 3 4
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.
$ strace -p 4005082 strace: Process 4005082 attached futex(0x7fffe52de1b8, FUTEX_WAIT, 2, NULL # futex - fast user-space locking(seems to be used in OpenMP) # It is typically used as a blocking construct in the context of shared-memory synchronization.