I'm currently trying something like -
projects = envsrc.MSVSProject(target = 'none' + env['MSVSPROJECTSUFFIX'],
srcs = Glob("src/*.cpp"),
incs = Glob("src/*.hpp"),
buildtarget = exe,
variant = 'Release')
But I get the error that srcs must be a string or list of strings, what is the right way to this? src is a folder within root dir that contains headers and cpp files, sconscript is in the root dir
I figured out what the problem is when I was trying to see why the print statement I suggested in the comments didnt work.
First of all, an efficient way in Python to print all the strings in a list of strings is like this:
', '.join(Sources)
The part in the quotes ', '
is the separator between elements in the list of strings.
I realized the problem with the following SConstruct excerpt:
sources = (Glob('src/dir1/*.cc')
+Glob('src/dir2/*.cc')
+Glob('src/dir3/*.cc'))
print sources
print ', '.join(sources)
Which gives this output:
scons: Reading SConscript files ...
[<SCons.Node.FS.File object at 0x122e4d0>, <SCons.Node.FS.File object at 0x122e710>, <SCons.Node.FS.File object at 0x122e950>]
TypeError: sequence item 0: expected string, File found:
File "/home/notroot/projects/sandbox/SconsGlob/SConstruct", line 10:
print ', '.join(sources)
That's when I remembered that the SCons Glob() function returns a list of Nodes (Files), not a list of strings. According to the SCons man page (search for 'glob(' ) the usage is as follows:
Glob(pattern, [ondisk, source, strings])
And the strings argument does the following:
The strings argument may be set to True (or any equivalent value) to have the Glob() function return strings, not Nodes, that represent the matched files or directories...
The MSVSProject() builder is expecting a list of strings, not Nodes. So, it works as you are expecting if you do the following:
sources = (Glob('src/dir1/*.cc', strings=True)
+Glob('src/dir2/*.cc', strings=True)
+Glob('src/dir3/*.cc', strings=True))
print ', '.join(sources)
Which gives the following output:
scons: Reading SConscript files ...
src/dir1/main.cc, src/dir2/func2.cc, src/dir3/func3.cc
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.