The VariantDir Function

SCons User Guide 0.98.0
Prev | Chapter 15. Separating Source and Build Directories | Next

# 15.4. The `VariantDir` Function

Use the `VariantDir` function to establish that target files should be built in a separate directory from the source files:

          VariantDir('build', 'src')
          env = Environment()
          env.Program('build/hello.c')

Note that when you're not using an `SConscript` file in the `src` subdirectory, you must actually specify that the program must be built from the `build/hello.c` file that SCons will duplicate in the `build` subdirectory.

When using the `VariantDir` function directly, SCons still duplicates the source files in the variant directory by default:

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

You can specify the same `duplicate=0` argument that you can specify for an `SConscript` call:

          VariantDir('build', 'src', duplicate=0)
          env = Environment()
          env.Program('build/hello.c')

In which case SCons will disable duplication of the source files:

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

Prev | Home | Next
Telling SCons to Not Duplicate Source Files in the Variant Directory Tree | Up | Using `VariantDir` With an `SConscript` File