[cmake-developers] [PATCH] Macro generation for relaxed constexpr

Jean-Michaël Celerier jeanmichael.celerier at gmail.com
Wed Jul 8 11:01:08 EDT 2015


Hello,

At the ned of this mail is a patch that adds generation of a macro for
the relaxed ("c++14") constexpr in WriteCompilerDetectionHeader.

This is intended for compilers that support c++11 constexpr (with
everything on a single return statement) like GCC-4.9 and the upcoming
MSVC, but not extended constexpr which allows for more complete
functions. This way, code bases can reap the benefits of most recent
compilers at no cost.

Best regards
Jean-Michaël Celerier


diff --git a/Modules/WriteCompilerDetectionHeader.cmake
b/Modules/WriteCompilerDetectionHeader.cmake
index a3b73bb..f7af7ec 100644
--- a/Modules/WriteCompilerDetectionHeader.cmake
+++ b/Modules/WriteCompilerDetectionHeader.cmake
@@ -144,6 +144,7 @@
 # ========================== ===================================
=================
 # ``c_restrict``              ``<PREFIX>_RESTRICT``               ``restrict``
 # ``cxx_constexpr``           ``<PREFIX>_CONSTEXPR``              ``constexpr``
+# ``cxx_relaxed_constexpr``   ``<PREFIX>_RELAXED_CONSTEXPR``      ``constexpr``
 # ``cxx_deleted_functions``   ``<PREFIX>_DELETED_FUNCTION``       ``= delete``
 # ``cxx_extern_templates``    ``<PREFIX>_EXTERN_TEMPLATE``        ``extern``
 # ``cxx_final``               ``<PREFIX>_FINAL``                  ``final``
@@ -494,6 +495,16 @@ function(write_compiler_detection_header
 #  endif
 \n")
       endif()
+      if (feature STREQUAL cxx_relaxed_constexpr)
+        set(def_value "${prefix_arg}_RELAXED_CONSTEXPR")
+        set(file_content "${file_content}
+#  if ${def_name}
+#    define ${def_value} constexpr
+#  else
+#    define ${def_value}
+#  endif
+\n")
+      endif()
       if (feature STREQUAL cxx_final)
         set(def_value "${prefix_arg}_FINAL")
         set(file_content "${file_content}


More information about the cmake-developers mailing list