[CMake] Visual Studio 12 C++ Compiler Detection

Allen Barnett Allen.Barnett at varian.com
Thu Dec 4 18:29:34 EST 2014


Hi: I'm trying to create a 64-bit Visual Studio 12 (aka 2013) project with CMake 3.0.2. My CMakeLists.txt file is really simple:

cmake_minimum_required( VERSION 3.0 )
project( cmc CXX )
# What compiler did we find?
message( "C++: ${CMAKE_CXX_COMPILER}" )

>From a windows shell I do:

> c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\vcvars64.bat
> cmake -G "Visual Studio 12 Win64" .
-- The CXX compiler identification is MSVC 18.0.31101.0
-- Check for working CXX compiler using: Visual Studio 12 2013 Win64
-- Check for working CXX compiler using: Visual Studio 12 2013 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
C++: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/cl.exe
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/dbarnett/cmc/build

So, it appears to find the compiler OK since it emits the correct compiler identification. But, the actual value of CMAKE_CXX_COMPILER is not usable. If you try to execute C:/Program..../x86_amd64/cl.exe from within a CMake script or even from the command line, it will fail and produce the well-known "0xc000007b" dialog (missing DLL). Unless you've sourced vcvarsx86_amd64.bat, the correct environment variables are not set for this version of the compiler.

On the other hand, if I do "cmake -G NMake Makefiles", I get what I expect:

-- The CXX compiler identification is MSVC 18.0.31101.0
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
C++: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/cl.exe
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/dbarnett/cmc/other

Namely, it finds C:/Program..../amd64/cl.exe.

I've looked through the CMake Modules, but I could not really find the place where CMake derives the value for CMAKE_CXX_COMPILER when you generate a VS project. Could someone point me to the source code where this occurs? I would like to see how it is coming up with this version of the compiler which isn't even in the PATH.

Thanks,
Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141204/16abbc9c/attachment-0001.html>


More information about the CMake mailing list