Boost logo

Boost-Build :

From: Alexey Pakhunov (alexeypa_at_[hidden])
Date: 2005-09-23 14:04:35


Vladimir Prus wrote:
> 1. For large patches, it's preferrable to send proposed log message along with
> the patch. This allows to document the purpose (indent) of the patch.

This patch implements autodetection code for the 'msvc' toolset. It is
able to detect Visual Studio 6.0, 7.0, 7.1, 8.0 and Visual C++ Toolkit
2003. Detected settings are used in the cases when:
- only version number is passed (using msvc : 8.0 ;)
- incomplete configuration command is given (using msvc : 8.0 : cl.exe ;)
- any available compiler is configured (using : default ;)
- all available compilers are configured (using : all ;)

A user is free to overwrite any of detected settings.

> 2. I see you've dropped use of the VS80COMNTTOOLS variable, and also dropped
> default paths for 8.0, 7.0 and 7.1. You left default paths for 6.0 and
> 7.1toolkit. I'd like some comment explaining this. I assume the problem with
> 7.1 toolkit is that it does not set any registry keys, but what's wrong with
> 6.0. Does it have the same problem.

We didn't have autodetection for 6.0 before and I didn't know where the
installation path is stored in the registry. After some googling the
correct path was found. It is
"HKLM\SOFTWARE\Microsoft\VisualStudio\6.0\Setup\Microsoft Visual
C++\ProductDir". At least some OpenOffice-related scripts relay on it.

Free C++ Toolkit does not have registry settings at all. I added the
comment.

Best regards/Venlig hilsen,
Alexey Pakhunov.
 --------------000906050902000804030909 Content-Type: text/plain;
name="msvc.autodetection.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="msvc.autodetection.diff"

Index: msvc.jam
===================================================================
RCS file: /cvsroot/boost/boost/tools/build/v2/tools/msvc.jam,v
retrieving revision 1.54
diff -u -r1.54 msvc.jam
--- msvc.jam 23 Sep 2005 14:17:59 -0000 1.54
+++ msvc.jam 23 Sep 2005 18:40:13 -0000
@@ -223,11 +223,14 @@
{
version = 8.0 ;
}
- else if [ MATCH "(NET 2003[\/\\]VC7)" : $(command) ] ||
- [ MATCH "(Microsoft Visual C\\+\\+ Toolkit 2003)" : $(command) ]
+ else if [ MATCH "(NET 2003[\/\\]VC7)" : $(command) ]
{
version = 7.1 ;
}
+ else if [ MATCH "(Microsoft Visual C\\+\\+ Toolkit 2003)" : $(command) ]
+ {
+ version = 7.1toolkit ;
+ }
else if [ MATCH "(.NET[\/\\]VC7)" : $(command) ]
{
version = 7.0 ;
@@ -265,71 +268,58 @@
}

-rule default-paths ( version ? )
+# Returns the default installation path for the given version.
+local rule default-path ( version )
{
- local possible-paths ;
-
- local ProgramFiles = [ os.environ ProgramFiles ] ;
- if ! $(ProgramFiles)
- {
- ProgramFiles = "c:\\Program Files" ;
- }
+ # Use auto-detected path if possible
+ local path = [ get-values <command> :
+ [ $(.versions).get $(version) : options ] ] ;

- local version-6-path = $(ProgramFiles)"\\Microsoft Visual Studio\\VC98" ;
- local version-7-path = $(ProgramFiles)"\\Microsoft Visual Studio .NET\\VC7" ;
- local version-7.0-path = $(version-7-path) ;
- local version-7.1-path = $(ProgramFiles)"\\Microsoft Visual Studio .NET 2003\\VC7" ;
- local version-8.0-path = $(ProgramFiles)"\\Microsoft Visual Studio 8" ;
-
- local VS71COMNTOOLS = [ os.environ VS71COMNTOOLS ] ;
- if $(VS71COMNTOOLS)
+ if $(path)
{
- # VS71COMNTOOLS is set by VS .NET 2003 to <VSDIR>\Common7\Tools
- version-7.1-path = [ path.make $(VS71COMNTOOLS) ] ;
- version-7.1-path = [ path.parent $(version-7.1-path) ] ;
- version-7.1-path = [ path.parent $(version-7.1-path) ] ;
- version-7.1-path = [ path.join $(version-7.1-path) "VC7" ] ;
- version-7.1-path = [ path.native $(version-7.1-path) ] ;
+ path = $(path:D) ;
}
-
- local VS80COMNTOOLS = [ os.environ VS80COMNTOOLS ] ;
-
- if $(VS80COMNTOOLS)
+ else
{
- # VS80COMNTOOLS is set by VS .NET 2005 to <VSDIR>\Common7\Tools
- version-8.0-path = [ path.make "$(VS80COMNTOOLS)" ] ;
- version-8.0-path = [ path.parent $(version-8.0-path) ] ;
- version-8.0-path = [ path.parent $(version-8.0-path) ] ;
- version-8.0-path = [ path.join $(version-8.0-path) "VC" ] ;
- version-8.0-path = [ path.native $(version-8.0-path) ] ;
+ # Check environment
+ if $(.version-$(version)-env)
+ {
+ local vc-path = [ os.environ $(.version-$(version)-env) ] ;
+ if $(vc-path)
+ {
+ vc-path = [ path.make $(vc-path) ] ;
+ vc-path = [ path.join $(vc-path) $(.version-$(version)-envpath) ] ;
+ vc-path = [ path.native $(vc-path) ] ;
+
+ path = $(vc-path) ;
+ }
+ }
+
+ # Check default path
+ if ! $(path) && $(.version-$(version)-path)
+ {
+ path = [ path.native [ path.join $(.ProgramFiles) $(.version-$(version)-path) ] ] ;
+ }
}

- # Fixed so we don't add paths without \\bin to all versions.
- # Path without 7.1
+ return $(path) ;
+}

