From ce21ab32fc00b089361d6d16b3a5061496ad2943 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 11 Oct 2018 21:18:24 -0700 Subject: [PATCH 1/6] cmake: update SwiftSupport from XCTest Update the swift support CMake rules from XCTest. This adds support for additional features like partial module compilation which improves incremental builds. It allows for executable and library builds. --- cmake/modules/SwiftSupport.cmake | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index bda9e6fb2..62189fa22 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -4,7 +4,7 @@ include(CMakeParseArguments) function(add_swift_target target) set(options LIBRARY;SHARED;STATIC) set(single_value_options MODULE_NAME;MODULE_LINK_NAME;MODULE_PATH;MODULE_CACHE_PATH;OUTPUT;TARGET) - set(multiple_value_options CFLAGS;DEPENDS;LINK_FLAGS;SOURCES;SWIFT_FLAGS) + set(multiple_value_options CFLAGS;DEPENDS;LINK_FLAGS;RESOURCES;SOURCES;SWIFT_FLAGS) cmake_parse_arguments(AST "${options}" "${single_value_options}" "${multiple_value_options}" ${ARGN}) @@ -132,16 +132,14 @@ function(add_swift_target target) if(AST_LIBRARY) set(emit_library -emit-library) endif() - if(library_kind STREQUAL SHARED) + if(NOT AST_LIBRARY OR library_kind STREQUAL SHARED) add_custom_command(OUTPUT ${AST_OUTPUT} DEPENDS ${objs} ${AST_DEPENDS} COMMAND - ${CMAKE_SWIFT_COMPILER} ${emit_library} ${link_flags} -o ${AST_OUTPUT} ${objs} - COMMAND - ${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}) + ${CMAKE_SWIFT_COMPILER} ${emit_library} ${link_flags} -o ${AST_OUTPUT} ${objs}) add_custom_target(${target} ALL DEPENDS @@ -164,6 +162,26 @@ function(add_swift_target target) ${module} ${documentation}) endif() + + if(AST_RESOURCES) + add_custom_command(TARGET + ${target} + POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${target} + COMMAND + ${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${target} + COMMAND + ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${target}/Resources + COMMAND + ${CMAKE_COMMAND} -E copy ${AST_RESOURCES} ${CMAKE_CURRENT_BINARY_DIR}/${target}/Resources) + else() + add_custom_command(TARGET + ${target} + POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}) + endif() endfunction() function(add_swift_library library) From 7492c0e98b235bc60a93f91c45e1d948ad0e4571 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 11 Oct 2018 21:27:22 -0700 Subject: [PATCH 2/6] cmake: support static and shared swift libraries Enhance add_wift_target to support building static libraries. We would always generate shared libraries previously. --- cmake/modules/SwiftSupport.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index 62189fa22..b55f161e3 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -148,6 +148,7 @@ function(add_swift_target target) ${documentation}) else() add_library(${target}-static STATIC ${objs}) + add_dependencies(${target}-static ${AST_DEPENDS}) get_filename_component(ast_output_bn ${AST_OUTPUT} NAME) get_filename_component(ast_output_dn ${AST_OUTPUT} DIRECTORY) set_target_properties(${target}-static From 87c1f5bc753e3b4e35635cdbacc4ef4e73ef6682 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 17 Nov 2018 08:03:46 -0800 Subject: [PATCH 3/6] build: install import libraries for Windows This is needed to enable Windows to actually link against swiftDispatch to build code. When building against a distribution image rather than the build tree, this comes to light. --- cmake/modules/SwiftSupport.cmake | 14 ++++++++++++++ src/CMakeLists.txt | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index b55f161e3..dff4ebe23 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -70,6 +70,11 @@ function(add_swift_target target) set(AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${target}${CMAKE_EXECUTABLE_SUFFIX}) endif() endif() + if(CMAKE_SYSTEM_NAME STREQUAL Windows) + if(AST_SHARED OR BUILD_SHARED_LIBS) + set(IMPORT_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${CMAKE_IMPORT_LIBRARY_PREFIX}${target}${CMAKE_IMPORT_LIBRARY_SUFFIX}) + endif() + endif() set(sources) foreach(source ${AST_SOURCES}) @@ -182,6 +187,15 @@ function(add_swift_target target) POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}) + if(CMAKE_SYSTEM_NAME STREQUAL Windows) + if(AST_SHARED OR BUILD_SHARED_LIBS) + add_custom_command(TARGET + ${target} + POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E copy ${IMPORT_LIBRARY} ${CMAKE_CURRENT_BINARY_DIR}) + endif() + endif() endif() endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12105999e..dec1dd436 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -267,5 +267,13 @@ if(ENABLE_SWIFT) ${swiftDispatch_OUTPUT_FILE} DESTINATION ${INSTALL_TARGET_DIR}) + if(CMAKE_SYSTEM_NAME STREQUAL Windows) + if(BUILD_SHARED_LIBS) + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_IMPORT_LIBRARY_PREFIX}swiftDispatch${CMAKE_IMPORT_LIBRARY_SUFFIX} + DESTINATION + ${INSTALL_TARGET_DIR}) + endif() + endif() endif() From 5aeea6ecf563bee965298083b636b87e6a47f791 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 17 Nov 2018 08:04:39 -0800 Subject: [PATCH 4/6] build: install os header for Windows We did not distribute generic_win_base.h which prevents the CDispatch module from being built when building against a distribution image. --- os/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/os/CMakeLists.txt b/os/CMakeLists.txt index 2c4d32e66..282af25f7 100644 --- a/os/CMakeLists.txt +++ b/os/CMakeLists.txt @@ -5,6 +5,7 @@ install(FILES object.h generic_unix_base.h + generic_win_base.h DESTINATION "${INSTALL_OS_HEADERS_DIR}") From 290df63c4d127eb132535ee0f92070066e7240af Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 17 Nov 2018 08:05:52 -0800 Subject: [PATCH 5/6] build: spell `-fno-exceptions` for MSVC We did not disable exceptions when building with cl, do so like we do with the GCC style driver. --- src/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dec1dd436..d90aeae80 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -174,7 +174,9 @@ if(WIN32) PRIVATE _CRT_NONSTDC_NO_WARNINGS) endif() -if(NOT "${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") +if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") + target_compile_options(dispatch PRIVATE /EHs-c-) +else() target_compile_options(dispatch PRIVATE -fno-exceptions) endif() if(DISPATCH_ENABLE_ASSERTS) From ea2a03ddfa642543f4d2d76b963d9f9974dad0ed Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 17 Nov 2018 08:07:10 -0800 Subject: [PATCH 6/6] build: install libraries into the right location Windows splits the installation into the library directory (for the import library) and the runtime component (dll) which is installed into bin. This makes the Windows build happier. --- CMakeLists.txt | 5 +++-- src/CMakeLists.txt | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 168c21a5f..42607a233 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,8 +166,9 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) endif() install(TARGETS BlocksRuntime - DESTINATION - ${INSTALL_TARGET_DIR}) + ARCHIVE DESTINATION ${INSTALL_TARGET_DIR} + LIBRARY DESTINATION ${INSTALL_TARGET_DIR} + RUNTIME DESTINATION bin) endif() check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d90aeae80..d41f4d305 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -249,8 +249,10 @@ dispatch_set_linker(dispatch) install(TARGETS dispatch - DESTINATION - "${INSTALL_TARGET_DIR}") + ARCHIVE DESTINATION ${INSTALL_TARGET_DIR} + LIBRARY DESTINATION ${INSTALL_TARGET_DIR} + RUNTIME DESTINATION bin) + if(ENABLE_SWIFT) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule