Browse Source

XLClang: Add policy CMP0089 to present as XL for compatibility

We now identify IBM's Clang-based XL compilers, which define
`__ibmxl__`, as `XLClang` rather than `XL`.  In order to support
existing project code that checks for `XL`, add a policy whose OLD
behavior is to present the compiler id as `XL` and whose NEW behavior is
to present the compiler id as `XLClang` as we really detect it.
Brad King 6 years ago
parent
commit
5c41386357

+ 8 - 0
Help/manual/cmake-policies.7.rst

@@ -51,6 +51,14 @@ The :variable:`CMAKE_MINIMUM_REQUIRED_VERSION` variable may also be used
 to determine whether to report an error on use of deprecated macros or
 to determine whether to report an error on use of deprecated macros or
 functions.
 functions.
 
 
+Policies Introduced by CMake 3.15
+=================================
+
+.. toctree::
+   :maxdepth: 1
+
+   CMP0089: Compiler id for IBM Clang-based XL compilers is now XLClang. </policy/CMP0089>
+
 Policies Introduced by CMake 3.14
 Policies Introduced by CMake 3.14
 =================================
 =================================
 
 

+ 30 - 0
Help/policy/CMP0089.rst

@@ -0,0 +1,30 @@
+CMP0089
+-------
+
+Compiler id for IBM Clang-based XL compilers is now ``XLClang``.
+
+CMake 3.15 and above recognize that IBM's Clang-based XL compilers
+that define ``__ibmxl__`` are a new front-end distinct from ``xlc``
+with a different command line and set of capabilities.
+CMake now prefers to present this to projects by setting the
+:variable:`CMAKE_<LANG>_COMPILER_ID` variable to ``XLClang`` instead
+of ``XL``.  However, existing projects may assume the compiler id for
+Clang-based XL is just ``XL`` as it was in CMake versions prior to 3.15.
+Therefore this policy determines for Clang-based XL compilers which
+compiler id to report in the :variable:`CMAKE_<LANG>_COMPILER_ID`
+variable after language ``<LANG>`` is enabled by the :command:`project`
+or :command:`enable_language` command.  The policy must be set prior
+to the invocation of either command.
+
+The OLD behavior for this policy is to use compiler id ``XL``.  The
+NEW behavior for this policy is to use compiler id ``XLClang``.
+
+This policy was introduced in CMake version 3.15.  Use the
+:command:`cmake_policy` command to set this policy to OLD or NEW explicitly.
+Unlike most policies, CMake version |release| does *not* warn
+by default when this policy is not set and simply uses OLD behavior.
+See documentation of the
+:variable:`CMAKE_POLICY_WARNING_CMP0089 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
+variable to control the warning.
+
+.. include:: DEPRECATED.txt

+ 5 - 0
Help/release/dev/add-xlclang.rst

@@ -0,0 +1,5 @@
+add-xlclang
+-----------
+
+* IBM Clang-based XL compilers that define ``__ibmxl__`` now use the
+  compiler id ``XLClang`` instead of ``XL``.  See policy :policy:`CMP0089`.

+ 2 - 0
Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst

@@ -21,6 +21,8 @@ warn by default:
   policy :policy:`CMP0067`.
   policy :policy:`CMP0067`.
 * ``CMAKE_POLICY_WARNING_CMP0082`` controls the warning for
 * ``CMAKE_POLICY_WARNING_CMP0082`` controls the warning for
   policy :policy:`CMP0082`.
   policy :policy:`CMP0082`.
+* ``CMAKE_POLICY_WARNING_CMP0089`` controls the warning for
+  policy :policy:`CMP0089`.
 
 
 This variable should not be set by a project in CMake code.  Project
 This variable should not be set by a project in CMake code.  Project
 developers running CMake may set this variable in their cache to
 developers running CMake may set this variable in their cache to

+ 30 - 0
Source/cmGlobalGenerator.cxx

@@ -956,6 +956,36 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility(
         break;
         break;
     }
     }
   }
   }
+
+  if (strcmp(compilerId, "XLClang") == 0) {
+    switch (mf->GetPolicyStatus(cmPolicies::CMP0089)) {
+      case cmPolicies::WARN:
+        if (!this->CMakeInstance->GetIsInTryCompile() &&
+            mf->PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0089")) {
+          std::ostringstream w;
+          /* clang-format off */
+          w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0089) << "\n"
+            "Converting " << lang <<
+            " compiler id \"XLClang\" to \"XL\" for compatibility."
+            ;
+          /* clang-format on */
+          mf->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
+        }
+        CM_FALLTHROUGH;
+      case cmPolicies::OLD:
+        // OLD behavior is to convert XLClang to XL.
+        mf->AddDefinition(compilerIdVar, "XL");
+        break;
+      case cmPolicies::REQUIRED_IF_USED:
+      case cmPolicies::REQUIRED_ALWAYS:
+        mf->IssueMessage(
+          MessageType::FATAL_ERROR,
+          cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0089));
+      case cmPolicies::NEW:
+        // NEW behavior is to keep AppleClang.
+        break;
+    }
+  }
 }
 }
 
 
 std::string cmGlobalGenerator::GetLanguageOutputExtension(
 std::string cmGlobalGenerator::GetLanguageOutputExtension(

+ 4 - 1
Source/cmPolicies.h

@@ -261,7 +261,10 @@ class cmMakefile;
          3, 14, 0, cmPolicies::WARN)                                          \
          3, 14, 0, cmPolicies::WARN)                                          \
   SELECT(POLICY, CMP0088,                                                     \
   SELECT(POLICY, CMP0088,                                                     \
          "FindBISON runs bison in CMAKE_CURRENT_BINARY_DIR when executing.",  \
          "FindBISON runs bison in CMAKE_CURRENT_BINARY_DIR when executing.",  \
-         3, 14, 0, cmPolicies::WARN)
+         3, 14, 0, cmPolicies::WARN)                                          \
+  SELECT(POLICY, CMP0089,                                                     \
+         "Compiler id for IBM Clang-based XL compilers is now XLClang.", 3,   \
+         15, 0, cmPolicies::WARN)
 
 
 #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
 #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
 #define CM_FOR_EACH_POLICY_ID(POLICY)                                         \
 #define CM_FOR_EACH_POLICY_ID(POLICY)                                         \

+ 3 - 0
Tests/RunCMake/ParseImplicitIncludeInfo/data/CMakeLists.txt

@@ -12,6 +12,9 @@
 #
 #
 
 
 cmake_minimum_required(VERSION 3.3)
 cmake_minimum_required(VERSION 3.3)
+if(POLICY CMP0089)
+  cmake_policy(SET CMP0089 NEW)
+endif()
 
 
 set(lngs C CXX)
 set(lngs C CXX)
 set(LANGUAGES "${lngs}" CACHE STRING "List of languages to generate inputs for")
 set(LANGUAGES "${lngs}" CACHE STRING "List of languages to generate inputs for")