From 3c6a410c20a6ed11142661dca72279d66699ac54 Mon Sep 17 00:00:00 2001 From: jesperpedersen Date: Wed, 2 Oct 2024 06:16:18 -0400 Subject: [PATCH] Add pthread --- CMakeLists.txt | 7 +++++++ cmake/FindTHREAD.cmake | 23 +++++++++++++++++++++++ src/CMakeLists.txt | 6 ++++++ 3 files changed, 36 insertions(+) create mode 100644 cmake/FindTHREAD.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e7de2f39..e38e1c72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,13 @@ else () message(FATAL_ERROR "rst2man needed") endif() +find_package(THREAD) +if (THREAD_FOUND) + message(STATUS "pthread found") +else () + message(FATAL_ERROR "pthread needed") +endif() + # search for cJSON library # find_package(cJSON) diff --git a/cmake/FindTHREAD.cmake b/cmake/FindTHREAD.cmake new file mode 100644 index 00000000..17c2acc8 --- /dev/null +++ b/cmake/FindTHREAD.cmake @@ -0,0 +1,23 @@ +# +# pthread support +# + +find_path(THREAD_INCLUDE_DIR + NAMES + pthread.h +) +find_library(THREAD_LIBRARY + NAMES + pthread +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(THREAD DEFAULT_MSG + THREAD_LIBRARY THREAD_INCLUDE_DIR) + +if(THREAD_FOUND) + set(THREAD_LIBRARIES ${THREAD_LIBRARY}) + set(THREAD_INCLUDE_DIRS ${THREAD_INCLUDE_DIR}) +endif() + +mark_as_advanced(THREAD_INCLUDE_DIR THREAD_LIBRARY) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d0cea712..655633e4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") ${OPENSSL_INCLUDE_DIR} ${SYSTEMD_INCLUDE_DIRS} ${CJSON_INCLUDE_DIRS} + ${THREAD_INCLUDE_DIRS} ) # @@ -35,6 +36,7 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") ${SYSTEMD_LIBRARIES} ${LIBATOMIC_LIBRARY} ${CJSON_LIBRARIES} + ${THREAD_LIBRARY} ) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") @@ -72,6 +74,7 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") ${LIBEV_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS} ${CJSON_INCLUDE_DIRS} + ${THREAD_INCLUDE_DIRS} ) # @@ -81,6 +84,7 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") ${LIBEV_LIBRARIES} ${OPENSSL_LIBRARIES} ${CJSON_LIBRARIES} + ${THREAD_LIBRARY} ) else() @@ -103,6 +107,7 @@ else() ${LIBEV_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIRS} ${CJSON_INCLUDE_DIRS} + ${THREAD_INCLUDE_DIRS} ) # @@ -112,6 +117,7 @@ else() ${LIBEV_LIBRARIES} ${OPENSSL_LIBRARIES} ${CJSON_LIBRARIES} + ${THREAD_LIBRARY} ) endif()