Merge topic 'apple-clang-id'

1763c31 Set policy CMP0025 to NEW while building CMake itself
aa53ee5 Add policy CMP0025 for Apple Clang compiler id compatibility
ab65862 Clang: Add separate "AppleClang" compiler id
This commit is contained in:
Brad King 2013-10-09 10:21:28 -04:00 committed by CMake Topic Stage
commit 12a7e2b10c
19 changed files with 94 additions and 5 deletions

View File

@ -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)

View File

@ -29,7 +29,12 @@
# endif
#elif defined(__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__)

View File

@ -34,7 +34,12 @@
# endif
#elif defined(__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__)

View File

@ -0,0 +1 @@
include(Compiler/Clang-ASM)

View File

@ -0,0 +1 @@
include(Compiler/Clang-C)

View File

@ -0,0 +1 @@
include(Compiler/Clang-CXX)

View File

@ -0,0 +1 @@
include(Platform/Darwin-Clang-C)

View File

@ -0,0 +1 @@
include(Platform/Darwin-Clang-CXX)

View File

@ -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"

View File

@ -624,6 +624,9 @@ cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& 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::vector<std::string>const& 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)

View File

@ -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

View File

@ -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_<LANG>_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_<LANG>_COMPILER_ID after <LANG> 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()

View File

@ -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.
*

View File

@ -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.

View File

@ -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};")

View File

@ -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)

View File

@ -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}"

View File

@ -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

View File

@ -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")