+# Returns either the default installation path (if 'version' is not empty) or list of all
+# known default paths (if no version is given)
+rule default-paths ( version ? )
+{
+ local possible-paths ;
+
if $(version)
{
- local v = [ MATCH ^(6|[^6].*) : $(version) ] ;
- possible-paths += $(version-$(v)-path) ;
+ default-path += [ default-path $(version) ] ;
}
else
{
- possible-paths += $(version-8.0-path) $(version-7.1-path) $(version-7.0-path) $(version-6-path) ;
- }
-
- # The vcvars32.bat is actually in "bin" directory.
- # (except for free VC7.1 tools)
- possible-paths = $(possible-paths)\\bin ;
-
- local VCToolkitInstallDir = [ os.environ VCToolkitInstallDir ] ;
- if $(VCToolkitInstallDir)
- {
- if $(version) = "7.1" || ! $(version)
+ for local i in $(.known-versions)
{
- # NOTE it's impossible to switch between Toolkit and VS.
- # I wonder is toolkit and VS can be installed together?
- possible-paths += [ path.native [ path.make $(VCToolkitInstallDir) ] ] ;
-
+ default-path += [ default-path $(i) ] ;
}
}

@@ -529,3 +519,84 @@
}

+#
+# Autodetection code
+# detects versions listed as '.known-versions' using registry, environment
+# and checking default paths. Supports both native Windows and Cygwin.
+#
+
+.ProgramFiles = [ path.make [ common.get-program-files-dir ] ] ;
+
+.known-versions = 8.0 7.1 7.1toolkit 7.0 6.0 ;
+
+# Name of the registry key that contains Visual C++ installation path
+# (relative to "HKEY_LOCAL_MACHINE\SOFTWARE\\Microsoft\VisualStudio\x.y\Setup"
+.version-6.0-reg = "Microsoft Visual C++" ;
+.version-7.0-reg = "VC" ;
+.version-7.1-reg = "VC" ;
+.version-8.0-reg = "VC" ;
+
+# Visual C++ Toolkit 2003 do not store its installation path in the registry.
+# The environment variable 'VCToolkitInstallDir' and the default installation
+# path will be checked instead.
+.version-7.1toolkit-path = "Microsoft Visual C++ Toolkit 2003" "bin" ;
+.version-7.1toolkit-env = VCToolkitInstallDir ;
+
+# Path to the folder containing "cl.exe" relative to the value of the corresponding
+# environment variable
+.version-7.1toolkit-envpath = "bin" ;
+
+
+# Validates given path, registers found configuration and prints debug information
+# about it.
+local rule register-configuration ( version : path ? )
+{
+ if $(path)
+ {
+ local command = [ GLOB $(path) : cl.exe ] ;
+
+ if $(command)
+ {
+ if $(.debug-configuration)
+ {
+ ECHO "notice: msvc-$(version) detected, command: '$(command)'" ;
+ }
+
+ $(.versions).register $(version) ;
+ $(.versions).set $(version) : options : <command>$(command) ;
+ }
+ }
+}
+
+if [ os.name ] in NT CYGWIN
+{
+ # Get installation paths from the registry
+
+ for local i in $(.known-versions)
+ {
+ if $(.version-$(i)-reg)
+ {
+ local vc-path = [ W32_GETREG
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$(i)\\Setup\\"$(.version-$(i)-reg)
+ : "ProductDir" ] ;
+
+ if $(vc-path)
+ {
+ vc-path = [ path.native [ path.join [ path.make-NT $(vc-path) ] "bin" ] ] ;
+ register-configuration $(i) : $(vc-path) ;
+ }
+ }
+ }
+}
+
+
+# Check environment and default installation paths
+
+for local i in $(.known-versions)
+{
+ if ! $(i) in [ $(.versions).all ]
+ {
+ register-configuration $(i) : [ default-path $(i) ] ;
+ }
+}
+
 --------------000906050902000804030909--


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk