[CMake] Wrong cl.exe getting picked up
Bill Hoffman
bill.hoffman at kitware.com
Thu Mar 15 08:46:38 EDT 2012
On 3/14/2012 6:39 PM, James Bigler wrote:
> I have a system with several copies of Visual Studio installed.
>
> When I set the generator for "Visual Studio 9 2008" it ends up picking
> up a different compiler:
>
> CMAKE_C_COMPILER:FILEPATH=C:/Program Files (x86)/SCE/Common/VSI/bin/cl.exe
>
> I think this is because of the following code in
> CMakeDetermineCCompiler.cmake (which I can't figure out how it's invokes
> by the cmake-gui or cmake.exe):
>
> # Find the compiler.
> IF (_CMAKE_USER_CXX_COMPILER_PATH)
> FIND_PROGRAM(CMAKE_C_COMPILER NAMES ${CMAKE_C_COMPILER_LIST} PATHS
> ${_CMAKE_USER_CXX_COMPILER_PATH} DOC "C compiler" NO_DEFAULT_PATH)
> ENDIF (_CMAKE_USER_CXX_COMPILER_PATH)
> FIND_PROGRAM(CMAKE_C_COMPILER NAMES ${CMAKE_C_COMPILER_LIST} DOC "C
> compiler")
>
> IF(CMAKE_C_COMPILER_INIT AND NOT CMAKE_C_COMPILER)
> SET(CMAKE_C_COMPILER "${CMAKE_C_COMPILER_INIT}" CACHE FILEPATH "C
> compiler" FORCE)
> ENDIF(CMAKE_C_COMPILER_INIT AND NOT CMAKE_C_COMPILER)
>
> I believe the CMAKE_C_COMPILER_LIST contains "cl" as is the default of
> CMAKE_GENERATOR_CC for VS generators.
>
> Typically VS isn't in the default path, so the first two FIND_PROGRAM
> commands don't yield any usable results. Then the next block sets the
> CMAKE_C_COMPILER to "cl", and everything is OK, because if it's run from
> within the project, VS sets the paths so its cl.exe is first.
>
> However if there is another cl.exe in the system PATH, then that version
> will get picked up by the second FIND_PROGRAM, and thus cause a bit of
> trouble later on when the copies of cl.exe aren't the same.
>
> Does this seem like a bug to anyone? It seems like if you would want cl
> to point to the same version as your copy of Visual Studio. Perhaps
> $(VCInstallDir) could be used with a custom command to generate what VS
> thinks the path should be?
>
> Anyone have any thoughts?
>
> I'm using CMake 2.8.2 and 2.8.6 on windows.
>
So, with the IDE generators CMake should not even look for cl. It does
not use that value anyway.
-Bill
More information about the CMake
mailing list