Skip to content

Commit 10890b7

Browse files
compnerddas
authored andcommitted
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. Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
1 parent 495ec35 commit 10890b7

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

CMakeLists.txt

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ 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")
22-
set(WITH_PTHREAD_WORKQUEUES "" CACHE PATH "Path to pthread-workqueues")
2326

2427
include(DispatchAppleOptions)
2528

@@ -34,27 +37,27 @@ set(USE_LIBDISPATCH_INIT_CONSTRUCTOR ${ENABLE_DISPATCH_INIT_CONSTRUCTOR})
3437
option(ENABLE_THREAD_LOCAL_STORAGE "enable usage of thread local storage via __thread" ON)
3538
set(DISPATCH_USE_THREAD_LOCAL_STORAGE ${ENABLE_THREAD_LOCAL_STORAGE})
3639

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)
40+
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR
41+
CMAKE_SYSTEM_NAME STREQUAL Android OR
42+
CMAKE_SYSTEM_NAME STREQUAL Windows)
43+
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT ON)
5444
else()
55-
# TODO(compnerd) support system installed pthread-workqueues
56-
# find_package(pthread_workqueues REQUIRED)
57-
# set(HAVE_PTHREAD_WORKQUEUES 1)
45+
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT OFF)
46+
endif()
47+
option(ENABLE_INTERNAL_PTHREAD_WORKQUEUES "use libdispatch's own implementation of pthread workqueues" ${ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT})
48+
if(ENABLE_INTERNAL_PTHREAD_WORKQUEUES)
49+
set(DISPATCH_USE_INTERNAL_WORKQUEUE 1)
50+
set(HAVE_PTHREAD_WORKQUEUES 0)
51+
else()
52+
check_include_files(pthread/workqueue_private.h HAVE_PTHREAD_WORKQUEUE_PRIVATE_H)
53+
check_include_files(pthread_workqueue.h HAVE_PTHREAD_WORKQUEUE_H)
54+
if(HAVE_PTHREAD_WORKQUEUE_PRIVATE_H AND HAVE_PTHREAD_WORKQUEUE_H)
55+
set(HAVE_PTHREAD_WORKQUEUES 1)
56+
set(DISPATCH_USE_INTERNAL_WORKQUEUE 0)
57+
else()
58+
set(HAVE_PTHREAD_WORKQUEUES 0)
59+
set(DISPATCH_USE_INTERNAL_WORKQUEUE 1)
60+
endif()
5861
endif()
5962

6063
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR
@@ -78,12 +81,6 @@ else()
7881
# find_package(BlocksRuntime REQUIRED)
7982
endif()
8083

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

cmake/config.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/* Define if building pthread work queues from source */
3-
#cmakedefine BUILD_OWN_PTHREAD_WORKQUEUES
3+
#cmakedefine01 DISPATCH_USE_INTERNAL_WORKQUEUE
44

55
/* Enable usage of thread local storage via __thread */
66
#cmakedefine01 DISPATCH_USE_THREAD_LOCAL_STORAGE

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)