Skip to content

Commit 9c16cbe

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 2e92644 commit 9c16cbe

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
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
@@ -325,9 +325,12 @@ elseif(NOT APPLE AND NOT LINUX AND NOT ANDROID AND UNIX)
325325
target_link_libraries(swiftCore PRIVATE "${EXECINFO_LIBRARY}")
326326
endif()
327327

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

Runtimes/Core/runtime/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ 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-
install(TARGETS swiftrt DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift")
152+
install(TARGETS swiftrt DESTINATION "${SwiftCore_INSTALL_LIBDIR}")
153153
elseif("${SwiftCore_OBJECT_FORMAT}" STREQUAL "coffx")
154154
add_library(swiftrt OBJECT SwiftRT-COFF.cpp)
155155
target_compile_definitions(swiftrt PRIVATE
156156
$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:SWIFT_STATIC_STDLIB>)
157157
target_link_libraries(swiftrt PRIVATE swiftShims)
158-
install(TARGETS swiftrt DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift")
158+
install(TARGETS swiftrt DESTINATION "${SwiftCore_INSTALL_LIBDIR}")
159159
elseif(NOT "${SwiftCore_OBJECT_FORMAT}" STREQUAL "x")
160160
message(SEND_ERROR "Unknown object format '${SwiftCore_OBJECT_FORMAT}'")
161161
endif()

0 commit comments

Comments
 (0)