1
votes

Is there any way to set environment variables for my system which scons will use, without me having to change the SConstruct file? For example, I would like to use MinGW instead of VC++ for my C++ builds on Windows. I can, of course, do this in my SConstruct file:

env = Environment(tools = ['mingw'])

But if I do that, then I'm editing things into my build files that make it specific to my particular system configuration. That defeats the whole purpose of a portable build system, in my opinion. If I upload that as part of my repository for others to build, they may not be using MinGW. They may want to use VC++, or Clang, and I don't think they should have to modify the build file (or anything else in the repository for that matter) in order to build the program or library. Ideally, anyone with in an environment with a functional C++ toolchain and scons installed should be able to just type scons on the command line, and things should go smoothly for them. Isn't that the (or a) goal of scons? Or am I misunderstanding its purpose?

Another thing is paths. The above line is not even enough, I have to still import the path to the MinGW binaries. I've read the justification for this. But it's just more system specific information which I have to put in my build files, which may be used by others where the chosen paths are not applicable.

2

2 Answers

0
votes

I think you have indeed understood the purpose of SCons regarding it being portable and multi-platform :)

The issue here is if you have multiple compilers to choose from on your system, how to tell SCons which one to use. By default SCons will look for and use the compiler specific to your system (VC++ on windows or g++ on linux for example).

I can think of at least 2 ways of telling SCons which compiler to use, both of which will require extra logic in the build scripts, but can be done in a portable manner:

  1. Environment variables
  2. command line arguments

I would consider always using the system-specific compiler unless the user invokes scons with arguments/variables instructing it to use a different one.

If you choose to use Environment variables, you can just use standard python code, as follows, and explained here:

import os

some_var = os.environ['SOME_VAR']

Or, if you choose to use command line arguments, you can find everything you need here.

Personally, I would prefer command line options, as its more explicit than env vars. With env vars, the users may get undesired results due to env vars they didnt realize were set.

0
votes

Try editing the file site_init.py in one of these directories:

%ALLUSERSPROFILE/Application Data/scons/site_scons
%USERPROFILE%/Local Settings/Application Data/scons/site_scons
%APPDATA%/scons/site_scons
%HOME%/.scons/site_scons
./site_scons

In that file, add a line like this:

DefaultEnvironment(tools = ['mingw'])

or maybe this:

DefaultEnvironment(tools = ['default', 'mingw'])