Skip to content

Commit

Permalink
build: extract libdispatch build for swift
Browse files Browse the repository at this point in the history
Extract the ExternalProject handling for libdispatch needed to build
SourceKit on Linux into a separate CMake list.  This will allow us to
pull in a dependency on Foundation as well to allow building SwiftSyntax
on Linux which requires Foundation.  Foundation has a dependency on
libdispatch requiring that the external project handling is centralised.
  • Loading branch information
compnerd committed Aug 8, 2018
1 parent 7759c02 commit f140734
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 62 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,11 @@ add_subdirectory(stdlib)
if(SWIFT_INCLUDE_TOOLS)
add_subdirectory(include)
add_subdirectory(lib)

endif()

include(SwiftExternal)

if(SWIFT_INCLUDE_TOOLS)
# Always include this after including stdlib/!
# Refer to the large comment above the add_subdirectory(stdlib) call.
# https://bugs.swift.org/browse/SR-5975
Expand Down
65 changes: 65 additions & 0 deletions cmake/modules/SwiftExternal.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
include(ExternalProject)

if(SWIFT_BUILD_SOURCEKIT)
ExternalProject_Add(libdispatch
SOURCE_DIR
"${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}"
BINARY_DIR
"${SWIFT_PATH_TO_LIBDISPATCH_BUILD}"
CMAKE_ARGS
-DCMAKE_C_COMPILER=${PATH_TO_CLANG_BUILD}/bin/clang
-DCMAKE_CXX_COMPILER=${PATH_TO_CLANG_BUILD}/bin/clang++
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DCMAKE_SWIFT_COMPILER=$<TARGET_FILE:swift>c
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DENABLE_SWIFT=YES
BUILD_BYPRODUCTS
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/src/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/${CMAKE_STATIC_LIBRARY_PREFIX}BlocksRuntime${CMAKE_STATIC_LIBRARY_SUFFIX}
STEP_TARGETS
configure
BUILD_ALWAYS
1)

# CMake does not like the addition of INTERFACE_INCLUDE_DIRECTORIES without
# the directory existing. Just create the location which will be populated
# during the installation.
ExternalProject_Get_Property(libdispatch install_dir)
file(MAKE_DIRECTORY ${install_dir}/include)

# TODO(compnerd) this should be taken care of by the
# INTERFACE_INCLUDE_DIRECTORIES below
include_directories(AFTER
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE})
add_dependencies(libdispatch
swift
copy_shim_headers
swiftCore-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}
swiftSwiftOnoneSupport-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}
swiftCore-swiftmodule-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}
swiftSwiftOnoneSupport-swiftmodule-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH})
endif()

ExternalProject_Get_Property(libdispatch install_dir)
add_library(dispatch SHARED IMPORTED)
set_target_properties(dispatch
PROPERTIES
IMPORTED_LOCATION
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/src/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES
${install_dir}/include
IMPORTED_LINK_INTERFACE_LIBRARIES
swiftCore-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH})

add_library(BlocksRuntime STATIC IMPORTED)
set_target_properties(BlocksRuntime
PROPERTIES
IMPORTED_LOCATION
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/${CMAKE_STATIC_LIBRARY_PREFIX}BlocksRuntime${CMAKE_STATIC_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime)
endif()

61 changes: 0 additions & 61 deletions tools/SourceKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,67 +92,6 @@ include_directories(BEFORE

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(SOURCEKIT_DEFAULT_TARGET_SDK "LINUX")
if(SWIFT_BUILD_SOURCEKIT)
include(ExternalProject)
ExternalProject_Add(libdispatch
SOURCE_DIR
"${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}"
BINARY_DIR
"${SWIFT_PATH_TO_LIBDISPATCH_BUILD}"
CMAKE_ARGS
-DCMAKE_C_COMPILER=${PATH_TO_CLANG_BUILD}/bin/clang
-DCMAKE_CXX_COMPILER=${PATH_TO_CLANG_BUILD}/bin/clang++
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DCMAKE_SWIFT_COMPILER=$<TARGET_FILE:swift>c
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DENABLE_SWIFT=YES
BUILD_BYPRODUCTS
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/src/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/${CMAKE_STATIC_LIBRARY_PREFIX}BlocksRuntime${CMAKE_STATIC_LIBRARY_SUFFIX}
STEP_TARGETS
configure
BUILD_ALWAYS
1)

# CMake does not like the addition of INTERFACE_INCLUDE_DIRECTORIES without
# the directory existing. Just create the location which will be populated
# during the installation.
ExternalProject_Get_Property(libdispatch install_dir)
file(MAKE_DIRECTORY ${install_dir}/include)

# TODO(compnerd) this should be taken care of by the
# INTERFACE_INCLUDE_DIRECTORIES below
include_directories(AFTER
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE})
add_dependencies(libdispatch
swift
copy_shim_headers
swiftCore-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}
swiftSwiftOnoneSupport-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}
swiftCore-swiftmodule-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}
swiftSwiftOnoneSupport-swiftmodule-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH})
endif()

ExternalProject_Get_Property(libdispatch install_dir)
add_library(dispatch SHARED IMPORTED)
set_target_properties(dispatch
PROPERTIES
IMPORTED_LOCATION
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/src/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES
${install_dir}/include
IMPORTED_LINK_INTERFACE_LIBRARIES
swiftCore-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH})

add_library(BlocksRuntime STATIC IMPORTED)
set_target_properties(BlocksRuntime
PROPERTIES
IMPORTED_LOCATION
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/${CMAKE_STATIC_LIBRARY_PREFIX}BlocksRuntime${CMAKE_STATIC_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime)

set(SOURCEKIT_NEED_EXPLICIT_LIBDISPATCH TRUE)
endif()

Expand Down

0 comments on commit f140734

Please sign in to comment.