@@ -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 )
@@ -131,21 +134,22 @@ endif()
131
134
132
135
option (INSTALL_PRIVATE_HEADERS "installs private headers in the same location as the public ones" OFF )
133
136
134
- find_package (BlocksRuntime QUIET )
135
- if (NOT BlocksRuntime_FOUND )
137
+ if (NOT CMAKE_SYSTEM_NAME STREQUAL Darwin )
136
138
set (BlocksRuntime_INCLUDE_DIR ${PROJECT_SOURCE_DIR} /src/BlocksRuntime )
137
139
140
+ # NOTE(compnerd) use the `BUILD_SHARED_LIBS` variable to determine what type
141
+ # of library to build. If it is true, we will generate shared libraries,
142
+ # otherwise we will generate static libraries.
138
143
add_library (BlocksRuntime
139
- STATIC
140
- ${PROJECT_SOURCE_DIR} /src/BlocksRuntime/data.c
141
- ${PROJECT_SOURCE_DIR} /src/BlocksRuntime/runtime.c )
144
+ ${PROJECT_SOURCE_DIR} /src/BlocksRuntime/data.c
145
+ ${PROJECT_SOURCE_DIR} /src/BlocksRuntime/runtime.c )
142
146
set_target_properties (BlocksRuntime
143
147
PROPERTIES
144
148
POSITION_INDEPENDENT_CODE TRUE )
145
149
if (HAVE_OBJC AND CMAKE_DL_LIBS )
146
- set_target_properties (BlocksRuntime
147
- PROPERTIES
148
- INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS} )
150
+ target_link_libraries (BlocksRuntime
151
+ PUBLIC
152
+ ${CMAKE_DL_LIBS} )
149
153
endif ()
150
154
151
155
add_library (BlocksRuntime::BlocksRuntime ALIAS BlocksRuntime )
@@ -160,6 +164,10 @@ if(NOT BlocksRuntime_FOUND)
160
164
DESTINATION
161
165
"${INSTALL_BLOCK_HEADERS_DIR} " )
162
166
endif ()
167
+ install (TARGETS
168
+ BlocksRuntime
169
+ DESTINATION
170
+ ${INSTALL_TARGET_DIR} )
163
171
endif ()
164
172
165
173
check_symbol_exists (__GNU_LIBRARY__ "features.h" _GNU_SOURCE )
0 commit comments