[Cmake-commits] CMake branch, next, updated. v3.0.0-rc3-2469-g5528d01

Stephen Kelly steveire at gmail.com
Thu Apr 17 11:19:26 EDT 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  5528d015f2ba96790ed399500f4f050a80e7d5dc (commit)
       via  ce9001ddedf8f51e474750341dc604d08a97bca9 (commit)
       via  5b34ccc5adb9f905e64bb8d8a01288b9a8a37d1f (commit)
      from  a1c076704cd0a71533b542c271ea9fa560ba8c37 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5528d015f2ba96790ed399500f4f050a80e7d5dc
commit 5528d015f2ba96790ed399500f4f050a80e7d5dc
Merge: a1c0767 ce9001d
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Thu Apr 17 11:19:26 2014 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Thu Apr 17 11:19:26 2014 -0400

    Merge topic 'WriteCompilerDetectionHeader-module' into next
    
    ce9001dd Add the WriteCompilerDetectionHeader module.
    5b34ccc5 Project: Add another define for determined compiler ids.


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ce9001ddedf8f51e474750341dc604d08a97bca9
commit ce9001ddedf8f51e474750341dc604d08a97bca9
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Mon Oct 21 16:59:40 2013 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Thu Apr 17 15:09:16 2014 +0200

    Add the WriteCompilerDetectionHeader module.
    
    Provide a function to write a portable header to detect compiler
    features.

diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst
index 2bbe622..ecc9cc4 100644
--- a/Help/manual/cmake-modules.7.rst
+++ b/Help/manual/cmake-modules.7.rst
@@ -232,3 +232,4 @@ All Modules
    /module/UsewxWidgets
    /module/Use_wxWindows
    /module/WriteBasicConfigVersionFile
