diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fbbe08a1..77b460440 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,9 @@ #============================================================================= cmake_minimum_required(VERSION 2.8.2 FATAL_ERROR) set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required +if(POLICY CMP0025) + cmake_policy(SET CMP0025 NEW) +endif() project(CMake) if(CMAKE_BOOTSTRAP) diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in index dda7bf6f3..6dde1c3b2 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 915ae7faa..3a6092242 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 000000000..f52bde05e --- /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 000000000..44070b83f --- /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 000000000..680f7208e --- /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 000000000..98971bbca --- /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 000000000..4e9e7c12e --- /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 8b5f8510b..58634ea13 100644 --- a/Source/cmDocumentVariables.cxx +++ b/Source/cmDocumentVariables.cxx @@ -1622,6 +1622,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/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index dc4bf5053..eacf85ba2 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -624,6 +624,9 @@ cmGlobalGenerator::EnableLanguage(std::vectorconst& languages, { this->LanguageToOriginalSharedLibFlags[lang] = sharedLibFlags; } + + // Translate compiler ids for compatibility. + this->CheckCompilerIdCompatibility(mf, lang); } // end for each language // Now load files that can override any settings on the platform or for @@ -639,6 +642,44 @@ cmGlobalGenerator::EnableLanguage(std::vectorconst& languages, } } +//---------------------------------------------------------------------------- +void cmGlobalGenerator::CheckCompilerIdCompatibility(cmMakefile* mf, + std::string lang) +{ + std::string compilerIdVar = "CMAKE_" + lang + "_COMPILER_ID"; + const char* compilerId = mf->GetDefinition(compilerIdVar.c_str()); + if(compilerId && strcmp(compilerId, "AppleClang") == 0) + { + cmPolicies* policies = this->CMakeInstance->GetPolicies(); + switch(mf->GetPolicyStatus(cmPolicies::CMP0025)) + { + case cmPolicies::WARN: + if(!this->CMakeInstance->GetIsInTryCompile()) + { + cmOStringStream w; + w << policies->GetPolicyWarning(cmPolicies::CMP0025) << "\n" + "Converting " << lang << + " compiler id \"AppleClang\" to \"Clang\" for compatibility." + ; + mf->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + } + case cmPolicies::OLD: + // OLD behavior is to convert AppleClang to Clang. + mf->AddDefinition(compilerIdVar.c_str(), "Clang"); + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + mf->IssueMessage( + cmake::FATAL_ERROR, + policies->GetRequiredPolicyError(cmPolicies::CMP0025) + ); + case cmPolicies::NEW: + // NEW behavior is to keep AppleClang. + break; + } + } +} + //---------------------------------------------------------------------------- const char* cmGlobalGenerator::GetLanguageOutputExtension(cmSourceFile const& source) diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 18aba24bf..70f6e32b2 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -383,6 +383,8 @@ private: void WriteSummary(); void WriteSummary(cmTarget* target); + void CheckCompilerIdCompatibility(cmMakefile* mf, std::string lang); + cmExternalMakefileProjectGenerator* ExtraGenerator; // track files replaced during a Generate diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 9e5e6e004..1d3469f7f 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -620,6 +620,23 @@ cmPolicies::cmPolicies() "The NEW behavior for this policy is to not to allow including the " "result of an export() command.", 2,8,13,0, cmPolicies::WARN); + + this->DefinePolicy( + CMP0025, "CMP0025", + "Compiler id for Apple Clang is now AppleClang.", + "CMake >= 2.8.13 recognize that Apple Clang is a different compiler " + "than upstream Clang and that they have different version numbers. " + "CMake now prefers to present this to projects by setting " + "CMAKE__COMPILER_ID to \"AppleClang\" instead of \"Clang\". " + "However, existing projects may assume the compiler id for Apple Clang " + "is just \"Clang\" as it was in CMake < 2.8.13. " + "Therefore this policy determines for Apple Clang which compiler id " + "to report in CMAKE__COMPILER_ID after is enabled by " + "the project() or enable_language() command." + "\n" + "The OLD behavior for this policy is to use compiler id \"Clang\". " + "The NEW behavior for this policy is to use compiler id \"AppleClang\".", + 2,8,13,0, cmPolicies::WARN); } cmPolicies::~cmPolicies() diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index bafe5b2d3..ec8959d45 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -75,6 +75,7 @@ public: CMP0022, ///< INTERFACE_LINK_LIBRARIES defines the link interface CMP0023, ///< Disallow mixing keyword and plain tll signatures CMP0024, ///< Disallow including export() result. + CMP0025, ///< Compiler id for Apple Clang is now AppleClang /** \brief Always the last entry. * diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index 0f2783689..a9d89d474 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -85,6 +85,9 @@ # written. CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR) +IF(POLICY CMP0025) + CMAKE_POLICY(SET CMP0025 NEW) +ENDIF() #----------------------------------------------------------------------------- # If a namespace is not specified, use "kwsys" and enable testing. diff --git a/Tests/Assembler/CMakeLists.txt b/Tests/Assembler/CMakeLists.txt index bb4bcccbe..1f07dc9cf 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 35ad8dc90..9ee195714 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/Tests/RunCMake/RunCMake.cmake b/Tests/RunCMake/RunCMake.cmake index f770c9368..5c7c05c1a 100644 --- a/Tests/RunCMake/RunCMake.cmake +++ b/Tests/RunCMake/RunCMake.cmake @@ -36,6 +36,9 @@ function(run_cmake test) if(NOT DEFINED RunCMake_TEST_OPTIONS) set(RunCMake_TEST_OPTIONS "") endif() + if(APPLE) + list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0025=NEW) + endif() execute_process( COMMAND ${CMAKE_COMMAND} "${RunCMake_TEST_SOURCE_DIR}" -G "${RunCMake_GENERATOR}" diff --git a/Utilities/cmcurl/CMakeLists.txt b/Utilities/cmcurl/CMakeLists.txt index 74a713dd8..abf04d8b0 100644 --- a/Utilities/cmcurl/CMakeLists.txt +++ b/Utilities/cmcurl/CMakeLists.txt @@ -1,4 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR) +IF(POLICY CMP0025) + CMAKE_POLICY(SET CMP0025 NEW) +ENDIF() PROJECT(LIBCURL C) # Setup package meta-data diff --git a/Utilities/cmlibarchive/CMakeLists.txt b/Utilities/cmlibarchive/CMakeLists.txt index 8ef0e89d6..132bfebdb 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")