Skip to content

Commit

Permalink
[C++] Ensure we compile with -pthread flag (apache#9749)
Browse files Browse the repository at this point in the history
### Motivation

After removing some of the Boost runtime libs, CMake is not passing anymore the `-pthread` flag when compiling and linking. While that's ok on most environments, it does break compilation in some cases.

We need to make sure that `-phtread` is always passed, because Asio is using the pthread API directly (not through the c++-11 classes).
  • Loading branch information
merlimat authored Mar 8, 2021
1 parent bf60b4c commit fe10c96
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pulsar-client-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ ENDIF ()

MESSAGE(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})

set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
MESSAGE(STATUS "Threads library: " ${CMAKE_THREAD_LIBS_INIT})

set(Boost_NO_BOOST_CMAKE ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 11)
Expand Down Expand Up @@ -282,13 +286,15 @@ include_directories(

set(COMMON_LIBS
${COMMON_LIBS}
Threads::Threads
${Boost_REGEX_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${CURL_LIBRARIES}
${OPENSSL_LIBRARIES}
${ZLIB_LIBRARIES}
${Protobuf_LITE_LIBRARIES}
${ADDITIONAL_LIBRARIES}
${CMAKE_DL_LIBS}
)

if (MSVC)
Expand All @@ -299,11 +305,7 @@ if (MSVC)
endif()

if (NOT MSVC)
set(COMMON_LIBS
${COMMON_LIBS} -lpthread -lm
dl
pthread
)
set(COMMON_LIBS ${COMMON_LIBS} m)
else()
set(COMMON_LIBS
${COMMON_LIBS}
Expand Down

0 comments on commit fe10c96

Please sign in to comment.