c++ - 编写 scons 脚本来处理许多子目录中文件的编译

标签 c++ build makefile scons subdirectory

我有一个项目,其中包含子目录中的许多文件。我有一个简单的 Makefile 来处理编译。它看起来像这样:

CC = g++ -Wall -ansi -pedantic 
all:
$(CC) -O2 engine/core/*.cpp engine/objects3d/*.cpp engine/display/*.cpp engine/io  /*.cpp engine/math/*.cpp engine/messages/*.cpp  *.cpp -o project1 -lGL -lGLU -lX11 `sdl-config --cflags --libs`

clean:
@echo Cleaning up...
@rm project1
@echo Done.

但是我需要迁移到 SCons。我不知道如何编写一个脚本来自动处理在子目录中查找所有 *.cpp 文件并将它们包含在编译过程中。

最佳答案

这就是如何在 SCons 中执行 Makefile 中的操作。您应该将此 Python 代码放在名为 SConstruct 的项目根目录下的文件中,然后只需执行 scons。要清理,请执行 scons -c

env = Environment()
env.Append(CPPFLAGS=['-Wall', '-ansi', '-pedantic', '-O2', '-lGL', '-lGLU', '-lX11'])

# Determine compiler and linker flags for SDL
env.ParseConfig('sdl-config --cflags')
env.ParseConfig('sdl-config --libs')

# Remember that the SCons Glob() function is not recursive
env.Program(target='project1',
            source=[Glob('engine/core/*.cpp'),
                    Glob('engine/objects3d/*.cpp'),
                    Glob('engine/display/*.cpp)',
                    Glob('engine/io/*.cpp'),
                    Glob('engine/math/*.cpp'),
                    Glob('engine/messages/*.cpp'),
                    Glob('*.cpp')])

Here是将 SDL 与 SCons 结合使用的链接。

这是关于 SCons ParseConfig() function 的信息.

关于c++ - 编写 scons 脚本来处理许多子目录中文件的编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19626250/

相关文章:

c++ - 拆分大文件而不复制?

c++ - 使'clean.Stop需要: *** No rule to make target 'rm' ,

build - 如何不在输出中打印生成文件中的注释

Windows 下的 Java makefile 因重音符号而卡住

makefile - 有人知道从 Makefile 生成点 (graphviz) 文件的工具吗?

c++ - 当试图找到 '*' 程序发现 '.' insted in c++

C++:初始化变量;重载隐式构造函数?

c++ - 实例化变量的新实例

go - `//go:build` 和 `//+build` 指令有什么区别?

java - 如何将 .jar 依赖项包含到生成应用程序的最终 .jar 文件的 ANT 目标中?