WCDH: Add feature portability for thread_local.

AppleClang does not support the cxx_thread_local feature, even
though it is based on a Clang version which does support the
feature.

 http://stackoverflow.com/a/23850891/2428389

A possible reason for that is that thread_local might be used as
a variable in existing Apple SDK headers.

Extend the WriteCompilerDetectionHeader module to generate a define
for that feature with portability fallbacks.  For the avoidance of
making it easy to write code which looks correct but which has odd
runtime behavior, don't set the define symbol at all if no
equivalent keyword is known.
This commit is contained in:
Stephen Kelly 2015-01-01 17:56:01 +01:00
parent ec31926d24
commit 998e9c1094
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,7 @@
WriteCompilerDetectionHeader thread_local portability
-----------------------------------------------------
* The :module:`WriteCompilerDetectionHeader` module learned to
create a define for portability of the cxx_thread_local feature. The define
expands to either the C++11 ``thread_local`` keyword, or a
pre-standardization compiler-specific equivalent, as appropriate.

View File

@ -194,6 +194,7 @@
# ``cxx_static_assert`` ``<PREFIX>_STATIC_ASSERT_MSG`` ``static_assert``
# ``cxx_attribute_deprecated`` ``<PREFIX>_DEPRECATED`` ``[[deprecated]]``
# ``cxx_attribute_deprecated`` ``<PREFIX>_DEPRECATED_MSG`` ``[[deprecated]]``
# ``cxx_thread_local`` ``<PREFIX>_THREAD_LOCAL`` ``thread_local``
# ============================= ================================ =====================
#
# A use-case which arises with such deprecation macros is the deprecation
@ -571,6 +572,20 @@ function(write_compiler_detection_header
# else
# define ${def_value} static_cast<void*>(0)
# endif
\n")
endif()
if (feature STREQUAL cxx_thread_local)
set(def_value "${prefix_arg}_THREAD_LOCAL")
set(file_content "${file_content}
# if ${def_name}
# define ${def_value} thread_local
# elif ${prefix_arg}_COMPILER_IS_GNU || ${prefix_arg}_COMPILER_IS_Clang || ${prefix_arg}_COMPILER_IS_AppleClang
# define ${def_value} __thread
# elif ${prefix_arg}_COMPILER_IS_MSVC
# define ${def_value} __declspec(thread)
# else
// ${def_value} not defined for this configuration.
# endif
\n")
endif()
if (feature STREQUAL cxx_attribute_deprecated)