1include(CheckCSourceCompiles) 2 3macro(check_tls_support VAR) 4 if(NOT DEFINED "${VAR}") 5 set(CMAKE_REQUIRED_QUIET 1) 6 7 check_c_source_compiles(" 8 __thread int tls; 9 10 int main(void) { 11 return 0; 12 }" HAVE_GCC_TLS) 13 14 if(HAVE_GCC_TLS) 15 message(STATUS "Thread-local storage: supported (__thread)") 16 set(${VAR} "__thread" CACHE INTERNAL "Thread-local storage support keyword in compiler") 17 else() 18 check_c_source_compiles(" 19 __declspec(thread) int tls; 20 21 int main(void) { 22 return 0; 23 }" HAVE_MSVC_TLS) 24 if(HAVE_MSVC_TLS) 25 message(STATUS "Thread-local storage: supported (__declspec(thread))") 26 set(${VAR} "__declspec(thread)" CACHE INTERNAL "Thread-local storage keyword in compiler") 27 else() 28 message(STATUS "Thread-local storage: not supported") 29 set(${VAR} "" CACHE INTERNAL "Thread-local storage keyword in compiler") 30 endif() 31 endif() 32 set(CMAKE_REQUIRED_QUIET 0) 33 endif() 34endmacro() 35