15.5. Using `VariantDir` With an `SConscript` File
Prev | Chapter 15. Separating Source and Build Trees: Variant Directories | Next

## 15.5. Using `VariantDir` With an `SConscript` File

Even when using the `VariantDir` function, it is more natural to use it with a subsidiary `SConscript` file, because then you don't have to adjust your individual build instructions to use the variant directory path. For example, if the `src/SConscript` looks like this:

    env = Environment()
    env.Program('hello.c')

Then our `SConstruct` file could look like:

    VariantDir('build', 'src')
    SConscript('build/SConscript')

Yielding the following output:

    % ls src
    SConscript  hello.c
    % scons -Q
    cc -o build/hello.o -c build/hello.c
    cc -o build/hello build/hello.o
    % ls build
    SConscript  hello  hello.c  hello.o

This is completely equivalent to the use of `SConscript` with the `variant_dir` argument from earlier in this chapter, but did require callng the SConscript using the already established variant directory path to trigger that behavior. If you call `SConscript('src/SConscript')` you would get a normal in-place build in `src`.

Prev | Up | Next
15.4. The `VariantDir` Function | Home | 15.6. Using `Glob` with `VariantDir`