Skip to content

cmake parity updates #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)

include(CheckCSourceCompiles)
include(CheckFunctionExists)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(GNUInstallDirs)
include(ExternalProject)

set(WITH_BLOCKS_RUNTIME "" CACHE PATH "Path to blocks runtime")
set(WITH_PTHREAD_WORKQUEUES "" CACHE PATH "Path to pthread-workqueues")

include(DispatchAppleOptions)

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

if(EXISTS "${CMAKE_SOURCE_DIR}/libpwq/CMakeLists.txt")
ExternalProject_Add(pwq
SOURCE_DIR
"${CMAKE_SOURCE_DIR}/libpwq"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
BUILD_BYPRODUCTS
<INSTALL_DIR>/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}pthread_workqueue${CMAKE_STATIC_LIBRARY_SUFFIX})
ExternalProject_Get_Property(pwq install_dir)
add_library(PTHREAD::workqueue UNKNOWN IMPORTED)
set_target_properties(PTHREAD::workqueue
PROPERTIES
IMPORTED_LOCATION ${install_dir}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}pthread_workqueue${CMAKE_STATIC_LIBRARY_SUFFIX})
set(WITH_PTHREAD_WORKQUEUES "${install_dir}" CACHE PATH "Path to pthread-workqueues" FORCE)
set(HAVE_PTHREAD_WORKQUEUES 1)
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR
CMAKE_SYSTEM_NAME STREQUAL Android OR
CMAKE_SYSTEM_NAME STREQUAL Windows)
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT ON)
else()
# TODO(compnerd) support system installed pthread-workqueues
# find_package(pthread_workqueues REQUIRED)
# set(HAVE_PTHREAD_WORKQUEUES 1)
set(ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT OFF)
endif()
option(ENABLE_INTERNAL_PTHREAD_WORKQUEUES "use libdispatch's own implementation of pthread workqueues" ${ENABLE_INTERNAL_PTHREAD_WORKQUEUES_DEFAULT})
if(ENABLE_INTERNAL_PTHREAD_WORKQUEUES)
set(DISPATCH_USE_INTERNAL_WORKQUEUE 1)
set(HAVE_PTHREAD_WORKQUEUES 0)
else()
check_include_files(pthread/workqueue_private.h HAVE_PTHREAD_WORKQUEUE_PRIVATE_H)
check_include_files(pthread_workqueue.h HAVE_PTHREAD_WORKQUEUE_H)
if(HAVE_PTHREAD_WORKQUEUE_PRIVATE_H AND HAVE_PTHREAD_WORKQUEUE_H)
set(HAVE_PTHREAD_WORKQUEUES 1)
set(DISPATCH_USE_INTERNAL_WORKQUEUE 0)
else()
set(HAVE_PTHREAD_WORKQUEUES 0)
set(DISPATCH_USE_INTERNAL_WORKQUEUE 1)
endif()
endif()

if(CMAKE_SYSTEM_NAME STREQUAL Linux OR
Expand All @@ -78,12 +81,6 @@ else()
# find_package(BlocksRuntime REQUIRED)
endif()

include(CheckCSourceCompiles)
include(CheckFunctionExists)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckSymbolExists)

check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
if(_GNU_SOURCE)
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE)
Expand Down
2 changes: 1 addition & 1 deletion cmake/config.h.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/* Define if building pthread work queues from source */
#cmakedefine BUILD_OWN_PTHREAD_WORKQUEUES
#cmakedefine01 DISPATCH_USE_INTERNAL_WORKQUEUE

/* Enable usage of thread local storage via __thread */
#cmakedefine01 DISPATCH_USE_THREAD_LOCAL_STORAGE
Expand Down
92 changes: 51 additions & 41 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,44 +1,6 @@

include(SwiftSupport)

set(dispatch_BLOCK_SOURCES block.cpp)
if(HAVE_OBJC)
list(APPEND dispatch_BLOCK_SOURCES data.m object.m)
endif()
set(dispatch_SWIFT_SOURCES)
if(CMAKE_SWIFT_COMPILER)
set(swift_optimization_flags)
if(CMAKE_BUILD_TYPE MATCHES Release)
set(swift_optimization_flags -O)
endif()
add_swift_library(swiftDispatch
MODULE_NAME
Dispatch
MODULE_LINK_NAME
dispatch
MODULE_PATH
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o
SOURCES
swift/Block.swift
swift/Data.swift
swift/Dispatch.swift
swift/IO.swift
swift/Private.swift
swift/Queue.swift
swift/Source.swift
swift/Time.swift
swift/Wrapper.swift
CFLAGS
-fblocks
-fmodule-map-file=${CMAKE_SOURCE_DIR}/dispatch/module.modulemap
SWIFT_FLAGS
-I ${CMAKE_SOURCE_DIR}
${swift_optimization_flags})
list(APPEND dispatch_SWIFT_SOURCES
swift/DispatchStubs.cc;${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o)
endif()
add_library(dispatch
allocator.c
apply.c
Expand Down Expand Up @@ -90,9 +52,57 @@ add_library(dispatch
shims/perfmon.h
shims/time.h
shims/tsd.h
shims/yield.h
${dispatch_BLOCK_SOURCES}
${dispatch_SWIFT_SOURCES})
shims/yield.h)
if(DISPATCH_USE_INTERNAL_WORKQUEUE)
target_sources(dispatch
PRIVATE
event/workqueue.c
event/workqueue_internal.h)
endif()
target_sources(dispatch
PRIVATE
block.cpp)
if(HAVE_OBJC)
target_sources(dispatch
PRIVATE
data.m
object.m)
endif()
if(CMAKE_SWIFT_COMPILER)
set(swift_optimization_flags)
if(CMAKE_BUILD_TYPE MATCHES Release)
set(swift_optimization_flags -O)
endif()
add_swift_library(swiftDispatch
MODULE_NAME
Dispatch
MODULE_LINK_NAME
dispatch
MODULE_PATH
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o
SOURCES
swift/Block.swift
swift/Data.swift
swift/Dispatch.swift
swift/IO.swift
swift/Private.swift
swift/Queue.swift
swift/Source.swift
swift/Time.swift
swift/Wrapper.swift
CFLAGS
-fblocks
-fmodule-map-file=${CMAKE_SOURCE_DIR}/dispatch/module.modulemap
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a pre-existing bug but this is the linux modulemap, if we ever want this part to work on Darwin this path will need to be conditionalized per platform

SWIFT_FLAGS
-I ${CMAKE_SOURCE_DIR}
${swift_optimization_flags})
target_sources(dispatch
PRIVATE
swift/DispatchStubs.cc
${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o)
endif()
target_include_directories(dispatch
PRIVATE
${CMAKE_BINARY_DIR}
Expand Down