Skip to content

Commit b488b2d

Browse files
committed
build: support static builds for Swift
Adjust the paths for static runtime builds of Swift.
1 parent 8aa73a1 commit b488b2d

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

CMakeLists.txt

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,37 @@ if(ENABLE_SWIFT)
5656
string(TOLOWER ${CMAKE_SYSTEM_NAME} SWIFT_OS)
5757
get_swift_host_arch(SWIFT_HOST_ARCH)
5858

59-
set(SWIFT_RUNTIME_LIBDIR ${SWIFT_TOOLCHAIN}/${SWIFT_LIBDIR}/swift/${SWIFT_OS}/${SWIFT_HOST_ARCH})
59+
if(BUILD_SHARED_LIBS)
60+
set(swift_dir swift)
61+
set(runtime_kind SHARED)
62+
else()
63+
set(swift_dir swift_static)
64+
set(runtime_kind STATIC)
65+
endif()
66+
67+
set(prefix ${CMAKE_${runtime_kind}_LIBRARY_PREFIX})
68+
set(suffix ${CMAKE_${runtime_kind}_LIBRARY_SUFFIX})
69+
70+
set(SWIFT_RUNTIME_LIBDIR ${SWIFT_TOOLCHAIN}/${SWIFT_LIBDIR}/${swift_dir}/${SWIFT_OS}/${SWIFT_HOST_ARCH})
6071

6172
add_library(swiftCore
62-
SHARED IMPORTED GLOBAL)
73+
${runtime_kind} IMPORTED GLOBAL)
6374
set_target_properties(swiftCore
6475
PROPERTIES
6576
IMPORTED_LOCATION
66-
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftCore${CMAKE_SHARED_LIBRARY_SUFFIX})
77+
${SWIFT_RUNTIME_LIBDIR}/${prefix}swiftCore${suffix})
6778

6879
add_library(swiftSwiftOnoneSupport
69-
SHARED IMPORTED GLOBAL)
80+
${runtime_kind} IMPORTED GLOBAL)
7081
set_target_properties(swiftSwiftOnoneSupport
7182
PROPERTIES
7283
IMPORTED_LOCATION
73-
${SWIFT_RUNTIME_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}swiftSwiftOnoneSupport${CMAKE_SHARED_LIBRARY_SUFFIX})
84+
${SWIFT_RUNTIME_LIBDIR}/${prefix}swiftSwiftOnoneSupport${suffix})
7485

75-
set(INSTALL_TARGET_DIR "${INSTALL_LIBDIR}/swift/${SWIFT_OS}" CACHE PATH "Path where the libraries will be installed")
76-
set(INSTALL_DISPATCH_HEADERS_DIR "${INSTALL_LIBDIR}/swift/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch")
77-
set(INSTALL_BLOCK_HEADERS_DIR "${INSTALL_LIBDIR}/swift/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime")
78-
set(INSTALL_OS_HEADERS_DIR "${INSTALL_LIBDIR}/swift/os" CACHE PATH "Path where the os/ headers will be installed")
86+
set(INSTALL_TARGET_DIR "${INSTALL_LIBDIR}/${swift_dir}/${SWIFT_OS}" CACHE PATH "Path where the libraries will be installed")
87+
set(INSTALL_DISPATCH_HEADERS_DIR "${INSTALL_LIBDIR}/${swift_dir}/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch")
88+
set(INSTALL_BLOCK_HEADERS_DIR "${INSTALL_LIBDIR}/${swift_dir}/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime")
89+
set(INSTALL_OS_HEADERS_DIR "${INSTALL_LIBDIR}/${swift_dir}/os" CACHE PATH "Path where the os/ headers will be installed")
7990
endif()
8091

8192
if(NOT ENABLE_SWIFT)

0 commit comments

Comments
 (0)