[Scons-users] Changing VariantDir in an SConscript file
Bill Deegan
bill at baddogconsulting.com
Mon Nov 15 11:38:00 EST 2021
Luke,
VariantDir()'s seem to be one of the harder to grasp concepts in SCons so
you're in good company.
Assuming your Library() statements are in the same SConscript, you'd need
to change them as follows
lib_A = env_A.Library('Build/A/lib_A', ['Build/A/src/common.c', 'Build/A/
src/impl_A.c'])
lib_B = env_B.Library('Build/B/lib_B', ['Build/A/src/common.c', 'Build/A/
src/impl_B.c'])
Just adding a VariantDir() to an Environment() doesn't do anything to any
builders you use with that environment.
All you're doing with any VariantDir() statement is telling SCons that for
example Build/A should be treated as if it was '.'.
So any files you reference relative to Build/A, if they don't exist in
Build/A, SCons should also look in .
So for Build/A/src/common.c SCons should first look at that location, then
it should look at ./src/commmon.c
Is that any clearer?
-Bill
On Mon, Nov 15, 2021 at 9:54 AM Luke Tunmer <luke.tunmer at gmail.com> wrote:
> Hi all,
>
> I'm trying to understand why calling VariantDir on my environment within
> an SConstript file doesn't do what I thought it would. I suspect it's my
> understanding that is broken, and if so, I'm looking for advice for how to
> do this properly.
>
> My top level SConstruct file started the ball rolling with a variant_dir
> that encapsulates all the different configurations that this system can be
> built to ensure each configuration is built into a unique build folder
> location (I turn duplicate off).
>
> Deep down in the tree in a particular SConscript file I need to compile
> some C files two different ways which target the C compiler optimizer for
> the particular CPU on which it will run (the embedded system is a multicore
> one with at least 5 different CPU types). Some of these C files will be
> running on different cores.
>
> I thought I could clone the environment two ways and modify the VariantDir
> of each:
>
> Import('env')
>
> env_A = env.Clone()
> env_A.VariantDir('build/A', '.', duplicate=0)
> # add various CC flags to env_A
>
> env_B = env.Clone()
> env_B.VariantDir('build/B', '.', duplicate=0)
> # add different CC flags to env_B
>
> And then I would like to be able to specify the two different libraries
> that need to be built at this level in the tree:
>
> lib_A = env_A.Library('lib_A', ['src/common.c', 'src/impl_A.c'])
> lib_B = env_B.Library('lib_B', ['src/common.c', 'src/impl_B.c'])
>
> and then common.c will be compiled two ways into different build folders,
> and the appropriate one included in each library. However, the change to
> the VariantDir of each environment seems to make no difference at all: it
> uses the build folder specified right at the top of the tree for both the
> .o files and for the .lib files that it makes.
>
> Any help in my understanding of how VariantDir is supposed to work, and
> what it is actually doing is appreciated. Or, of course, any information on
> the proper way to achieve this result would be great.
>
> Regards,
> Luke
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20211115/3e50fcbf/attachment.htm>
More information about the Scons-users
mailing list