Question

Background

I'm trying out Scons by setting up a basic C++ sample project that has two sub-projects:

  • Prj1 is an EXE that depends on Prj2
  • Prj2 is a DLL that exports some functions

You can see the directory structure and the contents of my SConstruct and SConscript files here

Problem

The problem I'm running into is that in order to build these targets from the command line I have to specify both the relative path to their build directory and their platform specific file extensions.

For example, to build Prj1 I have to do:


build> scons ../bin/project1.exe

Likewise, to build Prj2 I have to do:


build> scons ../bin/project2.dll

Question

How can I make SCons build these projects without specifying the relative path and platform specific file extension?

Desired:


build> scons project1 
build> scons project2

Potential Solutions

  • Use Alias - I'm pretty sure this is what I want but I'm messing something up apparently. I've tried the following without success:

prj1_env.Alias( 'project1', PROG)
prj1_env.Alias( 'project1', os.path.join( BIN_DIR, PROG) )

References

Was it helpful?

Solution

Moving this to an answer instead of a comment. :)

References

Alias needs an actual target as its second argument. I think the issue is that "project1" (the value of PROG) is not an actual target. An easy way to correct this is the following. Make PrefixProgram return a value:

def PrefixProgram(env, outdir, trgt, srcs):
    return env.Program(target = os.path.join(outdir, trgt), source = srcs)

Then:

target = PrefixProgram( prj1_env, BIN_DIR, PROG, SOURCES )
prj1_env.Alias("project1", target)

You can of course just do this:

prj1_env.Alias("project1", PrefixProgram( prj1_env, BIN_DIR, PROG, SOURCES ))

But I think the first way is easier to understand.

I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top