+   /module/WriteCompilerDetectionHeader
diff --git a/Help/module/WriteCompilerDetectionHeader.rst b/Help/module/WriteCompilerDetectionHeader.rst
new file mode 100644
index 0000000..4c81b48
--- /dev/null
+++ b/Help/module/WriteCompilerDetectionHeader.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/WriteCompilerDetectionHeader.cmake
diff --git a/Help/release/dev/module-WriteCompilerDetectionHeader.rst b/Help/release/dev/module-WriteCompilerDetectionHeader.rst
new file mode 100644
index 0000000..d355d2c
--- /dev/null
+++ b/Help/release/dev/module-WriteCompilerDetectionHeader.rst
@@ -0,0 +1,5 @@
+module-WriteCompilerDetectionHeader
+-----------------------------------
+
+* The WriteCompilerDetectionHeader module was added to allow creation of
+  a portable header file for compiler optional feature detection.
diff --git a/Modules/WriteCompilerDetectionHeader.cmake b/Modules/WriteCompilerDetectionHeader.cmake
new file mode 100644
index 0000000..1043024
--- /dev/null
+++ b/Modules/WriteCompilerDetectionHeader.cmake
@@ -0,0 +1,368 @@
+#.rst:
+# WriteCompilerDetectionHeader
+# ----------------------------
+#
+# Function for generation of compile feature conditionals
+#
+# This module provides the function write_compiler_detection_header().
+#
+# The ``GENERATE_EXPORT_HEADER`` function can be used to generate a file
+# suitable for preprocessor inclusion which contains macros to be
+# used in source code::
+#
+#    write_compiler_detection_header(
+#              FILE <file>
+#              PREFIX <prefix>
+#              [VERSION <version>]
+#              [PROLOG <prolog>]
+#              [EPILOG <epilog>]
+#              COMPILERS <compiler> [...]
+#              FEATURES <feature> [...]
+#    )
+#
+# The ``write_compiler_detection_header`` function generates the
+# file ``<file>`` with macros which all have the prefix ``<prefix>``.
+#
+# ``VERSION`` may be used to specify a generation compatibility with older
+# CMake versions.  By default, a file is generated with compatibility with
+# the :variable:`CMAKE_MINIMUM_REQUIRED_VERSION`.  Newer CMake versions may
+# generate additional code, and the ``VERSION`` may be used to maintain
+# compatibility in the generated file while allowing the minimum CMake
+# version of the project to be changed indepenendently.
+#
+# ``PROLOG`` may be specified as text content to write at the start of the
+# header. ``EPILOG`` may be specified as text content to write at the end
+# of the header
+#
+# At least one ``<compiler>`` and one ``<feature>`` must be listed.
+#
+# Feature Test Macros
+# ===================
+#
+# For each compiler, a preprocessor test of the compiler version is generated
+# denoting whether the each feature is enabled.  A preprocessor macro
+# matching ``${PREFIX}_COMPILER_${FEATURE_NAME_UPPER}`` is generated to
+# contain the value ``0`` or ``1`` depending on whether the compiler in
+# use supports the feature:
+#
+# .. code-block:: cmake
+#
+#    write_compiler_detection_header(
+#      FILE climbingstats_compiler_detection.h
+#      PREFIX ClimbingStats
+#      COMPILERS GNU Clang MSVC
+#      FEATURES cxx_variadic_templates
+#    )
+#
+# .. code-block:: c++
+#
+#    #if ClimbingStats_COMPILER_CXX_VARIADIC_TEMPLATES
+#    template<typename... T>
+#    void someInterface(T t...) { /* ... */ }
+#    #else
+#    // Compatibility versions
+#    template<typename T1>
+#    void someInterface(T1 t1) { /* ... */ }
+#    template<typename T1, typename T2>
+#    void someInterface(T1 t1, T2 t2) { /* ... */ }
+#    template<typename T1, typename T2, typename T3>
+#    void someInterface(T1 t1, T2 t2, T3 t3) { /* ... */ }
+#    #endif
+#
+# Symbol Macros
+# =============
+#
+# Some additional symbol-defines are created for particular features for
+# use as symbols which may be conditionally defined empty. The macros for
+# such symbol defines match ``${PREFIX}_DECL_${FEATURE_NAME_UPPER}``:
+#
+# .. code-block:: c++
+#
+#    class MyClass ClimbingStats_DECL_CXX_FINAL
+#    {
+#        ClimbingStats_DECL_CXX_CONSTEXPR int someInterface() { return 42; }
+#    };
+#
+# The ``ClimbingStats_DECL_CXX_FINAL`` macro will expand to ``final`` if the
+# compiler (and its flags) support the ``cxx_final`` feature, and the
+# ``ClimbingStats_DECL_CXX_CONSTEXPR`` macro will expand to ``constexpr``
+# if ``cxx_constexpr`` is supported.
+#
+# The following features generate corresponding symbol defines:
+#
+# ========================== ===============
+#         Feature                 Symbol
+# ========================== ===============
+# ``cxx_constexpr``           ``constexpr``
+# ``cxx_deleted_functions``   ``= delete``
+# ``cxx_extern_templates``    ``extern``
+# ``cxx_final``               ``final``
+# ``cxx_noexcept``            ``noexcept``
+# ``cxx_override``            ``override``
+# ========================== ===============
+#
+# Compatibility Implemetation Macros
+# ==================================
+#
+# Some features are suitable for wrapping in a macro with a backward
+# compatibility implementation if the compiler does not support the feature.
+#
+# When the ``cxx_static_assert`` feature is not provided by the compiler,
+# a compatibility implementation is available via the
+# ``${PREFIX}_STATIC_ASSERT`` and ``${PREFIX}_STATIC_ASSERT_MSG``
+# function-like macros. The macros expand to ``static_assert`` where that
+# compiler feature is available, and to a compatibility implementation
+# otherwise.
+#
+# ========================== ================================
+#         Feature                         Define
+# ========================== ================================
+# ``cxx_alignas``              ``@PREFIX at _ALIGNAS``
+# ``cxx_alignof``              ``@PREFIX at _ALIGNOF``
+# ``cxx_deleted_functions``    ``@PREFIX at _DISABLE_COPY``
+# ``cxx_noexcept``             ``@PREFIX at _NOEXCEPT_EXPR(X)``
+# ``cxx_nullptr``              ``@PREFIX at _NULLPTR``
+# ``cxx_static_assert``        ``@PREFIX at _STATIC_ASSERT``
+# ``cxx_static_assert``        ``@PREFIX at _STATIC_ASSERT_MSG``
+# ========================== ================================
+
+
+#=============================================================================
+# Copyright 2013 Stephen Kelly <steveire at gmail.com>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
+
+function(_load_compiler_variables CompilerId lang)
+  include("${CMAKE_ROOT}/Modules/Compiler/${CompilerId}-${lang}-FeatureTests.cmake" OPTIONAL)
+  foreach(feature ${ARGN})
+    set(_cmake_feature_test_${CompilerId}_${feature} ${_cmake_feature_test_${feature}} PARENT_SCOPE)
+    if (_cmake_symbol_alternative_${feature})
+      set(_cmake_symbol_alternative_${CompilerId}_${feature} ${_cmake_symbol_alternative_${feature}} PARENT_SCOPE)
+      set(_cmake_symbol_alternative_test_${CompilerId}_${feature} ${_cmake_symbol_alternative_test_${feature}} PARENT_SCOPE)
+    endif()
+  endforeach()
+endfunction()
+
+function(write_compiler_detection_header
+    file_keyword file_arg
+    prefix_keyword prefix_arg
+    )
+  if (NOT file_keyword STREQUAL FILE)
+    message(FATAL_ERROR "Wrong parameters for function.")
+  endif()
+  if (NOT prefix_keyword STREQUAL PREFIX)
+    message(FATAL_ERROR "Wrong parameters for function.")
+  endif()
+  set(options)
+  set(oneValueArgs VERSION EPILOG PROLOG)
+  set(multiValueArgs COMPILERS FEATURES)
+  cmake_parse_arguments(_WCD "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+  if(NOT _WCD_COMPILERS OR NOT _WCD_FEATURES)
+    message(FATAL_ERROR "Invalid arguments.")
+  endif()
+
+  if(_WCD_UNPARSED_ARGUMENTS)
+    message(FATAL_ERROR "Unparsed arguments: ${_WCD_UNPARSED_ARGUMENTS}")
+  endif()
+
+  if(NOT _WCD_VERSION)
+    set(_WCD_VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION})
+  endif()
+  if (_WCD_VERSION VERSION_LESS 3.1.0) # Version which introduced this function
+    message(FATAL_ERROR "VERSION parameter too low.")
+  endif()
+  cmake_policy(GET CMP0025 setting_25)
+  if(NOT setting_25 STREQUAL NEW)
+    message(FATAL_ERROR "Policy CMP0025 must be NEW to use this function.")
+  endif()
+  cmake_policy(GET CMP0046 setting_46)
+  if(NOT setting_46 STREQUAL NEW)
+    message(FATAL_ERROR "Policy CMP0046 must be NEW to use this function.")
+  endif()
+
+  set(compilers
+    GNU
+  )
+  foreach(_comp ${_WCD_COMPILERS})
+    list(FIND compilers ${_comp} idx)
+    if (idx EQUAL -1)
+      message(FATAL_ERROR "Unsupported compiler ${_comp}.")
+    endif()
+  endforeach()
+
+  file(WRITE ${file_arg} "
+// This is a generated file. Do not edit!
+
+#ifndef ${prefix_arg}_COMPILER_DETECTION_H
+#define ${prefix_arg}_COMPILER_DETECTION_H
+")
+
+  if (_WCD_PROLOG)
+    file(APPEND "${file_arg}" "\n${_WCD_PROLOG}\n")
+  endif()
+
+  foreach(_lang CXX)
+
+    if(_lang STREQUAL CXX)
+      file(APPEND "${file_arg}" "\n#ifdef __cplusplus\n")
+    endif()
+
+    find_file(hdr_in CMakeCXXCompilerId.h.in PATHS ${CMAKE_ROOT}/Modules ${CMAKE_MODULE_PATH} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+    file(READ ${hdr_in} ID_CONTENT_IN)
+
+    set(PREFIX_OLD ${PREFIX})
+    set(PREFIX ${prefix_arg}_)
+    string(CONFIGURE "${ID_CONTENT_IN}" ID_CONTENT_OUT @ONLY)
+    set(PREFIX ${PREFIX_OLD})
+
+    file(APPEND "${file_arg}" "${ID_CONTENT_OUT}\n")
+    file(APPEND "${file_arg}" "#define ${prefix_arg}_COMPILER_IS(ID) defined(${prefix_arg}_COMPILER_IS_##ID)\n")
+
+    set(pp_if "if")
+    foreach(compiler ${_WCD_COMPILERS})
+      _load_compiler_variables(${compiler} ${_lang} ${_WCD_FEATURES})
+      file(APPEND "${file_arg}" "\n#  ${pp_if} ${prefix_arg}_COMPILER_IS(${compiler})\n")
+      set(pp_if "elif")
+      foreach(feature ${_WCD_FEATURES})
+        list(FIND CMAKE_${_lang}_KNOWN_FEATURES ${feature} idx)
+        if (NOT idx EQUAL -1)
+          set(_define_item "\n#    define ${prefix_arg}_${CMAKE_PP_NAME_${feature}} 0\n")
+          if (_cmake_feature_test_${compiler}_${feature} STREQUAL "1")
+            set(_define_item "\n#    define ${prefix_arg}_${CMAKE_PP_NAME_${feature}} 1\n")
+          elseif (_cmake_feature_test_${compiler}_${feature})
+            set(_define_item "\n#      define ${prefix_arg}_${CMAKE_PP_NAME_${feature}} 0\n")
+            set(_define_item "\n#    if ${_cmake_feature_test_${compiler}_${feature}}\n#      define ${prefix_arg}_${CMAKE_PP_NAME_${feature}} 1\n#    else${_define_item}#    endif\n")
+          endif()
+          file(APPEND "${file_arg}" "${_define_item}")
+        endif()
+      endforeach()
+    endforeach()
+    if(pp_if STREQUAL "elif")
+      file(APPEND "${file_arg}" "\n#  else\n")
+      foreach(feature ${_WCD_FEATURES})
+        file(APPEND "${file_arg}" "\n#    define ${prefix_arg}_${CMAKE_PP_NAME_${feature}} 0\n")
+      endforeach()
+      file(APPEND "${file_arg}" "\n#  endif\n\n")
+    endif()
+    foreach(feature ${_WCD_FEATURES})
+      set(def_value ${CMAKE_SYMBOL_DEFINE_${feature}})
+      if (def_value)
+        set(def_name ${prefix_arg}_${CMAKE_PP_DECL_${feature}})
+        file(APPEND "${file_arg}" "
+#  if ${prefix_arg}_${CMAKE_PP_NAME_${feature}}
+#    define ${def_name} ${def_value}
+#  else
+#    define ${def_name}
+#  endif
+\n")
+      endif()
+    endforeach()
+    foreach(feature ${_WCD_FEATURES})
+      if (feature STREQUAL cxx_static_assert)
+        set(def_name ${prefix_arg}_${CMAKE_PP_NAME_cxx_static_assert})
+        set(def_value "${prefix_arg}_STATIC_ASSERT(X)")
+        set(def_value_msg "${prefix_arg}_STATIC_ASSERT_MSG(X, MSG)")
+        set(static_assert_struct "template<bool> struct ${prefix_arg}StaticAssert;\ntemplate<> struct ${prefix_arg}StaticAssert<true>{};\n")
+        set(def_standard "#    define ${def_value} static_assert(X, #X)\n#    define ${def_value_msg} static_assert(X, MSG)")
+        set(def_alternative "${static_assert_struct}#    define ${def_value} sizeof(CMakeStaticAssert<X>)\n#    define ${def_value_msg} sizeof(CMakeStaticAssert<X>)")
+        file(APPEND "${file_arg}" "#  if ${def_name}\n${def_standard}\n#  else\n${def_alternative}\n#  endif\n\n")
+      endif()
+      if (feature STREQUAL cxx_alignas)
+        set(def_name ${prefix_arg}_${CMAKE_PP_NAME_${feature}})
+        set(def_value "${prefix_arg}_ALIGNAS(X)")
+        file(APPEND "${file_arg}" "
+#  if ${def_name}
+#    define ${def_value} alignas(X)
+#  elif ${prefix_arg}_COMPILER_IS(GNU)
+#    define ${def_value} __attribute__ ((__aligned__(X)))
+#  else
+#    define ${def_value}
+#  endif
+\n")
+      endif()
+      if (feature STREQUAL cxx_alignof)
+        set(def_name ${prefix_arg}_${CMAKE_PP_NAME_${feature}})
+        set(def_value "${prefix_arg}_ALIGNOF(X)")
+        file(APPEND "${file_arg}" "
+#  if ${def_name}
+#    define ${def_value} alignof(X)
+#  elif ${prefix_arg}_COMPILER_IS(GNU)
+#    define ${def_value} __alignof__(X)
+#  endif
+\n")
+      endif()
+      if (feature STREQUAL cxx_deleted_functions)
+        set(def_name ${prefix_arg}_${CMAKE_PP_NAME_${feature}})
+        set(def_value "${prefix_arg}_DELETED_FUNCTION")
+        file(APPEND "${file_arg}" "
+#  if ${def_name}
+#    define ${def_value} = delete
+#  else
+#    define ${def_value}
+#  endif
+
+#  define ${prefix_arg}_DISABLE_COPY(X) \\
+private: \\
+     X(X const&) ${prefix_arg}_DELETED_FUNCTION; \\
+     X& operator=(X const&) ${prefix_arg}_DELETED_FUNCTION;
+\n")
+      endif()
+      if (feature STREQUAL cxx_extern_templates)
+        set(def_name ${prefix_arg}_${CMAKE_PP_NAME_${feature}})
+        set(def_value "${prefix_arg}_EXTERN_TEMPLATE")
+        file(APPEND "${file_arg}" "
+#  if ${def_name}
+#    define ${def_value} extern
+#  else
+#    define ${def_value}
+#  endif
+\n")
+      endif()
+      if (feature STREQUAL cxx_noexcept)
+        set(def_name ${prefix_arg}_${CMAKE_PP_NAME_${feature}})
+        set(def_value "${prefix_arg}_NOEXCEPT")
+        file(APPEND "${file_arg}" "
+#  if ${def_name}
+#    define ${def_value} noexcept
+#    define ${def_value}_EXPR(X) noexcept(X)
+#  else
+#    define ${def_value}
+#    define ${def_value}_EXPR(X)
+#  endif
+\n")
+      endif()
+      if (feature STREQUAL cxx_nullptr)
+        set(def_name ${prefix_arg}_${CMAKE_PP_NAME_${feature}})
+        set(def_value "${prefix_arg}_NULLPTR")
+        file(APPEND "${file_arg}" "
+#  if ${def_name}
+#    define ${def_value} nullptr
+#  else
+#    define ${def_value} (void*)0
+#  endif
+\n")
+      endif()
+    endforeach()
+    if(_lang STREQUAL CXX)
+      file(APPEND "${file_arg}" "#endif\n")
+    endif()
+
+  endforeach()
+
+  if (_WCD_EPILOG)
+    file(APPEND "${file_arg}" "\n${_WCD_EPILOG}\n")
+  endif()
+
+  file(APPEND ${file_arg} "\n#endif\n")
+endfunction()
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 6ec40fb..a0c99f6 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -2504,6 +2504,33 @@ const char* cmMakefile::GetDefinition(const std::string& name) const
     return FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT) + 1;
 #undef STRING_LIST_ELEMENT
     }
+#define PP_FEATURE_NAME(F) \
+  if (name == "CMAKE_PP_NAME_" #F) \
+    { \
+    static std::string val = ("COMPILER_" + cmSystemTools::UpperCase(#F)); \
+    return val.c_str(); \
+    }
+  FOR_EACH_CXX_FEATURE(PP_FEATURE_NAME)
+#undef PP_FEATURE_NAME
+
+#define FOR_EACH_CXX_DECL_FEATURE(F) \
+  F(final) \
+  F(override) \
+  F(constexpr)
+
+#define PP_DECL_NAME(F) \
+  if (name == "CMAKE_PP_DECL_cxx_" #F) \
+    { \
+    static std::string val = ("DECL_CXX_" + cmSystemTools::UpperCase(#F)); \
+    return val.c_str(); \
+    } \
+  if (name == "CMAKE_SYMBOL_DEFINE_cxx_" #F) \
+    { \
+    return #F; \
+    }
+  FOR_EACH_CXX_DECL_FEATURE(PP_DECL_NAME)
+#undef PP_DECL_NAME
+
   const char* def = this->Internal->VarStack.top().Get(name);
   if(!def)
     {
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 12bd3b2..0be6ed2 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -413,6 +413,9 @@ if(BUILD_TESTING)
   ADD_TEST_MACRO(Module.GenerateExportHeader GenerateExportHeader)
   ADD_TEST_MACRO(Module.FindDependency FindDependency)
 
+  if (CMAKE_CXX_COMPILER_ID STREQUAL GNU)
+    ADD_TEST_MACRO(Module.WriteCompilerDetectionHeader WriteCompilerDetectionHeader)
+  endif()
   if (APPLE OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
     include(CheckCXXCompilerFlag)
     check_cxx_compiler_flag(-fPIE run_pic_test)
diff --git a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
new file mode 100644
index 0000000..eda5098
--- /dev/null
+++ b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
@@ -0,0 +1,61 @@
+cmake_minimum_required(VERSION 3.0.0)
+project(WriteCompilerDetectionHeader)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+  FILE "${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection.h"
+  PREFIX TEST
+  COMPILERS GNU
+  VERSION 3.1
+  PROLOG "// something"
+  EPILOG "// more"
+  FEATURES
+    ${CMAKE_CXX_KNOWN_FEATURES}
+)
+
+macro(set_defines target true_defs false_defs)
+  set(defines)
+  foreach(def ${true_defs})
+    list(APPEND defines ${def}=1)
+  endforeach()
+  foreach(def ${false_defs})
+    list(APPEND defines ${def}=0)
+  endforeach()
+  target_compile_definitions(${target}
+    PRIVATE
+      ${defines}
+  )
+endmacro()
+
+if (CMAKE_CXX_COMPILER_ID STREQUAL GNU)
+  # False for C++98 mode.
+  list(APPEND false_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS)
+  list(APPEND false_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES)
+endif()
+
+add_executable(WriteCompilerDetectionHeader main.cpp)
+set_property(TARGET WriteCompilerDetectionHeader PROPERTY CXX_STANDARD 98)
+set_defines(WriteCompilerDetectionHeader "${true_defs}" "${false_defs}")
+
+if(MSVC)
+  return() # MSVC has only one mode.
+endif()
+
+# Since GNU 4.7
+if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_delegating_constructors;")
+  list(APPEND true_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS)
+  list(REMOVE_ITEM false_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS)
+endif()
+
+# Since GNU 4.4
+if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_variadic_templates;")
+  list(APPEND true_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES)
+  list(REMOVE_ITEM false_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES)
+endif()
+
+add_executable(WriteCompilerDetectionHeader_11 main.cpp)
+set_property(TARGET WriteCompilerDetectionHeader_11 PROPERTY CXX_STANDARD 11)
+set_defines(WriteCompilerDetectionHeader_11 "${true_defs}" "${false_defs}")
diff --git a/Tests/Module/WriteCompilerDetectionHeader/main.cpp b/Tests/Module/WriteCompilerDetectionHeader/main.cpp
new file mode 100644
index 0000000..628d26b
--- /dev/null
+++ b/Tests/Module/WriteCompilerDetectionHeader/main.cpp
@@ -0,0 +1,19 @@
+
+#include "test_compiler_detection.h"
+
+#define JOIN_IMPL(A, B) A ## B
+#define JOIN(A, B) JOIN_IMPL(A, B)
+#define CHECK(FEATURE) (JOIN(TEST_COMPILER_, FEATURE) == JOIN(EXPECTED_COMPILER_, FEATURE))
+
+#if !CHECK(CXX_DELEGATING_CONSTRUCTORS)
+#error cxx_delegating_constructors expected availability did not match.
+#endif
+
+#if !CHECK(CXX_VARIADIC_TEMPLATES)
+#error cxx_variadic_templates expected availability did not match.
+#endif
+
+int main(int argc, char **argv)
+{
+  return 0;
+}

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5b34ccc5adb9f905e64bb8d8a01288b9a8a37d1f
commit 5b34ccc5adb9f905e64bb8d8a01288b9a8a37d1f
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Thu Apr 17 11:50:43 2014 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Thu Apr 17 15:09:16 2014 +0200

    Project: Add another define for determined compiler ids.
    
    This one can be processed by the preprocessor.

diff --git a/Modules/CMakeCXXCompilerId.h.in b/Modules/CMakeCXXCompilerId.h.in
index b7258b9..b02f29f 100644
--- a/Modules/CMakeCXXCompilerId.h.in
+++ b/Modules/CMakeCXXCompilerId.h.in
@@ -4,12 +4,14 @@
 
 #if defined(__COMO__)
 # define @PREFIX at COMPILER_ID "Comeau"
+# define @PREFIX at COMPILER_IS_Comeau
   /* __COMO_VERSION__ = VRR */
 # define @PREFIX at COMPILER_VERSION_MAJOR DEC(__COMO_VERSION__ / 100)
 # define @PREFIX at COMPILER_VERSION_MINOR DEC(__COMO_VERSION__ % 100)
 
 #elif defined(__INTEL_COMPILER) || defined(__ICC)
 # define @PREFIX at COMPILER_ID "Intel"
+# define @PREFIX at COMPILER_IS_Intel
   /* __INTEL_COMPILER = VRP */
 # define @PREFIX at COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100)
 # define @PREFIX at COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10)
@@ -24,6 +26,7 @@
 # endif
 # if defined(_MSC_VER)
 #  define @PREFIX at SIMULATE_ID "MSVC"
+#  define @PREFIX at SIMULATE_MSVC
    /* _MSC_VER = VVRR */
 #  define @PREFIX at SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
 #  define @PREFIX at SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
@@ -31,6 +34,7 @@
 
 #elif defined(__PATHCC__)
 # define @PREFIX at COMPILER_ID "PathScale"
+# define @PREFIX at COMPILER_IS_PathScale
 # define @PREFIX at COMPILER_VERSION_MAJOR DEC(__PATHCC__)
 # define @PREFIX at COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__)
 # if defined(__PATHCC_PATCHLEVEL__)
@@ -40,15 +44,18 @@
 #elif defined(__clang__)
 # if defined(__apple_build_version__)
 #  define @PREFIX at COMPILER_ID "AppleClang"
+#  define @PREFIX at COMPILER_IS_AppleClang
 #  define @PREFIX at COMPILER_VERSION_TWEAK DEC(__apple_build_version__)
 # else
 #  define @PREFIX at COMPILER_ID "Clang"
+#  define @PREFIX at COMPILER_IS_Clang
 # endif
 # define @PREFIX at COMPILER_VERSION_MAJOR DEC(__clang_major__)
 # define @PREFIX at COMPILER_VERSION_MINOR DEC(__clang_minor__)
 # define @PREFIX at COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
 # if defined(_MSC_VER)
 #  define @PREFIX at SIMULATE_ID "MSVC"
+#  define @PREFIX at SIMULATE_MSVC
    /* _MSC_VER = VVRR */
 #  define @PREFIX at SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
 #  define @PREFIX at SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
@@ -56,12 +63,14 @@
 
 #elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__)
 # define @PREFIX at COMPILER_ID "Embarcadero"
+# define @PREFIX at COMPILER_IS_Embarcadero
 # define @PREFIX at COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF)
 # define @PREFIX at COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF)
 # define @PREFIX at COMPILER_VERSION_PATCH HEX(__CODEGEARC_VERSION__     & 0xFFFF)
 
 #elif defined(__BORLANDC__)
 # define @PREFIX at COMPILER_ID "Borland"
+# define @PREFIX at COMPILER_IS_Borland
   /* __BORLANDC__ = 0xVRR */
 # define @PREFIX at COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8)
 # define @PREFIX at COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF)
@@ -69,10 +78,12 @@
 #elif defined(__WATCOMC__)
 # if __WATCOMC__ < 1200
 #  define @PREFIX at COMPILER_ID "Watcom"
+#  define @PREFIX at COMPILER_IS_Watcom
    /* __WATCOMC__ = VVRP */
 #  define @PREFIX at COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100)
 # else
 #  define @PREFIX at COMPILER_ID "OpenWatcom"
+#  define @PREFIX at COMPILER_IS_OpenWatcom
    /* __WATCOMC__ = VVRP + 1100 */
 #  define @PREFIX at COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100)
 # endif
@@ -83,6 +94,7 @@
 
 #elif defined(__SUNPRO_CC)
 # define @PREFIX at COMPILER_ID "SunPro"
+# define @PREFIX at COMPILER_IS_SunPro
 # if __SUNPRO_CC >= 0x5100
    /* __SUNPRO_CC = 0xVRRP */
 #  define @PREFIX at COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>12)
@@ -97,6 +109,7 @@
 
 #elif defined(__HP_aCC)
 # define @PREFIX at COMPILER_ID "HP"
+# define @PREFIX at COMPILER_IS_HP
   /* __HP_aCC = VVRRPP */
 # define @PREFIX at COMPILER_VERSION_MAJOR DEC(__HP_aCC/10000)
 # define @PREFIX at COMPILER_VERSION_MINOR DEC(__HP_aCC/100 % 100)
@@ -104,6 +117,7 @@
 
 #elif defined(__DECCXX)
 # define @PREFIX at COMPILER_ID "Compaq"
+# define @PREFIX at COMPILER_IS_Compaq
   /* __DECCXX_VER = VVRRTPPPP */
 # define @PREFIX at COMPILER_VERSION_MAJOR DEC(__DECCXX_VER/10000000)
 # define @PREFIX at COMPILER_VERSION_MINOR DEC(__DECCXX_VER/100000  % 100)
@@ -112,11 +126,14 @@
 #elif defined(__IBMCPP__)
 # if defined(__COMPILER_VER__)
 #  define @PREFIX at COMPILER_ID "zOS"
+#  define @PREFIX at COMPILER_IS_zOS
 # else
 #  if __IBMCPP__ >= 800
 #   define @PREFIX at COMPILER_ID "XL"
+#   define @PREFIX at COMPILER_IS_XL
 #  else
 #   define @PREFIX at COMPILER_ID "VisualAge"
+#   define @PREFIX at COMPILER_IS_VisualAge
 #  endif
    /* __IBMCPP__ = VRP */
 #  define @PREFIX at COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100)
@@ -126,6 +143,7 @@
 
 #elif defined(__PGI)
 # define @PREFIX at COMPILER_ID "PGI"
+# define @PREFIX at COMPILER_IS_PGI
 # define @PREFIX at COMPILER_VERSION_MAJOR DEC(__PGIC__)
 # define @PREFIX at COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__)
 # if defined(__PGIC_PATCHLEVEL__)
@@ -134,11 +152,13 @@
 
 #elif defined(_CRAYC)
 # define @PREFIX at COMPILER_ID "Cray"
+# define @PREFIX at COMPILER_IS_Cray
 # define @PREFIX at COMPILER_VERSION_MAJOR DEC(_RELEASE)
 # define @PREFIX at COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR)
 
 #elif defined(__TI_COMPILER_VERSION__)
 # define @PREFIX at COMPILER_ID "TI"
+# define @PREFIX at COMPILER_IS_TI
   /* __TI_COMPILER_VERSION__ = VVVRRRPPP */
 # define @PREFIX at COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000)
 # define @PREFIX at COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000   % 1000)
@@ -146,9 +166,11 @@
 
 #elif defined(__SCO_VERSION__)
 # define @PREFIX at COMPILER_ID "SCO"
+# define @PREFIX at COMPILER_IS_SCO
 
 #elif defined(__GNUC__)
 # define @PREFIX at COMPILER_ID "GNU"
+# define @PREFIX at COMPILER_IS_GNU
 # define @PREFIX at COMPILER_VERSION_MAJOR DEC(__GNUC__)
 # define @PREFIX at COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__)
 # if defined(__GNUC_PATCHLEVEL__)
@@ -157,6 +179,7 @@
 
 #elif defined(_MSC_VER)
 # define @PREFIX at COMPILER_ID "MSVC"
+# define @PREFIX at COMPILER_IS_MSVC
   /* _MSC_VER = VVRR */
 # define @PREFIX at COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100)
 # define @PREFIX at COMPILER_VERSION_MINOR DEC(_MSC_VER % 100)
@@ -176,6 +199,7 @@
 /* Analog VisualDSP++ >= 4.5.6 */
 #elif defined(__VISUALDSPVERSION__)
 # define @PREFIX at COMPILER_ID "ADSP"
+# define @PREFIX at COMPILER_IS_ADSP
   /* __VISUALDSPVERSION__ = 0xVVRRPP00 */
 # define @PREFIX at COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24)
 # define @PREFIX at COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF)
@@ -184,14 +208,17 @@
 /* Analog VisualDSP++ < 4.5.6 */
 #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
 # define @PREFIX at COMPILER_ID "ADSP"
+# define @PREFIX at COMPILER_IS_ADSP
 
 /* IAR Systems compiler for embedded systems.
    http://www.iar.com */
 #elif defined(__IAR_SYSTEMS_ICC__ ) || defined(__IAR_SYSTEMS_ICC)
 # define @PREFIX at COMPILER_ID "IAR"
+# define @PREFIX at COMPILER_IS_IAR
 
 #elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION)
 # define @PREFIX at COMPILER_ID "MIPSpro"
+# define @PREFIX at COMPILER_IS_MIPSpro
 # if defined(_SGI_COMPILER_VERSION)
   /* _SGI_COMPILER_VERSION = VRP */
 #  define @PREFIX at COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100)
@@ -209,9 +236,11 @@
    it is the native compiler.  */
 #elif defined(__sgi)
 # define @PREFIX at COMPILER_ID "MIPSpro"
+# define @PREFIX at COMPILER_IS_MIPSpro
 
 #elif defined(__hpux) || defined(__hpua)
 # define @PREFIX at COMPILER_ID "HP"
+# define @PREFIX at COMPILER_IS_HP
 
 #else /* unknown compiler */
 # define @PREFIX at COMPILER_ID ""

-----------------------------------------------------------------------

Summary of changes:


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list