Search code examples
c++scons

Can I use SCons aliasing for choosing SConscripts to run?


I'm using SCons to build a very large project, with many buildable sub-projects. I can easily use keyword commands like scons group=ai to build the AI sub-projects with if statements (choosing the right SConscripts based on the keyword command), but I want to make it as easy as possible for others to use scons. Ideally, I'd like to use it like so: scons ai to build the AI components. However, the only single-word command functionality I've found in SCons so far is aliasing, and all the examples are about changing the target. This is not what I want. Since I have a very large project with multiple sub-SConscript files to build the subprojects, I want to call the SConscripts selectively. I've tried code like so:

env.Alias("ai", SConscript("ai/SConscript", 'env'))

but this calls the AI SConscript every time, regardless of whether I use the "ai" alias or a different one. Does anyone know if it is possible to use aliasing this way to selectively call SConscripts based on the alias?


Solution

  • As you mentioned, the Alias() function is only used for targets. I can think of 2 ways to solve this

    Alias() can be called multiple times for the same alias with different targets, so you could call it for all targets in each SConscript, then you could build everything in a SConscript. Here's an example of what I mean:

    ai/SConscript:

    # targets, etc
    
    env.Alias("ai", target1)
    env.Alias("ai", target2)
    ...
    env.Alias("ai", targetn)
    

    Another option would be to put some logic in your root SConstruct so it only calls sub-project SConscript's based on a command line argument. This option would require you to use a command line argument of this form: group=ai