1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#-------------------------------------------------------------------------------
# GraphBLAS/cmake_modules/SuiteSparse__thread.cmake
#-------------------------------------------------------------------------------
# Copyright (c) 2017-2025, Timothy A. Davis. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#-------------------------------------------------------------------------------
# determine if the __thread keyword is available, which is an extension by
# gcc but supported by many compilers, to indicate thread-local-storage.
include ( CheckCSourceCompiles )
set ( thread_src
" #include <stdio.h>
__thread int x = 1 ;
int main (void)
{
x = 0 ;
return (x) ;
}
" )
set ( declspec_thread_src
" #include <stdio.h>
__declspec ( thread ) int x = 1 ;
int main (void)
{
x = 0 ;
return (x) ;
}
" )
set ( thread_local_src
" #include <stdio.h>
#include <threads.h>
_Thread_local int x = 1 ;
int main (void)
{
x = 0 ;
return (x) ;
}
" )
check_c_source_compiles ( "${declspec_thread_src}" HAVE_KEYWORD__DECLSPEC_THREAD )
check_c_source_compiles ( "${thread_src}" HAVE_KEYWORD__THREAD )
check_c_source_compiles ( "${thread_local_src}" HAVE_KEYWORD__THREAD_LOCAL )
if ( HAVE_KEYWORD__DECLSPEC_THREAD )
add_compile_definitions ( HAVE_KEYWORD__DECLSPEC_THREAD )
message ( STATUS "__declspec(thread) keyword: available" )
else ( )
message ( STATUS "__declspec(thread) keyword: not available" )
endif ( )
if ( HAVE_KEYWORD__THREAD )
add_compile_definitions ( HAVE_KEYWORD__THREAD )
message ( STATUS "__thread keyword: available" )
else ( )
message ( STATUS "__thread keyword: not available" )
endif ( )
if ( HAVE_KEYWORD__THREAD_LOCAL )
add_compile_definitions ( HAVE_KEYWORD__THREAD_LOCAL )
message ( STATUS "_Thread_local keyword: available" )
else ( )
message ( STATUS "_Thread_local_thread keyword: not available" )
endif ( )
|