[CMake] Path to current Visual Studio installation

David Cole david.cole at kitware.com
Thu Mar 17 13:35:05 EDT 2011


I haven't found a super-easy, completely reliable way to do this for
all versions of Visual Studio. But here's some data for you...

If it's set, for VS9 and earlier, CMAKE_MAKE_PROGRAM will point to the
full path of devenv.com:
CMAKE_MAKE_PROGRAM:FILEPATH=C:/PROGRA~2/MICROS~1.0/Common7/IDE/devenv.com

But for VS10, that points to MSBuild, which is typically here:
CMAKE_MAKE_PROGRAM:FILEPATH=C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe
(and doesn't help you say anything one way or another about
which/where VS is being used)

And for an nmake based build, it is frequently simply "nmake" without
any path info, trusting that you'll run it from the proper environment
to use the right nmake whenever you do a build in that tree...

Basing your code on the environment variables VS90COMNTOOLS and
VS100COMNTOOLS (and prior version equivalents if needed) might be one
way to do what you want.

In fact, I wrote a blog article about a year ago on how to extract the
VS root dir from those environment variables here in a batch file
context:
http://dlrdave.blogspot.com/2010/03/fun-with-batch-files.html

Sorry there's not a more direct way to do it.


Hope this is helpful,
David


On Thu, Mar 17, 2011 at 12:56 PM, James Bigler <jamesbigler at gmail.com> wrote:
> I'm wanting to get a path that points me to where vcvarsall.bat might live.
> It's usually in the VS installation directory, and I was wondering if there
> was a nice convenient CMake variable that could tell me where Visual Studio
> is located.
>
> "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat
>
> I see from the documentation we have various variables regarding which
> version of visual studio we have:
>
> CMAKE_CL_64
> CMAKE_COMPILER_2005
> MSVC_IDE
> MSVC_VERSION
>
> In my cache the path to cl is simply cl:
> CMAKE_C_COMPILER:FILEPATH=cl
>
> Thanks,
> James
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list