Skip to content

Commit

Permalink
Add pthread
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperpedersen committed Oct 2, 2024
1 parent 091bdeb commit 3c6a410
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/DaveGamble/cJSON>
find_package(cJSON)
Expand Down
23 changes: 23 additions & 0 deletions cmake/FindTHREAD.cmake
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
${OPENSSL_INCLUDE_DIR}
${SYSTEMD_INCLUDE_DIRS}
${CJSON_INCLUDE_DIRS}
${THREAD_INCLUDE_DIRS}
)

#
Expand All @@ -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")
Expand Down Expand Up @@ -72,6 +74,7 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
${LIBEV_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIRS}
${CJSON_INCLUDE_DIRS}
${THREAD_INCLUDE_DIRS}
)

#
Expand All @@ -81,6 +84,7 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
${LIBEV_LIBRARIES}
${OPENSSL_LIBRARIES}
${CJSON_LIBRARIES}
${THREAD_LIBRARY}
)
else()

Expand All @@ -103,6 +107,7 @@ else()
${LIBEV_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIRS}
${CJSON_INCLUDE_DIRS}
${THREAD_INCLUDE_DIRS}
)

#
Expand All @@ -112,6 +117,7 @@ else()
${LIBEV_LIBRARIES}
${OPENSSL_LIBRARIES}
${CJSON_LIBRARIES}
${THREAD_LIBRARY}
)
endif()

Expand Down

2 comments on commit 3c6a410

@ashu3103
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jesperpedersen, where are we planning to use threads??

@jesperpedersen
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using pthreads for workers - see the core data structures

Please sign in to comment.