Skip to content

Commit fd4f6da

Browse files
mikeferompenick
authored andcommitted
CPP-882 - Correct pthread compiler flag for older CMake versions (#11)
1 parent 7787de4 commit fd4f6da

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cmake/modules/CppDriver.cmake

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

428-
if (LIBUV_VERSION VERSION_LESS "1.0")
428+
if(LIBUV_VERSION VERSION_LESS "1.0")
429429
message(FATAL_ERROR "Libuv version ${LIBUV_VERSION} is not "
430430
" supported. Please updgrade to libuv version 1.0 or greater in order to "
431431
"utilize the driver.")
432432
endif()
433433

434-
if (LIBUV_VERSION VERSION_LESS "1.6")
434+
if(LIBUV_VERSION VERSION_LESS "1.6")
435435
message(WARNING "Libuv version ${LIBUV_VERSION} does not support custom "
436436
"memory allocators (version 1.6 or greater required)")
437437
endif()
@@ -441,10 +441,16 @@ macro(CassUseLibuv)
441441
set(CASS_LIBS ${CASS_LIBS} ${LIBUV_LIBRARIES})
442442

443443
# libuv and gtests require thread library
444-
set (THREADS_PREFER_PTHREAD_FLAG 1)
444+
set(CMAKE_THREAD_PREFER_PTHREAD 1)
445+
set(THREADS_PREFER_PTHREAD_FLAG 1)
445446
find_package(Threads REQUIRED)
446447
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
447448
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
449+
if(NOT WIN32 AND ${CMAKE_VERSION} VERSION_LESS "3.1.0")
450+
# FindThreads in CMake versions < v3.1.0 do not have the THREADS_PREFER_PTHREAD_FLAG to prefer -pthread
451+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
452+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
453+
endif()
448454
endmacro()
449455

450456
#------------------------

0 commit comments

Comments
 (0)