[Scons-users] Generated source file is placed in build directory, missing includes
Thomas Berg
merlin66b at gmail.com
Sat Oct 27 07:51:00 EDT 2012
Hi,
On Sat, Oct 27, 2012 at 12:45 PM, Carsten Fuchs <carsten.fuchs at cafu.de> wrote:
> Hi all,
>
> I'm using a Command() builder for generating a C++ source code file that is
> part of the input files for a program builder. Shortened example:
>
>
> def generateCode(target, source, env):
> with open(str(target[0]), 'w') as f:
> f.write("#include "AppCafu.hpp"\n");
> f.write("// ...\n");
>
> app = env.Program('Ca3DE/Cafu',
> Glob("Ca3DE/*.cpp") +
> envCafu.Command("Ca3DE/AppCafu_GenList.cpp", "", generateCode))
>
>
> This is in a SConscript file that is called from SConstruct via a call to
> SConscript(..., variant_dir=..., duplicate=0).
>
>
> It all works, but like all obj and exe files, also the generated source file
> Ca3DE/AppCafu_GenList.cpp is created in the build directory that was
> specified with variant_dir.
>
> The problem is that when Scons next calls the compiler to build the file, it
> cannot find the header specified in the #include statement.
>
> It seems obvious that I can either manipulate the #include
> "../../../Ca3DE/AppCafu.hpp" path so that it points to the proper header
> file directly, whereas adding another parameter CPPPATH=['.', 'Ca3DE'] does
> not seem to have any effect.
> It seems like I'm missing something, but I've not been able to figure out
> what it is.
Usually the trick is to add env.Dir('.').srcnode() to CPPPATH.
You probably don't need it here, but another useful trick to know
about is the '#' for referring to paths relative to the top level
SConstruct. It is mainly useful if you are in a subdirectory
SConscript for example, and it is another thing to try if you have
trouble setting things up:
env.AppendUnique(CPPPATH = [env.Dir('#/Ca3DE').srcnode()])
Hope this helps,
- Thomas
More information about the Scons-users
mailing list