Skip to content

Commit 99839f7

Browse files
mikeferoMichael Penick
authored andcommitted
CPP-882 - Correct pthread compiler flag for older CMake versions (#11)
1 parent ad518b0 commit 99839f7

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

cpp-driver/cmake/modules/CppDriver.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,13 @@ macro(CassUseLibuv)
420420
message(FATAL_ERROR "Unable to Locate libuv: libuv v1.0.0+ is required")
421421
endif()
422422

423-
if (LIBUV_VERSION VERSION_LESS "1.0")
423+
if(LIBUV_VERSION VERSION_LESS "1.0")
424424
message(FATAL_ERROR "Libuv version ${LIBUV_VERSION} is not "
425425
" supported. Please updgrade to libuv version 1.0 or greater in order to "
426426
"utilize the driver.")
427427
endif()
428428

429-
if (LIBUV_VERSION VERSION_LESS "1.6")
429+
if(LIBUV_VERSION VERSION_LESS "1.6")
430430
message(WARNING "Libuv version ${LIBUV_VERSION} does not support custom "
431431
"memory allocators (version 1.6 or greater required)")
432432
endif()
@@ -436,10 +436,16 @@ macro(CassUseLibuv)
436436
set(CASS_LIBS ${CASS_LIBS} ${LIBUV_LIBRARIES})
437437

438438
# libuv and gtests require thread library
439-
set (THREADS_PREFER_PTHREAD_FLAG 1)
439+
set(CMAKE_THREAD_PREFER_PTHREAD 1)
440+
set(THREADS_PREFER_PTHREAD_FLAG 1)
440441
find_package(Threads REQUIRED)
441442
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
442443
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
444+
if(NOT WIN32 AND ${CMAKE_VERSION} VERSION_LESS "3.1.0")
445+
# FindThreads in CMake versions < v3.1.0 do not have the THREADS_PREFER_PTHREAD_FLAG to prefer -pthread
446+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
447+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
448+
endif()
443449
endmacro()
444450

445451
#------------------------

0 commit comments

Comments
 (0)