LongTP5
LongTP5

Reputation: 457

How can I specify a target library defined in an SConscript file to be built by calling its parent SConstruct from the command line?

I have defined two libraries - one static, one shared - to be built in a "libraries" subdirectory with an SConscript file. This SConscript is then invoked from SConstruct in the parent directory, which dilligently builds both libraries.

D:\tony\libraries\SConscript:

# Define environmental/project constants
CPPPATH = ['../headers']
SOURCES = ['greeter.cxx']

# Inherit the parent environment and update values if necessary.
Import('env')

# Build targets using defined environment variables.
print "Building libraries"
env.StaticLibrary(target = 'lib_greeter.a', source = SOURCES, CPPPATH = CPPPATH)
env.SharedLibrary(target = 'greeter.dll', source = SOURCES, CPPPATH = CPPPATH)

D:\tony\SConstruct:

# Define environmental/project constants
TOOLS = ['gcc', 'g++', 'gnulink', 'ar']
PATH = ['C:/cygwin/bin']
CYGWIN = ['nodosfilewarning']
DECIDER = 'MD5-timestamp'   # Use a combination of timestamps and checksums to decide if dependencies have changed.

# Initialize the Default Environment and update values.
env = DefaultEnvironment(tools=TOOLS)
env['ENV']['PATH'] = PATH
env['ENV']['CYGWIN'] = CYGWIN
env.Decider(DECIDER)

# Call subsidiary SConscript files with defined environment variables.
SConscript('libraries/SConscript', exports = 'env', duplicate = 0) # do not copy src files to build directory.

But how can I specify that I only wish to build one of the libraries (eg. greeter.dll) when invoking scons on the cmd line?

I had previously defined some custom command line options using AddOption to introduce some flow control, but somehow that didn't feel quite right.

Upvotes: 2

Views: 415

Answers (1)

acm
acm

Reputation: 12737

Your question can be read one of two ways:

  • How can I select the target to build by naming it on the command line.
  • How can I arrange things such that greeter.dll is built by default if no target is named on the command line.

If your question is about the first case, you can just name the path to the generated file when you invoke SCons. Given your files, I would expect that to look something like scons libraries\greeter.dll.

If you are asking about the second case, you can use env.Default("greeter.dll") in your SConscript, and then when you invoke SCons with no arguments it will be built automatically.

Upvotes: 3

Related Questions