From e731c2250836bd47b39f83734e08de7ea3c08822 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 26 Sep 2019 08:34:10 -0700 Subject: [PATCH 1/2] build: add exports targets Now that we can build the Swift content as a library, we can do export targets. This enables us to have CMake determine more information about the target, track dependencies across projects, and manage the flags across the trees without the special variables to specify the source and build trees. --- CMakeLists.txt | 2 ++ cmake/modules/CMakeLists.txt | 7 +++++++ cmake/modules/dispatchConfig.cmake.in | 7 +++++++ src/BlocksRuntime/CMakeLists.txt | 2 ++ src/CMakeLists.txt | 2 ++ src/swift/CMakeLists.txt | 4 ++++ 6 files changed, 24 insertions(+) create mode 100644 cmake/modules/CMakeLists.txt create mode 100644 cmake/modules/dispatchConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 10a0e4623..75c419c13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -276,3 +276,5 @@ add_subdirectory(src) if(BUILD_TESTING) add_subdirectory(tests) endif() + +add_subdirectory(cmake/modules) diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt new file mode 100644 index 000000000..10cc0e100 --- /dev/null +++ b/cmake/modules/CMakeLists.txt @@ -0,0 +1,7 @@ + +set(DISPATCH_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/dispatchExports.cmake) +configure_file(dispatchConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/dispatchConfig.cmake) + +get_property(DISPATCH_EXPORTS GLOBAL PROPERTY DISPATCH_EXPORTS) +export(TARGETS ${DISPATCH_EXPORTS} FILE ${DISPATCH_EXPORTS_FILE}) diff --git a/cmake/modules/dispatchConfig.cmake.in b/cmake/modules/dispatchConfig.cmake.in new file mode 100644 index 000000000..81228f271 --- /dev/null +++ b/cmake/modules/dispatchConfig.cmake.in @@ -0,0 +1,7 @@ + +set(DISPATCH_HAS_SWIFT_SDK_OVERLAY @ENABLE_SWIFT@) + +if(NOT TARGET dispatch) + include(@DISPATCH_EXPORTS_FILE@) +endif() + diff --git a/src/BlocksRuntime/CMakeLists.txt b/src/BlocksRuntime/CMakeLists.txt index a5388d6eb..4c8fa9929 100644 --- a/src/BlocksRuntime/CMakeLists.txt +++ b/src/BlocksRuntime/CMakeLists.txt @@ -28,7 +28,9 @@ if(INSTALL_PRIVATE_HEADERS) install(FILES Block_private.h DESTINATION ${INSTALL_BLOCK_HEADERS_DIR}) endif() +set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS BlocksRuntime) install(TARGETS BlocksRuntime + EXPORT dispatchExports ARCHIVE DESTINATION ${INSTALL_TARGET_DIR} LIBRARY DESTINATION ${INSTALL_TARGET_DIR} RUNTIME DESTINATION bin) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a81e7dcfe..c401758c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -159,7 +159,9 @@ if(ENABLE_SWIFT) add_subdirectory(swift) endif() +set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS dispatch) install(TARGETS dispatch + EXPORT dispatchExports ARCHIVE DESTINATION ${INSTALL_TARGET_DIR} LIBRARY DESTINATION ${INSTALL_TARGET_DIR} RUNTIME DESTINATION bin) diff --git a/src/swift/CMakeLists.txt b/src/swift/CMakeLists.txt index a10d969a3..18a297f90 100644 --- a/src/swift/CMakeLists.txt +++ b/src/swift/CMakeLists.txt @@ -46,11 +46,15 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule ${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftdoc DESTINATION ${INSTALL_TARGET_DIR}/${swift_arch}) +set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS swiftDispatch) install(TARGETS swiftDispatch + EXPORT dispatchExports ARCHIVE DESTINATION ${INSTALL_TARGET_DIR} LIBRARY DESTINATION ${INSTALL_TARGET_DIR} RUNTIME DESTINATION bin) if(NOT BUILD_SHARED_LIBS) + set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS DispatchStubs) install(TARGETS DispatchStubs + EXPORT dispatchExports DESTINATION ${INSTALL_TARGET_DIR}) endif() From c26f435eabb765306953b8910af7e63f10e09ea8 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 27 Sep 2019 15:40:39 -0700 Subject: [PATCH 2/2] build: adjust linking visibility for exported targets Make BlocksRuntime public rather than private since the public headers reference `Blocks.h` making the users dependent on BlocksRuntime, requiring the explicit link. This also enables the use of the export targets to automatically setup the include paths for users. --- src/BlocksRuntime/CMakeLists.txt | 8 +++++--- src/CMakeLists.txt | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/BlocksRuntime/CMakeLists.txt b/src/BlocksRuntime/CMakeLists.txt index 4c8fa9929..1bed20210 100644 --- a/src/BlocksRuntime/CMakeLists.txt +++ b/src/BlocksRuntime/CMakeLists.txt @@ -12,14 +12,16 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows) endif() endif() -set_target_properties(BlocksRuntime PROPERTIES - POSITION_INDEPENDENT_CODE TRUE - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(BlocksRuntime PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}) if(HAVE_OBJC AND CMAKE_DL_LIBS) target_link_libraries(BlocksRuntime PUBLIC ${CMAKE_DL_LIBS}) endif() +set_target_properties(BlocksRuntime PROPERTIES + POSITION_INDEPENDENT_CODE TRUE) + add_library(BlocksRuntime::BlocksRuntime ALIAS BlocksRuntime) install(FILES Block.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c401758c2..c88b430de 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -95,14 +95,13 @@ endif() set_target_properties(dispatch PROPERTIES POSITION_INDEPENDENT_CODE YES) -target_include_directories(dispatch PRIVATE +target_include_directories(dispatch PUBLIC ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories(dispatch PRIVATE ${PROJECT_SOURCE_DIR}/private) -target_include_directories(dispatch SYSTEM BEFORE PRIVATE - "${BlocksRuntime_INCLUDE_DIR}") if(CMAKE_SYSTEM_NAME STREQUAL Windows) target_compile_definitions(dispatch PRIVATE @@ -137,7 +136,8 @@ if(LibRT_FOUND) target_link_libraries(dispatch PRIVATE RT::rt) endif() target_link_libraries(dispatch PRIVATE - Threads::Threads + Threads::Threads) +target_link_libraries(dispatch PUBLIC BlocksRuntime::BlocksRuntime) if(CMAKE_SYSTEM_NAME STREQUAL Windows) target_link_libraries(dispatch PRIVATE