Skip to content

Commit

Permalink
[CMake] Reduce path lengths in single-module build (#392)
Browse files Browse the repository at this point in the history
* Eliminate relative paths from the cmake single-module build

* Attempt to reduce length of paths in single module build
  • Loading branch information
jmschonfeld authored Jun 26, 2024
1 parent af8349c commit 3e120b4
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 178 deletions.
30 changes: 16 additions & 14 deletions Sources/BitCollections/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]

list(APPEND COLLECTIONS_BIT_SOURCES
if(COLLECTIONS_SINGLE_MODULE)
set(module_name ${COLLECTIONS_MODULE_NAME})
else()
set(module_name BitCollections)
add_library(BitCollections
${COLLECTIONS_BIT_SOURCES})
target_link_libraries(BitCollections PRIVATE
InternalCollectionsUtilities)
set_target_properties(BitCollections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(BitCollections)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS BitCollections)
endif()

target_sources(${module_name} PRIVATE
"BitArray/BitArray+BitwiseOperations.swift"
"BitArray/BitArray+ChunkedBitsIterators.swift"
"BitArray/BitArray+Codable.swift"
Expand Down Expand Up @@ -65,16 +80,3 @@ list(APPEND COLLECTIONS_BIT_SOURCES
"Shared/UInt+Tricks.swift"
"Shared/_Word.swift"
)
set_property(GLOBAL APPEND PROPERTY COLLECTIONS_BIT_SOURCES ${COLLECTIONS_BIT_SOURCES})

if(NOT COLLECTIONS_SINGLE_MODULE)
add_library(BitCollections
${COLLECTIONS_BIT_SOURCES})
target_link_libraries(BitCollections PRIVATE
InternalCollectionsUtilities)
set_target_properties(BitCollections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(BitCollections)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS BitCollections)
endif()
51 changes: 48 additions & 3 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,58 @@ Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]

if(COLLECTIONS_SINGLE_MODULE)
if (COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE)
set(COLLECTIONS_MODULE_NAME _FoundationCollections)
set(COLLECTIONS_MODULE_TYPE STATIC)
else()
set(COLLECTIONS_MODULE_NAME Collections)
set(COLLECTIONS_MODULE_TYPE)
endif()

add_library(${COLLECTIONS_MODULE_NAME} ${COLLECTIONS_MODULE_TYPE})

if(COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE)
target_compile_options(${COLLECTIONS_MODULE_NAME} PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -allowable-client -Xfrontend FoundationEssentials>")
endif()

target_compile_definitions(${COLLECTIONS_MODULE_NAME} PRIVATE COLLECTIONS_SINGLE_MODULE)
set_target_properties(${COLLECTIONS_MODULE_NAME} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

if(COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE)
get_swift_host_os(swift_os)
if(BUILD_SHARED_LIBS)
# Install only the swift module and not the library
set(swift swift)
else()
# Install both the swift module and the binary
set(swift swift_static)
install(TARGETS ${COLLECTIONS_MODULE_NAME}
ARCHIVE DESTINATION lib/swift_static/${swift_os}
LIBRARY DESTINATION lib/swift_static/${swift_os}
RUNTIME DESTINATION bin)
endif()
get_swift_host_arch(swift_arch)
install(FILES $<TARGET_PROPERTY:${COLLECTIONS_MODULE_NAME},Swift_MODULE_DIRECTORY>/${COLLECTIONS_MODULE_NAME}.swiftdoc
DESTINATION lib/${swift}/${swift_os}/${COLLECTIONS_MODULE_NAME}.swiftmodule
RENAME ${swift_arch}.swiftdoc)
install(FILES $<TARGET_PROPERTY:${COLLECTIONS_MODULE_NAME},Swift_MODULE_DIRECTORY>/${COLLECTIONS_MODULE_NAME}.swiftmodule
DESTINATION lib/${swift}/${swift_os}/${COLLECTIONS_MODULE_NAME}.swiftmodule
RENAME ${swift_arch}.swiftmodule)
else()
_install_target(${COLLECTIONS_MODULE_NAME})
endif()
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS ${COLLECTIONS_MODULE_NAME})
else()
add_subdirectory(Collections)
endif()

add_subdirectory(BitCollections)
add_subdirectory(DequeModule)
add_subdirectory(HashTreeCollections)
add_subdirectory(HeapModule)
add_subdirectory(OrderedCollections)
add_subdirectory(RopeModule)
add_subdirectory(InternalCollectionsUtilities)

# Add Collections last so it can find global properties set by sub directories
add_subdirectory(Collections)
96 changes: 13 additions & 83 deletions Sources/Collections/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,87 +7,17 @@ Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]

if(COLLECTIONS_SINGLE_MODULE)
if (COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE)
set(COLLECTIONS_MODULE_NAME _FoundationCollections)
set(COLLECTIONS_MODULE_TYPE STATIC)
else()
set(COLLECTIONS_MODULE_NAME Collections)
set(COLLECTIONS_MODULE_TYPE)
endif()

get_property(COLLECTIONS_UTILITIES_SOURCES GLOBAL PROPERTY COLLECTIONS_UTILITIES_SOURCES)
list(TRANSFORM COLLECTIONS_UTILITIES_SOURCES PREPEND "../InternalCollectionsUtilities/")
get_property(COLLECTIONS_BIT_SOURCES GLOBAL PROPERTY COLLECTIONS_BIT_SOURCES)
list(TRANSFORM COLLECTIONS_BIT_SOURCES PREPEND "../BitCollections/")
get_property(COLLECTIONS_DEQUE_SOURCES GLOBAL PROPERTY COLLECTIONS_DEQUE_SOURCES)
list(TRANSFORM COLLECTIONS_DEQUE_SOURCES PREPEND "../DequeModule/")
get_property(COLLECTIONS_HEAP_SOURCES GLOBAL PROPERTY COLLECTIONS_HEAP_SOURCES)
list(TRANSFORM COLLECTIONS_HEAP_SOURCES PREPEND "../HeapModule/")
get_property(COLLECTIONS_ORDERED_SOURCES GLOBAL PROPERTY COLLECTIONS_ORDERED_SOURCES)
list(TRANSFORM COLLECTIONS_ORDERED_SOURCES PREPEND "../OrderedCollections/")
get_property(COLLECTIONS_HASHTREE_SOURCES GLOBAL PROPERTY COLLECTIONS_HASHTREE_SOURCES)
list(TRANSFORM COLLECTIONS_HASHTREE_SOURCES PREPEND "../HashTreeCollections/")

add_library(${COLLECTIONS_MODULE_NAME} ${COLLECTIONS_MODULE_TYPE}
"Collections.swift"
${COLLECTIONS_UTILITIES_SOURCES}
${COLLECTIONS_BIT_SOURCES}
${COLLECTIONS_DEQUE_SOURCES}
${COLLECTIONS_HEAP_SOURCES}
${COLLECTIONS_ORDERED_SOURCES}
${COLLECTIONS_HASHTREE_SOURCES})

if(COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE)
get_property(COLLECTIONS_ROPE_SOURCES GLOBAL PROPERTY COLLECTIONS_ROPE_SOURCES)
list(TRANSFORM COLLECTIONS_ROPE_SOURCES PREPEND "../RopeModule/")
target_sources(${COLLECTIONS_MODULE_NAME} PRIVATE
${COLLECTIONS_ROPE_SOURCES})
target_compile_options(${COLLECTIONS_MODULE_NAME} PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -allowable-client -Xfrontend FoundationEssentials>")
endif()

target_compile_definitions(${COLLECTIONS_MODULE_NAME} PRIVATE COLLECTIONS_SINGLE_MODULE)
set_target_properties(${COLLECTIONS_MODULE_NAME} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

if(COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE)
get_swift_host_os(swift_os)
if(BUILD_SHARED_LIBS)
# Install only the swift module and not the library
set(swift swift)
else()
# Install both the swift module and the binary
set(swift swift_static)
install(TARGETS ${COLLECTIONS_MODULE_NAME}
ARCHIVE DESTINATION lib/swift_static/${swift_os}
LIBRARY DESTINATION lib/swift_static/${swift_os}
RUNTIME DESTINATION bin)
endif()
get_swift_host_arch(swift_arch)
install(FILES $<TARGET_PROPERTY:${COLLECTIONS_MODULE_NAME},Swift_MODULE_DIRECTORY>/${COLLECTIONS_MODULE_NAME}.swiftdoc
DESTINATION lib/${swift}/${swift_os}/${COLLECTIONS_MODULE_NAME}.swiftmodule
RENAME ${swift_arch}.swiftdoc)
install(FILES $<TARGET_PROPERTY:${COLLECTIONS_MODULE_NAME},Swift_MODULE_DIRECTORY>/${COLLECTIONS_MODULE_NAME}.swiftmodule
DESTINATION lib/${swift}/${swift_os}/${COLLECTIONS_MODULE_NAME}.swiftmodule
RENAME ${swift_arch}.swiftmodule)
else()
_install_target(${COLLECTIONS_MODULE_NAME})
endif()
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS ${COLLECTIONS_MODULE_NAME})
else()
add_library(Collections
add_library(Collections
"Collections.swift")
target_link_libraries(Collections PRIVATE
BitCollections
DequeModule
HeapModule
OrderedCollections
HashTreeCollections
)
set_target_properties(Collections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(Collections)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS Collections)
endif()
target_link_libraries(Collections PRIVATE
BitCollections
DequeModule
HeapModule
OrderedCollections
HashTreeCollections
)
set_target_properties(Collections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(Collections)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS Collections)
30 changes: 16 additions & 14 deletions Sources/DequeModule/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]

list(APPEND COLLECTIONS_DEQUE_SOURCES
if(COLLECTIONS_SINGLE_MODULE)
set(module_name ${COLLECTIONS_MODULE_NAME})
else()
set(module_name DequeModule)
add_library(DequeModule
${COLLECTIONS_DEQUE_SOURCES})
target_link_libraries(DequeModule PRIVATE
InternalCollectionsUtilities)
set_target_properties(DequeModule PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(DequeModule)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS DequeModule)
endif()

target_sources(${module_name} PRIVATE
"Deque+Codable.swift"
"Deque+Collection.swift"
"Deque+CustomReflectable.swift"
Expand All @@ -26,16 +41,3 @@ list(APPEND COLLECTIONS_DEQUE_SOURCES
"_DequeSlot.swift"
"_UnsafeWrappedBuffer.swift"
)
set_property(GLOBAL APPEND PROPERTY COLLECTIONS_DEQUE_SOURCES ${COLLECTIONS_DEQUE_SOURCES})

if(NOT COLLECTIONS_SINGLE_MODULE)
add_library(DequeModule
${COLLECTIONS_DEQUE_SOURCES})
target_link_libraries(DequeModule PRIVATE
InternalCollectionsUtilities)
set_target_properties(DequeModule PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(DequeModule)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS DequeModule)
endif()
30 changes: 16 additions & 14 deletions Sources/HashTreeCollections/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]

list(APPEND COLLECTIONS_HASHTREE_SOURCES
if(COLLECTIONS_SINGLE_MODULE)
set(module_name ${COLLECTIONS_MODULE_NAME})
else()
set(module_name HashTreeCollections)
add_library(HashTreeCollections
${COLLECTIONS_HASHTREE_SOURCES})
target_link_libraries(HashTreeCollections PRIVATE
InternalCollectionsUtilities)
set_target_properties(HashTreeCollections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(HashTreeCollections)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS HashTreeCollections)
endif()

target_sources(${module_name} PRIVATE
"HashNode/_AncestorHashSlots.swift"
"HashNode/_Bitmap.swift"
"HashNode/_Bucket.swift"
Expand Down Expand Up @@ -94,16 +109,3 @@ list(APPEND COLLECTIONS_HASHTREE_SOURCES
"TreeSet/TreeSet+SetAlgebra union.swift"
"TreeSet/TreeSet.swift"
)
set_property(GLOBAL APPEND PROPERTY COLLECTIONS_HASHTREE_SOURCES ${COLLECTIONS_HASHTREE_SOURCES})

if(NOT COLLECTIONS_SINGLE_MODULE)
add_library(HashTreeCollections
${COLLECTIONS_HASHTREE_SOURCES})
target_link_libraries(HashTreeCollections PRIVATE
InternalCollectionsUtilities)
set_target_properties(HashTreeCollections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(HashTreeCollections)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS HashTreeCollections)
endif()
22 changes: 12 additions & 10 deletions Sources/HeapModule/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]

list(APPEND COLLECTIONS_HEAP_SOURCES
"_HeapNode.swift"
"Heap.swift"
"Heap+Descriptions.swift"
"Heap+ExpressibleByArrayLiteral.swift"
"Heap+Invariants.swift"
"Heap+UnsafeHandle.swift")
set_property(GLOBAL APPEND PROPERTY COLLECTIONS_HEAP_SOURCES ${COLLECTIONS_HEAP_SOURCES})

if(NOT COLLECTIONS_SINGLE_MODULE)
if(COLLECTIONS_SINGLE_MODULE)
set(module_name ${COLLECTIONS_MODULE_NAME})
else()
set(module_name HeapModule)
add_library(HeapModule
${COLLECTIONS_HEAP_SOURCES})
target_link_libraries(HeapModule PRIVATE
Expand All @@ -27,3 +21,11 @@ if(NOT COLLECTIONS_SINGLE_MODULE)
_install_target(HeapModule)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS HeapModule)
endif()

target_sources(${module_name} PRIVATE
"_HeapNode.swift"
"Heap.swift"
"Heap+Descriptions.swift"
"Heap+ExpressibleByArrayLiteral.swift"
"Heap+Invariants.swift"
"Heap+UnsafeHandle.swift")
26 changes: 14 additions & 12 deletions Sources/InternalCollectionsUtilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]

list(APPEND COLLECTIONS_UTILITIES_SOURCES
if(COLLECTIONS_SINGLE_MODULE)
set(module_name ${COLLECTIONS_MODULE_NAME})
else()
set(module_name InternalCollectionsUtilities)
add_library(InternalCollectionsUtilities
${COLLECTIONS_UTILITIES_SOURCES})
set_target_properties(InternalCollectionsUtilities PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(InternalCollectionsUtilities)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS InternalCollectionsUtilities)
endif()

target_sources(${module_name} PRIVATE
"autogenerated/Debugging.swift"
"autogenerated/Descriptions.swift"
"autogenerated/RandomAccessCollection+Offsets.swift"
Expand All @@ -27,14 +40,3 @@ list(APPEND COLLECTIONS_UTILITIES_SOURCES
"_SortedCollection.swift"
"_UniqueCollection.swift"
)
set_property(GLOBAL APPEND PROPERTY COLLECTIONS_UTILITIES_SOURCES ${COLLECTIONS_UTILITIES_SOURCES})

if(NOT COLLECTIONS_SINGLE_MODULE)
add_library(InternalCollectionsUtilities
${COLLECTIONS_UTILITIES_SOURCES})
set_target_properties(InternalCollectionsUtilities PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(InternalCollectionsUtilities)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS InternalCollectionsUtilities)
endif()
30 changes: 16 additions & 14 deletions Sources/OrderedCollections/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]

list(APPEND COLLECTIONS_ORDERED_SOURCES
if(COLLECTIONS_SINGLE_MODULE)
set(module_name ${COLLECTIONS_MODULE_NAME})
else()
set(module_name OrderedCollections)
add_library(OrderedCollections
${COLLECTIONS_ORDERED_SOURCES})
target_link_libraries(OrderedCollections PRIVATE
InternalCollectionsUtilities)
set_target_properties(OrderedCollections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(OrderedCollections)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS OrderedCollections)
endif()

target_sources(${module_name} PRIVATE
"HashTable/_HashTable.swift"
"HashTable/_HashTable+Bucket.swift"
"HashTable/_HashTable+BucketIterator.swift"
Expand Down Expand Up @@ -71,16 +86,3 @@ list(APPEND COLLECTIONS_ORDERED_SOURCES
"OrderedSet/OrderedSet.swift"
"Utilities/_UnsafeBitset.swift"
)
set_property(GLOBAL APPEND PROPERTY COLLECTIONS_ORDERED_SOURCES ${COLLECTIONS_ORDERED_SOURCES})

if(NOT COLLECTIONS_SINGLE_MODULE)
add_library(OrderedCollections
${COLLECTIONS_ORDERED_SOURCES})
target_link_libraries(OrderedCollections PRIVATE
InternalCollectionsUtilities)
set_target_properties(OrderedCollections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(OrderedCollections)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS OrderedCollections)
endif()
Loading

0 comments on commit 3e120b4

Please sign in to comment.