From ab65862417adc80dfb18170a6bd70889a24fe045 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Oct 2013 13:52:48 -0400 Subject: Clang: Add separate "AppleClang" compiler id Apple distributes their own Clang build with their own version numbers that differ from upstream Clang. Use the __apple_build_version__ symbol to identify the Apple Clang compiler and report the Apple Build Version as the fourth version component in CMAKE__COMPILER_VERSION. Add Compiler/AppleClang- and Platform/Darwin-AppleClang- modules that simply include the upstream equivalents. Fix comparisons of CMAKE__COMPILER_ID to Clang in CMake's own source and tests to account for AppleClang. --- Modules/CMakeCCompilerId.c.in | 7 ++++++- Modules/CMakeCXXCompilerId.cpp.in | 7 ++++++- Modules/Compiler/AppleClang-ASM.cmake | 1 + Modules/Compiler/AppleClang-C.cmake | 1 + Modules/Compiler/AppleClang-CXX.cmake | 1 + Modules/Platform/Darwin-AppleClang-C.cmake | 1 + Modules/Platform/Darwin-AppleClang-CXX.cmake | 1 + Source/cmDocumentVariables.cxx | 1 + Tests/Assembler/CMakeLists.txt | 2 +- Tests/IncludeDirectories/CMakeLists.txt | 2 +- Utilities/cmlibarchive/CMakeLists.txt | 2 +- 11 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 Modules/Compiler/AppleClang-ASM.cmake create mode 100644 Modules/Compiler/AppleClang-C.cmake create mode 100644 Modules/Compiler/AppleClang-CXX.cmake create mode 100644 Modules/Platform/Darwin-AppleClang-C.cmake create mode 100644 Modules/Platform/Darwin-AppleClang-CXX.cmake diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in index 66a5582..56c11a0 100644 --- a/Modules/CMakeCCompilerId.c.in +++ b/Modules/CMakeCCompilerId.c.in @@ -29,7 +29,12 @@ # endif #elif defined(__clang__) -# define COMPILER_ID "Clang" +# if defined(__apple_build_version__) +# define COMPILER_ID "AppleClang" +# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__) +# else +# define COMPILER_ID "Clang" +# endif # define COMPILER_VERSION_MAJOR DEC(__clang_major__) # define COMPILER_VERSION_MINOR DEC(__clang_minor__) # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in index 5e87715..2b8bf6e 100644 --- a/Modules/CMakeCXXCompilerId.cpp.in +++ b/Modules/CMakeCXXCompilerId.cpp.in @@ -34,7 +34,12 @@ # endif #elif defined(__clang__) -# define COMPILER_ID "Clang" +# if defined(__apple_build_version__) +# define COMPILER_ID "AppleClang" +# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__) +# else +# define COMPILER_ID "Clang" +# endif # define COMPILER_VERSION_MAJOR DEC(__clang_major__) # define COMPILER_VERSION_MINOR DEC(__clang_minor__) # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) diff --git a/Modules/Compiler/AppleClang-ASM.cmake b/Modules/Compiler/AppleClang-ASM.cmake new file mode 100644 index 0000000..f52bde0 --- /dev/null +++ b/Modules/Compiler/AppleClang-ASM.cmake @@ -0,0 +1 @@ +include(Compiler/Clang-ASM) diff --git a/Modules/Compiler/AppleClang-C.cmake b/Modules/Compiler/AppleClang-C.cmake new file mode 100644 index 0000000..44070b8 --- /dev/null +++ b/Modules/Compiler/AppleClang-C.cmake @@ -0,0 +1 @@ +include(Compiler/Clang-C) diff --git a/Modules/Compiler/AppleClang-CXX.cmake b/Modules/Compiler/AppleClang-CXX.cmake new file mode 100644 index 0000000..680f720 --- /dev/null +++ b/Modules/Compiler/AppleClang-CXX.cmake @@ -0,0 +1 @@ +include(Compiler/Clang-CXX) diff --git a/Modules/Platform/Darwin-AppleClang-C.cmake b/Modules/Platform/Darwin-AppleClang-C.cmake new file mode 100644 index 0000000..98971bb --- /dev/null +++ b/Modules/Platform/Darwin-AppleClang-C.cmake @@ -0,0 +1 @@ +include(Platform/Darwin-Clang-C) diff --git a/Modules/Platform/Darwin-AppleClang-CXX.cmake b/Modules/Platform/Darwin-AppleClang-CXX.cmake new file mode 100644 index 0000000..4e9e7c1 --- /dev/null +++ b/Modules/Platform/Darwin-AppleClang-CXX.cmake @@ -0,0 +1 @@ +include(Platform/Darwin-Clang-CXX) diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx index c4f6216..a2a1bd6 100644 --- a/Source/cmDocumentVariables.cxx +++ b/Source/cmDocumentVariables.cxx @@ -1606,6 +1606,7 @@ void cmDocumentVariables::DefineVariables(cmake* cm) "Possible values include:\n" " Absoft = Absoft Fortran (absoft.com)\n" " ADSP = Analog VisualDSP++ (analog.com)\n" + " AppleClang = Apple Clang (apple.com)\n" " Clang = LLVM Clang (clang.llvm.org)\n" " Cray = Cray Compiler (cray.com)\n" " Embarcadero, Borland = Embarcadero (embarcadero.com)\n" diff --git a/Tests/Assembler/CMakeLists.txt b/Tests/Assembler/CMakeLists.txt index bb4bccc..1f07dc9 100644 --- a/Tests/Assembler/CMakeLists.txt +++ b/Tests/Assembler/CMakeLists.txt @@ -9,7 +9,7 @@ set(SRCS) # and also generate assembler files from C: if("${CMAKE_GENERATOR}" MATCHES "Makefile|Xcode" AND NOT CMAKE_OSX_ARCHITECTURES) - if(("${CMAKE_C_COMPILER_ID}" MATCHES "^(GNU|Clang|HP|SunPro|XL)$") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel" AND UNIX)) + if(("${CMAKE_C_COMPILER_ID}" MATCHES "^(GNU|Clang|AppleClang|HP|SunPro|XL)$") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel" AND UNIX)) set(C_FLAGS "${CMAKE_C_FLAGS}") separate_arguments(C_FLAGS) if(CMAKE_OSX_SYSROOT AND CMAKE_C_SYSROOT_FLAG AND NOT ";${C_FLAGS};" MATCHES ";${CMAKE_C_SYSROOT_FLAG};") diff --git a/Tests/IncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/CMakeLists.txt index 35ad8dc..9ee1957 100644 --- a/Tests/IncludeDirectories/CMakeLists.txt +++ b/Tests/IncludeDirectories/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 2.6) project(IncludeDirectories) if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4) - OR CMAKE_C_COMPILER_ID STREQUAL Clang) + OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL AppleClang) AND (CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "Ninja")) include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-Wunused-variable run_sys_includes_test) diff --git a/Utilities/cmlibarchive/CMakeLists.txt b/Utilities/cmlibarchive/CMakeLists.txt index 8ef0e89..132bfeb 100644 --- a/Utilities/cmlibarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/CMakeLists.txt @@ -56,7 +56,7 @@ SET(CMAKE_REQUIRED_FLAGS) # Disable warnings to avoid changing 3rd party code. IF("${CMAKE_C_COMPILER_ID}" MATCHES - "^(GNU|Clang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$") + "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") ELSEIF("${CMAKE_C_COMPILER_ID}" MATCHES "^(PathScale)$") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall") -- cgit v0.12