Skip to content

Commit cb8595a

Browse files
committed
build: adopt current best practices for installing modules
This introduces the new option to control installation to a nested subdirectory. It also converts the current installation into a thick module format.
1 parent 92042ef commit cb8595a

File tree

5 files changed

+34
-69
lines changed

5 files changed

+34
-69
lines changed

CMakeLists.txt

+8-11
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ include(DispatchAppleOptions)
118118
include(DispatchSanitization)
119119
include(DispatchCompilerWarnings)
120120
include(DTrace)
121-
include(SwiftSupport)
122121

123122
# NOTE(abdulras) this is the CMake supported way to control whether we generate
124123
# shared or static libraries. This impacts the behaviour of `add_library` in
@@ -157,6 +156,14 @@ option(INSTALL_PRIVATE_HEADERS "installs private headers in the same location as
157156
option(ENABLE_SWIFT "enable libdispatch swift overlay" OFF)
158157
if(ENABLE_SWIFT)
159158
enable_language(Swift)
159+
160+
include(PlatformInfo)
161+
162+
option(Dispatch_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" NO)
163+
set(Dispatch_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${Dispatch_PLATFORM_SUBDIR}$<$<BOOL:${Dispatch_INSTALL_NESTED_SUBDIR}>:/${Dispatch_ARCH_SUBDIR}>")
164+
set(Dispatch_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${Dispatch_PLATFORM_SUBDIR}$<$<BOOL:${Dispatch_INSTALL_NESTED_SUBDIR}>:/${Dispatch_ARCH_SUBDIR}>")
165+
else()
166+
set(Dispatch_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
160167
endif()
161168

162169
option(ENABLE_THREAD_LOCAL_STORAGE "enable usage of thread local storage via _Thread_local" ON)
@@ -307,20 +314,10 @@ add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:HAVE_CONFIG_H>)
307314

308315

309316
if(ENABLE_SWIFT)
310-
if(NOT SWIFT_SYSTEM_NAME)
311-
if(APPLE)
312-
set(SWIFT_SYSTEM_NAME macosx)
313-
else()
314-
set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
315-
endif()
316-
endif()
317-
318-
set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${SWIFT_SYSTEM_NAME}" CACHE PATH "Path where the libraries will be installed")
319317
set(INSTALL_DISPATCH_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch")
320318
set(INSTALL_BLOCK_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime")
321319
set(INSTALL_OS_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/os" CACHE PATH "Path where the os/ headers will be installed")
322320
else()
323-
set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Path where the libraries will be installed")
324321
set(INSTALL_DISPATCH_HEADERS_DIR "include/dispatch" CACHE PATH "Path where the headers will be installed")
325322
set(INSTALL_BLOCK_HEADERS_DIR "include" CACHE PATH "Path where the headers will be installed for the blocks runtime")
326323
set(INSTALL_OS_HEADERS_DIR "include/os" CACHE PATH "Path where the headers will be installed")

cmake/modules/SwiftSupport.cmake

-41
This file was deleted.

src/BlocksRuntime/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ endif()
3737
set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS BlocksRuntime)
3838
install(TARGETS BlocksRuntime
3939
EXPORT dispatchExports
40-
ARCHIVE DESTINATION ${INSTALL_TARGET_DIR}
41-
LIBRARY DESTINATION ${INSTALL_TARGET_DIR}
40+
ARCHIVE DESTINATION ${Dispatch_INSTALL_LIBDIR}
41+
LIBRARY DESTINATION ${Dispatch_INSTALL_LIBDIR}
4242
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

src/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,6 @@ endif()
189189
set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS dispatch)
190190
install(TARGETS dispatch
191191
EXPORT dispatchExports
192-
ARCHIVE DESTINATION ${INSTALL_TARGET_DIR}
193-
LIBRARY DESTINATION ${INSTALL_TARGET_DIR}
192+
ARCHIVE DESTINATION ${Dispatch_INSTALL_LIBDIR}
193+
LIBRARY DESTINATION ${Dispatch_INSTALL_LIBDIR}
194194
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

src/swift/CMakeLists.txt

+22-13
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,33 @@ target_link_libraries(swiftDispatch PRIVATE
3131
BlocksRuntime::BlocksRuntime)
3232
target_link_libraries(swiftDispatch PUBLIC
3333
dispatch)
34+
if(NOT DARWIN AND NOT WIN32)
35+
target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
36+
set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN")
37+
endif()
3438

35-
get_swift_host_arch(swift_arch)
36-
install(FILES
37-
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
38-
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftdoc
39-
DESTINATION ${INSTALL_TARGET_DIR}/${swift_arch})
40-
set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS swiftDispatch)
4139
install(TARGETS swiftDispatch
4240
EXPORT dispatchExports
43-
ARCHIVE DESTINATION ${INSTALL_TARGET_DIR}
44-
LIBRARY DESTINATION ${INSTALL_TARGET_DIR}
45-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
41+
ARCHIVE DESTINATION "${Dispatch_INSTALL_LIBDIR}"
42+
LIBRARY DESTINATION "${Dispatch_INSTALL_LIBDIR}"
43+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
44+
INSTALL(FILES $<TARGET_PROPERTY:swiftDispatch,Swift_MODULE_DIRECTORY>/$<TARGET_PROPERTY:swiftDispatch,Swift_MODULE_NAME>.swiftdoc
45+
DESTINATION ${Dispatch_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:swiftDispatch,Swift_MODULE_NAME>.swiftmodule
46+
RENAME ${Dispatch_MODULE_TRIPLE}.swiftdoc)
47+
# INSTALL(FILES $<TARGET_PROPERTY:swiftDispatch,Swift_MODULE_DIRECTORY>/$<TARGET_PROPERTY:swiftDispatch,Swift_MODULE_NAME>.swiftinterface
48+
# DESTINATION ${Dispatch_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:swiftDispatch,Swift_MODULE_NAME>.swiftmodule
49+
# RENAME ${Dispach_MODULE_TRIPLE}.swiftinterface)
50+
INSTALL(FILES $<TARGET_PROPERTY:swiftDispatch,Swift_MODULE_DIRECTORY>/$<TARGET_PROPERTY:swiftDispatch,Swift_MODULE_NAME>.swiftmodule
51+
DESTINATION ${Dispatch_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:swiftDispatch,Swift_MODULE_NAME>.swiftmodule
52+
RENAME ${Dispatch_MODULE_TRIPLE}.swiftmodule)
53+
INSTALL(FILES $<TARGET_PROPERTY:swiftDispatch,Swift_MODULE_DIRECTORY>/$<TARGET_PROPERTY:swiftDispatch,Swift_MODULE_NAME>.swiftsourceinfo
54+
DESTINATION ${Dispatch_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:swiftDispatch,Swift_MODULE_NAME>.swiftmodule
55+
RENAME ${Dispatch_MODULE_TRIPLE}.swiftsourceinfo)
4656
if(NOT BUILD_SHARED_LIBS)
4757
set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS DispatchStubs)
4858
install(TARGETS DispatchStubs
4959
EXPORT dispatchExports
50-
DESTINATION ${INSTALL_TARGET_DIR})
51-
elseif(NOT DARWIN AND NOT WIN32)
52-
target_link_options(swiftDispatch PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
53-
set_target_properties(swiftDispatch PROPERTIES INSTALL_RPATH "$ORIGIN")
60+
DESTINATION ${Dispatch_INSTALL_LIBDIR})
5461
endif()
62+
63+
set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS swiftDispatch)

0 commit comments

Comments
 (0)