Skip to content

Commit db2d2d7

Browse files
committed
build: support internal pthread workqueues in cmake
Add support to the cmake based build system to use the internal pthread workqueue implementation. This restores parity with the autotools build.
1 parent de938f3 commit db2d2d7

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

CMakeLists.txt

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
1515
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
1616
find_package(Threads REQUIRED)
1717

18+
include(CheckCSourceCompiles)
19+
include(CheckFunctionExists)
20+
include(CheckIncludeFiles)
21+
include(CheckLibraryExists)
22+
include(CheckSymbolExists)
1823
include(GNUInstallDirs)
19-
include(ExternalProject)
2024

2125
set(WITH_BLOCKS_RUNTIME "" CACHE PATH "Path to blocks runtime")
2226
set(WITH_PTHREAD_WORKQUEUES "" CACHE PATH "Path to pthread-workqueues")
@@ -34,27 +38,25 @@ set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR})
3438
option(ENABLE_THREAD_LOCAL_STORAGE "enable usage of thread local storage via __thread" ON)
3539
set(DISPATCH_USE_THREAD_LOCAL_STORAGE ${ENABLE_THREAD_LOCAL_STORAGE})
3640

37-
if(EXISTS "${CMAKE_SOURCE_DIR}/libpwq/CMakeLists.txt")
38-
ExternalProject_Add(pwq
39-
SOURCE_DIR
40-
"${CMAKE_SOURCE_DIR}/libpwq"
41-
CMAKE_ARGS
42-
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
43-
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
44-
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
45-
BUILD_BYPRODUCTS
46-
<INSTALL_DIR>/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}pthread_workqueue${CMAKE_STATIC_LIBRARY_SUFFIX})
47-
ExternalProject_Get_Property(pwq install_dir)
48-
add_library(PTHREAD::workqueue UNKNOWN IMPORTED)
49-
set_target_properties(PTHREAD::workqueue
50-
PROPERTIES
51-
IMPORTED_LOCATION ${install_dir}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}pthread_workqueue${CMAKE_STATIC_LIBRARY_SUFFIX})
52-
set(WITH_PTHREAD_WORKQUEUES "${install_dir}" CACHE PATH "Path to pthread-workqueues" FORCE)
53-
set(HAVE_PTHREAD_WORKQUEUES 1)
41+
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
42+
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT ON)
5443
else()
55-
# TODO(compnerd) support system installed pthread-workqueues
56-
# find_package(pthread_workqueues REQUIRED)
57-
# set(HAVE_PTHREAD_WORKQUEUES 1)
44+
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT OFF)
45+
endif()
46+
option(ENABLE_INTERNAL_PTHREAD_WORKQUEUES "use libdispatch's own implementation of pthread workqueues" ${ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT})
47+
if(ENABLE_INTERNAL_PTHREAD_WORKQUEUES)
48+
set(DISPATCH_USE_INTERNAL_WORKQUEUE 1)
49+
set(HAVE_PTHREAD_WORKQUEUES 0)
50+
else()
51+
check_include_files(pthread/workqueue_private.h HAVE_PTHREAD_WORKQUEUE_PRIVATE_H)
52+
check_include_files(pthread_workqueue.h HAVE_PTHREAD_WORKQUEUE_H)
53+
if(HAVE_PTHREAD_WORKQUEUE_PRIVATE_H AND HAVE_PTHREAD_WORKQUEUE_H)
54+
set(HAVE_PTHREAD_WORKQUEUES 1)
55+
set(DISPATCH_USE_INTERNAL_WORKQUEUE 0)
56+
else()
57+
set(HAVE_PTHREAD_WORKQUEUES 0)
58+
set(DISPATCH_USE_INTERNAL_WORKQUEUE 1)
59+
endif()
5860
endif()
5961

6062
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR
@@ -78,12 +80,6 @@ else()
7880
# find_package(BlocksRuntime REQUIRED)
7981
endif()
8082

81-
include(CheckCSourceCompiles)
82-
include(CheckFunctionExists)
83-
include(CheckIncludeFiles)
84-
include(CheckLibraryExists)
85-
include(CheckSymbolExists)
86-
8783
check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
8884
if(_GNU_SOURCE)
8985
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE)

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ add_library(dispatch
5353
shims/time.h
5454
shims/tsd.h
5555
shims/yield.h)
56+
if(DISPATCH_USE_INTERNAL_WORKQUEUE)
57+
target_sources(dispatch
58+
PRIVATE
59+
event/workqueue.c
60+
event/workqueue_internal.h)
61+
endif()
5662
target_sources(dispatch
5763
PRIVATE
5864
block.cpp)

0 commit comments

Comments
 (0)