Skip to content

Commit a9da4a5

Browse files
committed
CMake: Add install platform and architecture subdirs
In some configurations, libraries are installed under `<install-prefix>/{libdir}/swift/<platform>/<arch>` and module content is installed under `<install-prefix>/{libdir}/swift/<platform>`. This also accounts for the fact that Swift currently looks under `<install-prefix>/{libdir}/swift_static/**` for the static stdlib builds.
1 parent 74a8c58 commit a9da4a5

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

Runtimes/Core/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ option(SwiftCore_ENABLE_INTERNAL_CHECKS "" OFF)
111111
defaulted_set(SwiftCore_OBJECT_FORMAT STRING "Object format: ELF COFF")
112112
defaulted_set(SwiftCore_THREADING_PACKAGE STRING "Threading Package: C11 Linux PThreads Win32")
113113

114+
option(SwiftCore_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" ON)
115+
set(SwiftCore_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${SwiftCore_INSTALL_NESTED_SUBDIR}>:/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}>")
116+
set(SwiftCore_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${SwiftCore_INSTALL_NESTED_SUBDIR}>:/${SwiftCore_PLATFORM_SUBDIR}>")
117+
114118
# TODO: Most of these should be attached to specific targets rather than applied
115119
# globally. They can be applied as part of the library interface if they
116120
# affect the behavior of libraries that build against a given target.

Runtimes/Core/cmake/caches/Vendors/Apple/apple-common.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ set(SwiftCore_ENABLE_RUNTIME_FUNCTION_COUNTERS ON CACHE BOOL "")
1313
set(SwiftCore_ENABLE_BACKDEPLOYMENT_SUPPORT ON CACHE BOOL "")
1414
set(SwiftCore_ENABLE_FILESYSTEM_SUPPORT ON CACHE BOOL "")
1515

16+
set(SwiftCore_INSTALL_NESTED_SUBDIR OFF CACHE BOOL "")
17+
1618
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -g -DNDEBUG" CACHE STRING "")
1719
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -g -DNDEBUG" CACHE STRING "")
1820
set(CMAKE_Swift_FLAGS_MINSIZEREL "-Osize -g" CACHE STRING "")

Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ function(install_swift_interface target)
2121
if(SwiftCore_ENABLE_LIBRARY_EVOLUTION)
2222
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftinterface"
2323
RENAME "${SwiftCore_MODULE_TRIPLE}.swiftinterface"
24-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
24+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
2525

2626
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.private.swiftinterface"
2727
RENAME "${SwiftCore_MODULE_TRIPLE}.private.swiftinterface"
28-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
28+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
2929
endif()
3030
endfunction()

Runtimes/Core/core/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,12 @@ elseif(NOT APPLE AND NOT LINUX AND NOT ANDROID AND UNIX)
326326
target_link_libraries(swiftCore PRIVATE "${EXECINFO_LIBRARY}")
327327
endif()
328328

329-
install(TARGETS swiftCore)
329+
install(TARGETS swiftCore
330+
ARCHIVE DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
331+
LIBRARY DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
332+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
330333
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Swift.swiftmodule"
331-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/Swift.swiftmodule"
334+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/Swift.swiftmodule"
332335
RENAME "${SwiftCore_MODULE_TRIPLE}.swiftmodule")
333336
emit_swift_interface(swiftCore)
334337
install_swift_interface(swiftCore)

Runtimes/Core/runtime/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ if("${SwiftCore_OBJECT_FORMAT}" STREQUAL "elfx")
149149
"${SwiftCore_SWIFTC_SOURCE_DIR}/include"
150150
"${PROJECT_BINARY_DIR}/include")
151151
target_link_libraries(swiftrt PRIVATE swiftShims)
152+
# The driver requires that swifrt.o is under `usr/lib/swift/<platform>/<arch>`
153+
# Regardless of settings
152154
install(FILES $<TARGET_OBJECTS:swiftrt>
153155
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}"
154156
RENAME swiftrt.o)
@@ -158,6 +160,8 @@ elseif("${SwiftCore_OBJECT_FORMAT}" STREQUAL "coffx")
158160
$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:SWIFT_STATIC_STDLIB>)
159161
target_link_libraries(swiftrt PRIVATE swiftShims)
160162
install(FILES $<TARGET_OBJECTS:swiftrt>
163+
# The driver requires that swifrt.obj is under `usr/lib/swift/<platform>/<arch>`
164+
# Regardless of settings
161165
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}"
162166
RENAME swiftrt.obj)
163167
elseif(NOT "${SwiftCore_OBJECT_FORMAT}" STREQUAL "x")

0 commit comments

Comments
 (0)