Skip to content

build: honour BUILD_SHARED_LIBS #396

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 1 commit into from
Oct 4, 2018
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
24 changes: 16 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ endif()

option(ENABLE_DTRACE "enable dtrace support" "")

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

option(ENABLE_TESTING "build libdispatch tests" ON)
Expand Down Expand Up @@ -132,21 +135,22 @@ endif()

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

find_package(BlocksRuntime QUIET)
if(NOT BlocksRuntime_FOUND)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(BlocksRuntime_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/BlocksRuntime)

# NOTE(compnerd) use the `BUILD_SHARED_LIBS` variable to determine what type
# of library to build. If it is true, we will generate shared libraries,
# otherwise we will generate static libraries.
add_library(BlocksRuntime
STATIC
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/data.c
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/runtime.c)
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/data.c
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/runtime.c)
set_target_properties(BlocksRuntime
PROPERTIES
POSITION_INDEPENDENT_CODE TRUE)
if(HAVE_OBJC AND CMAKE_DL_LIBS)
set_target_properties(BlocksRuntime
PROPERTIES
INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS})
target_link_libraries(BlocksRuntime
Copy link

Choose a reason for hiding this comment

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

This is a functional linkage change that should go into another PR (though I suspect this branch is never executed). If this is required then we need to change our approach to the module map as well (as we'd now need to link dl and objc).

Copy link
Member Author

Choose a reason for hiding this comment

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

INTERFACE doesn't work with shared libraries, so this should be public (since INTERFACE is equal to PUBLIC with shared).

PUBLIC
${CMAKE_DL_LIBS})
endif()

add_library(BlocksRuntime::BlocksRuntime ALIAS BlocksRuntime)
Expand All @@ -161,6 +165,10 @@ if(NOT BlocksRuntime_FOUND)
DESTINATION
"${INSTALL_BLOCK_HEADERS_DIR}")
endif()
install(TARGETS
BlocksRuntime
DESTINATION
${INSTALL_TARGET_DIR})
endif()

check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
Expand Down
1 change: 1 addition & 0 deletions dispatch/generic/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Dispatch {
requires blocks
export *
link "dispatch"
link "BlocksRuntime"
}

module DispatchIntrospection [system] [extern_c] {
Expand Down