[CMake] 2.8.11: CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX Value Changed

Brad King brad.king at kitware.com
Wed Oct 16 15:19:33 EDT 2013


On 10/16/2013 12:56 PM, Giordano Khouri wrote:
> Looking at the source code, a check is first made for __clang__
> and sets CMAKE_<LANG>_COMPILER_ID to “Clang”.

Yes.

> If you are using CMake 2.8.12, you can even get “AppleClang”
> to further differentiate it.

AppleClang was introduced just after 2.8.12 and is controlled by
policy CMP0025 for compatibility.

> Since you are using clang, this is correct. This is the variable
> you should be looking at. Since so many flavors of compilers are
> based on or compatible with gcc, the test for __GNUC__ comes after
> testing for all of the others. CMAKE_COMPILER_IS_GNUCC is only set
> for this last case.

Yes, CMAKE_COMPILER_IS_GNUCC is true when CMAKE_C_COMPILER_ID is
"GNU" (and not "Clang").  However, this has been the case since
CMake 2.6.0.  CMake 2.8.2 learned about "Clang", so only versions
older than that would think the compiler is "GNU".

On 10/16/2013 02:45 AM, vv zhao wrote:
> Recently we updated our cmake from 2.8.8 to 2.8.11 on Mac
>
> I see CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX is changed
> from true to false, but I didn't change my compiler at all, I am using
> XCode4.5 and select com.apple.compilers.llvm.clang.1_0 as
> CMAKE_XCODE_ATTRIBUTE_GCC_VERSION in toolchain file,

What I think happened here is that with the Xcode generator prior
to CMake 2.8.10 the Modules/CMakeDetermineCCompiler.cmake would
detect the compiler as if one were using the Makefile generator
with a command-line build.  The result would be totally ignored
by the Xcode generator implementation.  However, as a side effect
the CMAKE_C_COMPILER would get set to a bogus value (/usr/bin/gcc)
that did not actually represent the compiler Xcode would use in
the IDE builds.  It would even detect the compiler id as GNU from
that and then set CMAKE_COMPILER_IS_GNUCC to true.  This was all
representing the information about the wrong compiler, which was
a bug.

This bug was fixed in CMake 2.8.10 with the introduction of logic
to detect the real compiler used by IDEs like VS and Xcode.  In
your case this real compiler is Clang, not GNU, so the end result
is that CMAKE_COMPILER_IS_GNUCC is false instead of the incorrect
true value it had before.

FYI, CMake 2.8.11 introduced the -T option to "cmake" to set the
CMAKE_GENERATOR_TOOLSET, which for Xcode becomes the GCC_VERSION
attribute value.  Therefore you don't need to set

 CMAKE_XCODE_ATTRIBUTE_GCC_VERSION

in project code anymore.  Instead it can be specified at the
command line:

 cmake ../src -G Xcode -T com.apple.compilers.llvm.clang.1_0

Any supported GCC_VERSION value can be specified.  Also, with
Xcode 4.5.2 that version is the default anyway IIRC.

-Brad


More information about the CMake mailing list