Skip to content

Commit 2067e48

Browse files
committed
check for std::thread during configuration
1 parent 883bc71 commit 2067e48

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ INCLUDE(CheckLibraryExists)
229229
INCLUDE(CheckIncludeFile)
230230
INCLUDE(CheckFunctionExists)
231231
INCLUDE(CheckTypeSize)
232+
INCLUDE(CMakePushCheckState)
233+
INCLUDE(CheckCXXSourceRuns)
232234
INCLUDE(${SCL_CMAKE_DIR}/FindLEX.cmake)
233235
INCLUDE(${SCL_CMAKE_DIR}/FindYACC.cmake)
234236

@@ -250,6 +252,26 @@ CHECK_FUNCTION_EXISTS(getopt HAVE_GETOPT)
250252

251253
CHECK_TYPE_SIZE("ssize_t" SSIZE_T)
252254

255+
set( TEST_STD_THREAD "
256+
#include <iostream>
257+
#include <thread>
258+
void do_work() {
259+
std::cout << \"thread\" << std::endl;
260+
}
261+
int main() {
262+
std::thread t(do_work);
263+
t.join();
264+
}
265+
" )
266+
cmake_push_check_state()
267+
if( UNIX )
268+
set( CMAKE_REQUIRED_FLAGS "-pthread -std=c++0x" )
269+
else( UNIX )
270+
# vars probably need set for MSVC11, embarcadero, etc
271+
endif( UNIX )
272+
CHECK_CXX_SOURCE_RUNS( "${TEST_STD_THREAD}" HAVE_STD_THREAD ) #quotes are *required*!
273+
cmake_pop_check_state()
274+
253275
# Now that all the tests are done, configure the scl_cf.h file:
254276
get_property(CONFIG_H_FILE_CONTENTS GLOBAL PROPERTY SCL_CONFIG_H_CONTENTS)
255277
file(WRITE ${CONFIG_H_FILE} "${CONFIG_H_FILE_CONTENTS}")

include/scl_cf_cmake.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@
2020

2121
#cmakedefine HAVE_SSIZE_T 1
2222

23+
#cmakedefine HAVE_STD_THREAD 1
24+
2325
#endif /* SCL_CF_H */

0 commit comments

Comments
 (0)