SCons with multiple Visual Studio versions.
Current Repository Revision: 10
At the end of the last blog entry, it was mentioned that the next problem was to see how SCons handled having both Visual Studio Express 2005 and Visual Studio Express 2008 installed, and how to select which one to use. Luckily, SCons caters for this easily, and this post will detail the relevant changes made to the SConstruct file.
SCons always uses the latest installed version of Visual Studio by default. In the set up being tested this meant that running SCons with:
scons -Q
always selects Visual Studio Express 2008 as the compile tool.
It is possible with SCons to change the tool being used. We did this before so that MinGW could be used on Windows when Visual Studio is installed (Visual Studio taking precedence over MinGW by default in SCons) by using the switch:
scons -Q mingw=true
We can do something similar with Visual Studio Express 2005 by adding the switch vs2005 to the Options(). This requires an entry in the SConstruct file:
BoolOption('vs2005',
"Set to use Visual Studio [Express] 2005 instead of a later compiler",
'false')
Note: See this post as to the decision to continue to use the now deprecated BoolOption at present.
Now when the user enters the vs2005=true switch, we can reset SCons to use Visual Studio 2005 instead of 2008 by setting the variable MSVS_VERSION to the appropriate version number (note: Visual Studio 2005 is actually version 8.0) before constructing the environment:
# If vs2005 or mingw is set, get an environment with
# the appropriate tool instead
if env['vs2005']:
env = Environment(options = opts,
MSVS_VERSION = '8.0')
elif env['mingw']:
env = Environment(options = opts,
tools = ['mingw'])
As we have had to construct the Environment earlier (for the options), we could just reset the tool, rather than creating a whole new environment, by setting the MSVS_VERSION variable to 8.0 (env["MSVS_VERSION"]=”8.0″) and calling Tool(“msvs”)(env), but this doesn’t update the tool cleanly – it still leaves paths to Visual Studio 2008 in some of the variables – and I like it neat!
The final part of this update was to ensure that when a user specified they wanted to use Visual Studio 2005, it didn’t try to use our workaround for Visual Studio 2008, as SCons gets all the variables right for Visual Studio 2005 without the need to call that code:
if (cmplr=='cl') and (not env['vs2005']):
We tested what happens if you use all three tools in a standard Command Prompt, and in a Microsoft Visual Studio Express 2008 Command Prompt. The code was built and cleaned with each tool using the sequence:
scons -Q runtests=true scons -Qc scons -Q vs2005=true runtests=true scons -Qc vs2005=true scons -Q mingw=true runtests=true scons -Qc mingw=true
In the standard command prompt Visual Studio Express 2005 and MinGW built the current code and ran the tests correctly, but Visual Studio Express 2008 failed to build the codeĀ (due to the problems described in this post). In the Microsoft Visual Studio Express 2008 Command Prompt all three tools compiled the code and ran the tests correctly.
Other versions of Visual Studio (or any other compiler for that matter) could also be catered for, but this is left as an exercise for the reader…
The code is now committed as revision 10 (the code was originally committed revision 9, but would allow both vs2005 and mingw switches to be processed, so the mingw if was replaced with an elif in revision 10, and a comment was updated).
Note: The version of SCons used for these tests was 1.0.1, confirming that the workaround for Visual Studio 2008 works with older SCons installations.
Frequent updates on Twitter
Leave a Reply
You must be logged in to post a comment.