[Scons-users] Generated source file is placed in build directory, missing includes
William Deegan
bill at baddogconsulting.com
Sat Oct 27 16:21:56 EDT 2012
Thomas,
On Oct 27, 2012, at 4:51 AM, Thomas Berg <merlin66b at gmail.com> wrote:
> 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()])
You shouldn't need to use the srcnode().
env.AppendUnique(CPPPATH=['#/Ca3DE',])
Should be sufficient..
Likely if you find yourself (for the most part) heavily using the .srcnode() and/or .abspath() you may be doing it the hard way...
-Bill
More information about the Scons-users
mailing list