[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
Thu May 8 17:55:07 EDT 2014


Thanks for your suggestions, J Decker and David. I find both approaches 
(using registry entry paths as hints to find_program or using 
$ENV{VS110COMNTOOLS}) quite interesting. However, I'd rather not have to 
write such code for each compiler version separately, in my CMakeLists. 
Also I have the impression that CMake already "knows" the directory path 
name of the selected compiler (current generator), so it would be 
helpful if CMake could tell me so directly.

We currently find vcvarsall.bat as follows:

   get_filename_component(MY_LINKER_DIR ${CMAKE_LINKER} DIRECTORY)
   find_file(MY_VCVARSALL_BAT vcvarsall.bat
     "${MY_LINKER_DIR}/.." "${MY_LINKER_DIR}/../..")

This appears to work fine for any Visual C++ version I have tested so 
far, including both 32 and 64 bits. However, it assumes that CMake 
generates this CMAKE_LINKER variable. Is it okay to make that assumption?

Kind regards, Niels

On 5/8/2014 11:09 PM, David Cole wrote:
> How about:
>
>     if(EXISTS "$ENV{VS110COMNTOOLS}../../VC")
>        get_filename_component(VC11_DIR "$ENV{VS110COMNTOOLS}../../VC"
> ABSOLUTE)
>     endif()
>     if(EXISTS "$ENV{VS120COMNTOOLS}../../VC")
>        get_filename_component(VC12_DIR "$ENV{VS120COMNTOOLS}../../VC"
> ABSOLUTE)
>     endif()
>     message(STATUS "VC11_DIR='${VC11_DIR}'")
>     message(STATUS "VC12_DIR='${VC12_DIR}'")



More information about the CMake mailing list