@@ -87,6 +87,9 @@ endif()
87
87
88
88
option (ENABLE_DTRACE "enable dtrace support" "" )
89
89
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.
90
93
option (BUILD_SHARED_LIBS "build shared libraries" ON )
91
94
92
95
option (ENABLE_TESTING "build libdispatch tests" ON )
@@ -132,21 +135,22 @@ endif()
132
135
133
136
option (INSTALL_PRIVATE_HEADERS "installs private headers in the same location as the public ones" OFF )
134
137
135
- find_package (BlocksRuntime QUIET )
136
- if (NOT BlocksRuntime_FOUND)
138
+ if (NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
137
139
set (BlocksRuntime_INCLUDE_DIR ${PROJECT_SOURCE_DIR} /src/BlocksRuntime)
138
140
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.
139
144
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)
143
147
set_target_properties (BlocksRuntime
144
148
PROPERTIES
145
149
POSITION_INDEPENDENT_CODE TRUE )
146
150
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} )
150
154
endif ()
151
155
152
156
add_library (BlocksRuntime::BlocksRuntime ALIAS BlocksRuntime)
@@ -161,6 +165,10 @@ if(NOT BlocksRuntime_FOUND)
161
165
DESTINATION
162
166
"${INSTALL_BLOCK_HEADERS_DIR} " )
163
167
endif ()
168
+ install (TARGETS
169
+ BlocksRuntime
170
+ DESTINATION
171
+ ${INSTALL_TARGET_DIR} )
164
172
endif ()
165
173
166
174
check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
0 commit comments