Skip to content

Commit 06f94a7

Browse files
authored
better error message when thread_local is not supported (pytorch#2092)
1 parent 027264c commit 06f94a7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

torch/lib/THD/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ FUNCTION(EXCLUDE_DIR list_name dir_name)
1818
ENDFUNCTION()
1919

2020
################################################################################
21+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
22+
23+
INCLUDE(CheckCXXSourceCompiles)
24+
25+
CHECK_CXX_SOURCE_COMPILES("
26+
#include <thread>
27+
28+
thread_local int foo=1;
29+
30+
int main() {
31+
return 0;
32+
}" HAS_THREAD_LOCAL)
33+
34+
IF(NOT HAS_THREAD_LOCAL)
35+
MESSAGE(FATAL_ERROR "thread_local not supported. THD requires a compiler"
36+
" that supports thread_local. Please upgrade your "
37+
"compiler. If you are on OSX, upgrade to "
38+
"XCode 8 or newer.")
39+
ENDIF(NOT HAS_THREAD_LOCAL)
2140

2241
FIND_PACKAGE(MPI)
2342

@@ -101,7 +120,6 @@ EXCLUDE_DIR(all_cpp ".*/generic/.*\\.cpp$")
101120
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
102121

103122
ADD_LIBRARY(THD SHARED ${all_cpp})
104-
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
105123

106124
IF(THD_SO_VERSION)
107125
MESSAGE(STATUS "THD_SO_VERSION: ${THD_SO_VERSION}")

0 commit comments

Comments
 (0)