0
votes

I have the following project structure:

/prj
    SConstruct
    /src
        /app
        /lib1
        /lib2
        /...

'/prj/src/lib1' structure:

/lib1
    /src
    /test
    SConscript

'lib1/SConscript':

SConscript('test/test1/SConscript',
            exports = 'env',
            variant_dir = '#build/release/lib1/test', 
            duplicate = 0)

and, finally, 'test' directory:

/test
    /common
        helpers.cpp
    /test1
        SConscript
        main.cpp

In 'test/test1/SConscript' sources specified as:

Sources = ['../common/helpers.cpp', 'main.cpp']

Result:

scons: *** [build/release/lib1/common/helpers.o] 
Source `build/release/lib1/common/helpers.cpp' not found, 
needed by target `build/release/lib1/common/helpers.o'

As can be seen the problem is that scons tries to find out the source file 'helpers.cpp' in build directory, not in source one.

Some research shows that the problem raised when source file path begins with '../'. When all sources defined underneath 'SConscript' file all is Ok.

Scons v2.5.1 and v3.0.1 demonstrate the same behavior.

What I did wrong? I've found this answer where the author advised:

You could use ../test.cpp as filename

but I doing exactly the same. Is such scons behavior intended or this is a bug?

1

1 Answers

0
votes

Your "code" in "lib1/SConscript":

SConscript('test/test1/SConscript',
            exports = 'env',
            variant_dir = '#build/release/lib1/test', 
            duplicate = 0)

uses the name of the given "test/test1/SConscript" and implicitly links the folder "test/test1" as "variant folder" (=variant_dir) to the target directory "#build/release/lib1/test". So if a required file can't be found in "#build/release/lib1/test", SCons tries to do an alternative "lookup" in "test/test1/". But this link is not automatically set for the "common" folder as well, and that's why the lookup of the "helpers.cpp" fails. This is the intended behaviour and correct in SCons.

A solution for your current problem would be to move the "test/test1/SConscript" one folder level higher, include the sources there as "common/helpers.cpp" and "test/main.cpp" and call this new SConscript from "lib1/SConscript" as:

SConscript('test/SConscript',
            exports = 'env',
            variant_dir = '#build/release/lib1/test', 
            duplicate = 0)