[CMake] How to find vcvarsall.bat (e.g. at "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC")? CMAKE_LINKER?

Niels Dekker - address until 2018 niels_dekker_address_until_2018 at xs4all.nl
Sun May 11 05:03:27 EDT 2014


On May 10 2014, Iulian-Nicu Şerbănoiu wrote:
> Isn't it better to use vsvars32.bat? (or vsvars64.bat? - don't have
> a 64 bit windows)

vcvarsall.bat supports both 32-bits and 64-bits, as it may calls either 
vcvars32.bat or vcvars64.bat (depending on its optional argument, see 
http://msdn.microsoft.com/en-us/library/x4d2c09s.aspx). But indeed, if 
you only have 32-bits Windows, you might as well call vcvars32.bat directly.

> Here is the batch script for VS 2013, 2012, 2010 (priority in this
> specific order)
> ~~~~~~~~~
> IF  EXIST  "%VS120COMNTOOLS%"  CALL  "%VS120COMNTOOLS%vsvars32.bat"  &&SET  GENERATOR="Visual Studio 12"  &&GOTO  BUILD
> IF  EXIST  "%VS110COMNTOOLS%"  CALL  "%VS110COMNTOOLS%vsvars32.bat"  &&SET  GENERATOR="Visual Studio 11"  &&GOTO  BUILD
> IF  EXIST  "%VS100COMNTOOLS%"  CALL  "%VS100COMNTOOLS%vsvars32.bat"  &&SET  GENERATOR="Visual Studio 10"  &&GOTO  BUILD

Thank, Iulian. But my original question was about finding vcvarsall.bat 
from within CMakeLists.txt, and whether it is okay to use CMAKE_LINKER, 
given the fact that CMAKE_LINKER is undocumented. David Cole suggested 
me to use CMAKE_CXX_COMPILER instead, which appears to work fine:

   get_filename_component(MY_COMPILER_DIR
     ${CMAKE_CXX_COMPILER} DIRECTORY)
   find_file(MY_VCVARSALL_BAT vcvarsall.bat
     "${MY_COMPILER_DIR}/.." "${MY_COMPILER_DIR}/../..")

Result: MY_VCVARSALL_BAT = C:/Program Files (x86)/Microsoft Visual 
Studio 12.0/VC/vcvarsall.bat  :-)

Kind regards, Niels




More information about the CMake mailing list