[CMake] MSVC variable doesn't work without project() call first

David Cole david.cole at kitware.com
Tue Nov 1 11:43:07 EDT 2011


On Tue, Nov 1, 2011 at 11:22 AM, Alexander Neundorf
<a.neundorf-work at gmx.net> wrote:
> On Tuesday 01 November 2011, Robert Dailey wrote:
>> For some reason the built in variable like MSVC_VERSION and MSVC do not
>> have any value unless the project() command is called first. Can someone
>> explain why?
>
> Without checking...
> IIRC, the project() call enables by default the C and the CXX languages (if
> that hasn't been done before explicitely).
> During enabling the languages the compilers are detected, and with them those
> variables are set.
> So, before that no languages are known to cmake, so these variables are not
> set.
>
> Alex
> --
>
> 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
>

Alex is right.

If you need the value of MSVC *before* calling the project command for
some reason, then you can call enable_language(C) (or CXX) instead...


More information about the CMake mailing list