带有存储库目录的 Scons 分层构建 [英] Scons Hierarchical Builds with Repository directory

查看:31
本文介绍了带有存储库目录的 Scons 分层构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SCons 项目设置如下:

项目/构造来源/C/H/app1/SConscriptapp2/SConscript...

每个应用程序的所有源/头文件都位于 src/c 和 src/h 中.


  1. 第一步,我在 app1 中创建了一个 SConstruct,它使用了 Repository 函数.

<块引用>

...

src=Split("main.c first.c second.c")

env = Environment(CC='g++', CCFLAGS=['-O0', '-ggdb'], CPPPATH=['.'])

env.Program('appone', src)

存储库(../src/c",../src/h")

一切正常.scons 从存储库中找到了构建 appone 应用程序所需的所有源/头文件.


但是,如果我尝试构建 appone 层次结构,它将无法正常工作:-(

我将 app1/SConstruct 重命名为 app1/SConscript 并放置

<块引用>

SConscript('app1/SConscript')

进入项目/SConstruct

现在出现以下错误:

scons: *** [app1/main.o] 未找到源app1/main.c",目标app1/main.o"需要.

如何配置我的 proj/SConstruct 或 proj/app1/SConscript 以搜索我的 Repository 目录中的所有源文件?

解决方案

SCons 正在 app1 目录中寻找您的源文件.如果您像这样指定来源:

src=Split("#main.c #first.c #second.c")

然后 scons 将在存储库中搜索源文件.

一些额外的想法:

  1. 您可能希望 main.c 位于 app1 目录中,以避免与其他可执行文件的 main.c 发生冲突.在这种情况下,请从源列表中的 main.c 中删除 #.

  2. 如果多个应用程序共享存储库,最好在顶级 SConstruct 中定义存储库.

  3. 从共享源构建库通常很有用,这样单元测试就可以拥有自己的主要功能,但链接与您的应用程序相同的源代码(或者应用程序可以共享公共模块).将 SConscripts 放在共享存储库目录中以构建公共库可能更容易做到这一点.超出了这个问题的范围,但随着项目的发展需要考虑.

I have an SCons project set up as follows:

proj/
    SConstruct
    src/
        c/
        h/
    app1/SConscript
    app2/SConscript
    ...

All source/header files for each application are located in src/c and src/h.


  1. At first step I created a SConstruct in app1 which use the Repository function.

...

src=Split("main.c first.c second.c")

env = Environment(CC='g++', CCFLAGS=['-O0', '-ggdb'], CPPPATH=['.'])

env.Program('appone', src)

Repository("../src/c", "../src/h")

All works fine. scons found all necessary source/header files from repository to build the appone application.


But if I try to build appone hierarchical it will not work :-(

I renamed app1/SConstruct to app1/SConscript and put

SConscript('app1/SConscript')

into proj/SConstruct

Now I get following error:

scons: *** [app1/main.o] Source `app1/main.c' not found, needed by target `app1/main.o'.

How do I configure my proj/SConstruct or proj/app1/SConscript to search for all source files in my Repository directory?

解决方案

SCons is looking for your source files in the app1 directory. If you specify the sources like this:

src=Split("#main.c #first.c #second.c")

then scons will search the Repositories for the source files.

A couple extra thoughts:

  1. You may want main.c to be in the app1 directory to avoid conflicts with main.c for other executables. In this case, remove the # from main.c in your source list.

  2. It's probably a good idea to define the Repositories in your top-level SConstruct if multiple apps share the repositories.

  3. It's often useful to build libraries from the shared sources so that unit tests can have their own main functions, but link the same sources as your apps (or so apps can share common modules). It may be easier to do this by putting SConscripts in the shared repository directory to build common libraries. Beyond the scope of this question, but something to consider as your project grows.

这篇关于带有存储库目录的 Scons 分层构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