Here's my project on github.
Here's my SConstruct file:
SConscript('main.scons', variant_dir = 'build', duplicate = 0)
Here's my main.scons file:
import sys
import os
import fnmatch
def find_source_files(directory, ext = "cpp"):
matches = []
for root, dirnames, filenames in os.walk(directory):
for filename in fnmatch.filter(filenames, '*.' + ext):
matches.append(os.path.join(root, filename))
return matches
if __name__ == '__main__':
for f in find_source_files('src'):
print f
else:
Program(target = 'main.bin', source = find_source_files('src'))
Here's what I get when I run it:
bitcycle @ cypher ~/git/IeiuniumTela $ find $(pwd) -name "*.bin" -or -name "*.o" -exec rm {} \;; scons; find $(pwd) -name "*.bin" -or -name "*.o"
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build
gcc -o build/main.bin
gcc: fatal error: no input files
compilation terminated.
scons: *** [build/main.bin] Error 4
scons: building terminated because of errors.
Here's what happens when I run `python main.scons' to test it:
bitcycle @ cypher ~/git/IeiuniumTela $ python main.scons
src/main.cpp
I'm having a hard time understanding why it can't find my source files. Any suggestions or ideas here?
[UPDATE] After getting some good direction from the mailing list, I found that this worked "good enough" for me.
/SConstruct: SConscript('src/main.scons', variant_dir = 'build', duplicate = 0)
/src/main.scons: Program(target = 'main.bin', source = Glob('*.cpp'))
See the github repository for the full source tree. I've also added an empty build directory to the repo for completeness. I find it interesteding that:
a. SCons' version of Glob isn't recursive, in the context of this build tool for discovering source. I would expect that a recursive discovery option is preferred. :(
b. I need to put the scons file in the same directory as the source file (which is annoying).
c. Print statements apparently work, but sys.stdout.write doesn't (from the python module).