From aa53ee57bb50faa3aa64e86cb58bbe2df6688335 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Oct 2013 14:10:38 -0400 Subject: [PATCH] Add policy CMP0025 for Apple Clang compiler id compatibility The parent commit introduced a separate "AppleClang" compiler id for Apple's Clang distribution. Add a policy in order to support projects that expect this compiler's id to be just "Clang". When the policy is OLD or not set, map AppleClang back to Clang. Continue to use the AppleClang id internally while enabling the language, but set the CMAKE__COMPILER_ID after project() or enable_language() to the compatible value for use by project code. --- Source/cmGlobalGenerator.cxx | 41 ++++++++++++++++++++++++++++++++++++ Source/cmGlobalGenerator.h | 2 ++ Source/cmPolicies.cxx | 17 +++++++++++++++ Source/cmPolicies.h | 1 + 4 files changed, 61 insertions(+) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 7f2b592f3..2c3834a0e 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -616,6 +616,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 @@ -631,6 +634,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 45670b3ca..c3d6a946e 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. *