如何使用 scons 进行源代码外构建?
我一直在使用 cmake 从源代码构建我的项目,这非常方便,因为您可以避免不必要的文件污染源目录。
假设 CMakeLists.txt 位于当前目录中,可以按如下方式完成:
mkdir build
cd build
cmake ..
make
How can I do the same in scons?
I have been using cmake to build my projects out of source, which is really convenient as you avoid polluting your source directory with unnecessary files.
Assuming the CMakeLists.txt is in the current directory, this could be done as follows:
mkdir build
cd build
cmake ..
make
How can I do the same in scons?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的
SConstruct
文件中,您使用变体目录:然后在
main.scons
中您照常设置所有内容:可以在不将变体目录硬编码到 SConstruct 中的情况下执行此操作通过(ab)使用存储库,但这种方法有其缺陷。作为记录,您将按如下方式运行上述内容以在另一个目录中构建:
最简单且最可行的方法是仅使用
variant_dir
。然后,您可以照常从顶级源目录运行它。所有构建工件都在build
子目录中生成。为了响应 JesperE 的评论,以下是如何编写顶级 SConstruct 来添加可选命名的构建目录:
然后您可以从命令行调用它,如下所示,以创建一个名为“baz”的构建目录:
In your
SConstruct
file, you use a variant dir:Then in
main.scons
you set up everything as usual:It's possible to do this without hardcoding the variant dir into the SConstruct by (ab)using repositories, but that approach has its bugs. For the record, you would run the above as follows to build in another directory:
The easiest and most workable is to just use
variant_dir
. You then run this as usual from the top level source directory. All the build artefacts get produced in thebuild
sub directory.In response to JesperE's comment, here is how you could write the top level SConstruct to add an optionally named build directory:
Then you would call this from the command line as follows, to create a build directory called "baz":