0

I am a bit confused with the functionnement of targets with SCons. I am currently trying to create a simple target check to launch the Boost.Test suite located in my tests folder. In order to launch all the tests, I have a tests/SConscript file in which I register my cpp files containing my tests by simply calling the Program method.

I would simply like to tell SCons that he needs to call the tests/SConscript file if the target check is requested, otherwise, simply build the program by calling src/SConscript

$> scons check
Sam
  • 7,252
  • 16
  • 46
  • 65
Rippalka
  • 380
  • 6
  • 16

2 Answers2

1

As mentioned in your answer, you can use the SCons Alias() function to assign a name to one or several targets, but this does not tell SCons when to build the targets if you simply execute scons without specifying targets. When you dont specify any targets, you'll notice that the unit tests will be built and/or executed.

To tell SCons what should be built, you can use the SCons Default() function. When you dont use this function, every target will be built by default: obviously only those targets that need to be built, according to the dependencies, etc.

To only build the targets in your src/SConscript by default, then assuming its a library, you can do the following:

libTarget = env.Library('yourLib', theSourceFiles)
env.Default(libTarget)

You can use the Default() function for several different targets.

Now when you execute scons without any targets, only those targets set with the Default() function will be built. And if you execute scons check, then the check target and its dependencies will be built (assuming you called Alias() with the check target and havent also called Default() with the check target)

SaiyanGirl
  • 16,376
  • 11
  • 41
  • 57
Brady
  • 10,207
  • 2
  • 20
  • 59
  • Thank you, that helped me a lot! I was not finding where this issue was comming from. It's working fine now – Rippalka Aug 03 '12 at 16:35
0

I am going to answer my own question. From what I saw, you can use Aliases in SCons to bind a Builder to a rule.

I've read a post from Chris Foster at this address: http://www.scons.org/wiki/UnitTests coming up with the following idea:

For each test we want to add, we add it to the check target like this:

prog = env.Program(...)
env.Alias('check', prog)
env.Alias(nameOfTheTest, prog)

This way, I can call my test in two different ways:

$> scons check             # Calls all the tests of the suite
$> scons nameOfTheTest     # Only calls the test we added

Hope that helps. Thanks

Rippalka
  • 380
  • 6
  • 16
  • This will work when specifying the targets to build, but the problem is that these targets will also get built if you dont specify a target. That is, just executing "scons" will cause these targets to be built, which is something you said you dont want. I added an answer explaining how to get your desired behavior. – Brady Aug 03 '12 at 08:10