Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#[[
This source file is part of the Swift Collections Open Source Project

Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

cmake_minimum_required(VERSION 3.16)
project(swift-collections
LANGUAGES C Swift)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)

if(CMAKE_SYSTEM_NAME STREQUAL Windows OR CMAKE_SYSTEM_NAME STREQUAL Darwin)
option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)
endif()

include(CTest)
include(SwiftSupport)

add_subdirectory(Sources)
# if(BUILD_TESTING)
# add_subdirectory(Tests)
# endif()

get_property(SWIFT_COLLECTIONS_EXPORTS GLOBAL PROPERTY SWIFT_COLLECTIONS_EXPORTS)
export(TARGETS ${SWIFT_COLLECTIONS_EXPORTS}
NAMESPACE SwiftCollections::
FILE swift-collections-config.cmake
EXPORT_LINK_INTERFACE_LIBRARIES)
12 changes: 12 additions & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[[
This source file is part of the Swift Collections Open Source Project

Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

add_subdirectory(Collections)
add_subdirectory(DequeModule)
add_subdirectory(OrderedCollections)
19 changes: 19 additions & 0 deletions Sources/Collections/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#[[
This source file is part of the Swift Collections Open Source Project

Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

add_library(Collections
Collections.swift)
target_link_libraries(Collections PRIVATE
DequeModule
OrderedCollections)
set_target_properties(Collections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(Collections)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS Collections)
36 changes: 36 additions & 0 deletions Sources/DequeModule/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#[[
This source file is part of the Swift Collections Open Source Project

Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

add_library(DequeModule
_DequeBuffer.swift
_DequeBufferHeader.swift
_DequeSlot.swift
_UnsafeWrappedBuffer.swift
Deque._Storage.swift
Deque._UnsafeHandle.swift
Deque.swift
Deque+Codable.swift
Deque+CustomDebugStringConvertible.swift
Deque+CustomReflectable.swift
Deque+CustomStringConvertible.swift
Deque+Equatable.swift
Deque+ExpressibleByArrayLiteral.swift
Deque+Extras.swift
Deque+Hashable.swift
Deque+MutableCollection.swift
Deque+RandomAccessCollection.swift
Deque+RangeReplaceableCollection.swift
Deque+Sequence.swift
Deque+Testing.swift
UnsafeMutableBufferPointer+Utilities.swift)
set_target_properties(DequeModule PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(DequeModule)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS DequeModule)
67 changes: 67 additions & 0 deletions Sources/OrderedCollections/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#[[
This source file is part of the Swift Collections Open Source Project

Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

add_library(OrderedCollections
"HashTable/_HashTable+Bucket.swift"
"HashTable/_HashTable+BucketIterator.swift"
"HashTable/_HashTable+Constants.swift"
"HashTable/_HashTable+CustomStringConvertible.swift"
"HashTable/_Hashtable+Header.swift"
"HashTable/_HashTable+Testing.swift"
"HashTable/_HashTable+UnsafeHandle.swift"
"HashTable/_HashTable.swift"

"OrderedDictionary/OrderedDictionary+Codable.swift"
"OrderedDictionary/OrderedDictionary+CustomDebugStringConvertible.swift"
"OrderedDictionary/OrderedDictionary+CustomReflectable.swift"
"OrderedDictionary/OrderedDictionary+CustomStringConvertible.swift"
"OrderedDictionary/OrderedDictionary+Elements+SubSequence.swift"
"OrderedDictionary/OrderedDictionary+Elements.swift"
"OrderedDictionary/OrderedDictionary+Equatable.swift"
"OrderedDictionary/OrderedDictionary+ExpressibleByDictionaryLiteral.swift"
"OrderedDictionary/OrderedDictionary+Hashable.swift"
"OrderedDictionary/OrderedDictionary+Initializers.swift"
"OrderedDictionary/OrderedDictionary+Invariants.swift"
"OrderedDictionary/OrderedDictionary+Partial MutableCollection.swift"
"OrderedDictionary/OrderedDictionary+Partial RangeReplaceableCollection.swift"
"OrderedDictionary/OrderedDictionary+Sequence.swift"
"OrderedDictionary/OrderedDictionary+Values.swift"
"OrderedDictionary/OrderedDictionary.swift"

"OrderedSet/OrderedSet+Codable.swift"
"OrderedSet/OrderedSet+CustomDebugStringConvertible.swift"
"OrderedSet/OrderedSet+CustomReflectable.swift"
"OrderedSet/OrderedSet+CustomStringConvertible.swift"
"OrderedSet/OrderedSet+Diffing.swift"
"OrderedSet/OrderedSet+Equatable.swift"
"OrderedSet/OrderedSet+ExpressibleByArrayLiteral.swift"
"OrderedSet/OrderedSet+Hashable.swift"
"OrderedSet/OrderedSet+Initializers.swift"
"OrderedSet/OrderedSet+Insertions.swift"
"OrderedSet/OrderedSet+Invariants.swift"
"OrderedSet/OrderedSet+Partial MutableCollection.swift"
"OrderedSet/OrderedSet+Partial RangeReplaceableCollection.swift"
"OrderedSet/OrderedSet+Partial SetAlgebra+Basics.swift"
"OrderedSet/OrderedSet+Partial SetAlgebra+Operations.swift"
"OrderedSet/OrderedSet+Partial SetAlgebra+Predicates.swift"
"OrderedSet/OrderedSet+RandomAccessCollection.swift"
"OrderedSet/OrderedSet+ReserveCapacity.swift"
"OrderedSet/OrderedSet+SubSequence.swift"
"OrderedSet/OrderedSet+Testing.swift"
"OrderedSet/OrderedSet+UnorderedView.swift"
"OrderedSet/OrderedSet+UnstableInternals.swift"
"OrderedSet/OrderedSet.swift"

"Utilities/_UnsafeBitset.swift"
"Utilities/RandomAccessCollection+Offsets.swift")
set_target_properties(OrderedCollections PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})

_install_target(OrderedCollections)
set_property(GLOBAL APPEND PROPERTY SWIFT_COLLECTIONS_EXPORTS OrderedCollections)
94 changes: 94 additions & 0 deletions cmake/modules/SwiftSupport.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#[[
This source file is part of the Swift Collections Open Source Project

Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
#]]

# Returns the architecture name in a variable
#
# Usage:
# get_swift_host_arch(result_var_name)
#
# Sets ${result_var_name} with the converted architecture name derived from
# CMAKE_SYSTEM_PROCESSOR.
function(get_swift_host_arch result_var_name)
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
set("${result_var_name}" "x86_64" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
set("${result_var_name}" "aarch64" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
set("${result_var_name}" "powerpc64le" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
set("${result_var_name}" "s390x" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
set("${result_var_name}" "armv6" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
set("${result_var_name}" "armv7" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
set("${result_var_name}" "armv7" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
set("${result_var_name}" "x86_64" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
set("${result_var_name}" "itanium" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
set("${result_var_name}" "i686" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
set("${result_var_name}" "i686" PARENT_SCOPE)
else()
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
endfunction()

# Returns the os name in a variable
#
# Usage:
# get_swift_host_os(result_var_name)
#
#
# Sets ${result_var_name} with the converted OS name derived from
# CMAKE_SYSTEM_NAME.
function(get_swift_host_os result_var_name)
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(${result_var_name} macosx PARENT_SCOPE)
else()
string(TOLOWER ${CMAKE_SYSTEM_NAME} cmake_system_name_lc)
set(${result_var_name} ${cmake_system_name_lc} PARENT_SCOPE)
endif()
endfunction()

function(_install_target module)
get_swift_host_os(swift_os)
get_target_property(type ${module} TYPE)

if(type STREQUAL STATIC_LIBRARY)
set(swift swift_static)
else()
set(swift swift)
endif()

install(TARGETS ${module}
ARCHIVE DESTINATION lib/${swift}/${swift_os}
LIBRARY DESTINATION lib/${swift}/${swift_os}
RUNTIME DESTINATION bin)
if(type STREQUAL EXECUTABLE)
return()
endif()

get_swift_host_arch(swift_arch)
get_target_property(module_name ${module} Swift_MODULE_NAME)
if(NOT module_name)
set(module_name ${module})
endif()

install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
RENAME ${swift_arch}.swiftdoc)
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
RENAME ${swift_arch}.swiftmodule)
endfunction()