Skip to content

Commit 730deab

Browse files
committed
[hbox] 优化CMake下thread_local与_Atomic检测
1 parent 4a860ff commit 730deab

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

hbox/CMakeLists.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,25 @@ include(CheckSourceCompiles)
9191

9292
#thread_local
9393
set(CMAKE_C_STANDARD 11)
94+
if(HAVE_THREADS_H)
9495
check_source_compiles(C [[
9596
#include "threads.h"
96-
thread_local int a=0;
97+
thread_local int a=0;
9798
int main()
9899
{
99100
return 0;
100101
}
101102
]] HAVE_C_THREAD_LOCAL)
102-
103+
else()
104+
check_source_compiles(C [[
105+
#include "stdlib.h"
106+
thread_local int a=0;
107+
int main()
108+
{
109+
return 0;
110+
}
111+
]] HAVE_C_THREAD_LOCAL)
112+
endif()
103113
if(HAVE_C_THREAD_LOCAL)
104114
target_compile_definitions(HBox PUBLIC HAVE_C_THREAD_LOCAL=1)
105115
endif()
@@ -121,6 +131,7 @@ endif()
121131

122132
#_Atomic
123133
set(CMAKE_C_STANDARD 11)
134+
if(HAVE_STDATOMIC_H)
124135
check_source_compiles(C [[
125136
#include "stdatomic.h"
126137
_Atomic int a=0;
@@ -129,6 +140,16 @@ check_source_compiles(C [[
129140
return 0;
130141
}
131142
]] HAVE_C_ATOMIC)
143+
else()
144+
check_source_compiles(C [[
145+
#include "stdlib.h"
146+
_Atomic int a=0;
147+
int main()
148+
{
149+
return 0;
150+
}
151+
]] HAVE_C_ATOMIC)
152+
endif()
132153

133154
if(HAVE_C_ATOMIC)
134155
target_compile_definitions(HBox PUBLIC HAVE_C_ATOMIC=1)

0 commit comments

Comments
 (0)