Skip to content

Commit 8aa73a1

Browse files
committed
build: honour BUILD_SHARED_LIBS
This is needed for proper shared linkage to the BlocksRuntime (e.g. when building SourceKit). We now build BlocksRuntime shared or static as requested.
1 parent 6162a1d commit 8aa73a1

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

CMakeLists.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ endif()
8787

8888
option(ENABLE_DTRACE "enable dtrace support" "")
8989

90+
# NOTE(abdulras) this is the CMake supported way to control whether we generate
91+
# shared or static libraries. This impacts the behaviour of `add_library` in
92+
# what type of library it generates.
9093
option(BUILD_SHARED_LIBS "build shared libraries" ON)
9194

9295
option(ENABLE_TESTING "build libdispatch tests" ON)
@@ -132,21 +135,22 @@ endif()
132135

133136
option(INSTALL_PRIVATE_HEADERS "installs private headers in the same location as the public ones" OFF)
134137

135-
find_package(BlocksRuntime QUIET)
136-
if(NOT BlocksRuntime_FOUND)
138+
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
137139
set(BlocksRuntime_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/BlocksRuntime)
138140

141+
# NOTE(compnerd) use the `BUILD_SHARED_LIBS` variable to determine what type
142+
# of library to build. If it is true, we will generate shared libraries,
143+
# otherwise we will generate static libraries.
139144
add_library(BlocksRuntime
140-
STATIC
141-
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/data.c
142-
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/runtime.c)
145+
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/data.c
146+
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/runtime.c)
143147
set_target_properties(BlocksRuntime
144148
PROPERTIES
145149
POSITION_INDEPENDENT_CODE TRUE)
146150
if(HAVE_OBJC AND CMAKE_DL_LIBS)
147-
set_target_properties(BlocksRuntime
148-
PROPERTIES
149-
INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS})
151+
target_link_libraries(BlocksRuntime
152+
PUBLIC
153+
${CMAKE_DL_LIBS})
150154
endif()
151155

152156
add_library(BlocksRuntime::BlocksRuntime ALIAS BlocksRuntime)
@@ -161,6 +165,10 @@ if(NOT BlocksRuntime_FOUND)
161165
DESTINATION
162166
"${INSTALL_BLOCK_HEADERS_DIR}")
163167
endif()
168+
install(TARGETS
169+
BlocksRuntime
170+
DESTINATION
171+
${INSTALL_TARGET_DIR})
164172
endif()
165173

166174
check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)

dispatch/generic/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Dispatch {
22
requires blocks
33
export *
44
link "dispatch"
5+
link "BlocksRuntime"
56
}
67

78
module DispatchIntrospection [system] [extern_c] {

0 commit comments

Comments
 (0)