Merge pull request #25 from compnerd/cmake

build: add a CMake based build for Atomics
This commit is contained in:
Karoy Lorentey authored and GitHub committed 2021-08-18 19:04:26 -07:00
commit 9ded028e0d
7 files changed
+228

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
#[[
This source file is part of the Swift Atomics 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-atomics
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_ATOMICS_EXPORTS GLOBAL PROPERTY SWIFT_ATOMICS_EXPORTS)
export(TARGETS ${SWIFT_ATOMICS_EXPORTS}
NAMESPACE SwiftAtomics::
FILE swift-atomics-config.cmake
EXPORT_LINK_INTERFACE_LIBRARIES)
+31
View File
@@ -0,0 +1,31 @@
#[[
This source file is part of the Swift Atomics 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(Atomics
autogenerated/AtomicBool.swift
autogenerated/AtomicLazyReference.swift
autogenerated/HighLevelTypes.swift
autogenerated/IntegerConformances.swift
autogenerated/PointerConformances.swift
AtomicInteger.swift
AtomicMemoryOrderings.swift
AtomicOptional.swift
AtomicRawRepresentable.swift
AtomicStrongReference.swift
AtomicValue.swift
DoubleWord.swift)
set_target_properties(Atomics PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
target_compile_definitions(Atomics PRIVATE
ENABLE_DOUBLEWIDE_ATOMICS)
target_link_libraries(Atomics PUBLIC
_AtomicsShims)
_install_target(Atomics)
set_property(GLOBAL APPEND PROPERTY SWIFT_ATOMICS_EXPORTS Atomics)
+11
View File
@@ -0,0 +1,11 @@
#[[
This source file is part of the Swift Atomics Open Source Project
Copyright (c) 2020 Apple Inc. and the Swift Numerics project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]
add_subdirectory(_AtomicsShims)
add_subdirectory(Atomics)
+19
View File
@@ -0,0 +1,19 @@
#[[
This source file is part of the Swift Atomics 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(_AtomicsShims STATIC
src/_AtomicsShims.c)
target_include_directories(_AtomicsShims PUBLIC
include)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
target_compile_options(_AtomicsShims PUBLIC
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -mcx16>")
endif()
set_property(GLOBAL APPEND PROPERTY SWIFT_ATOMICS_EXPORTS _AtomicsShims)
@@ -0,0 +1,3 @@
module _AtomicsShims {
header "_AtomicsShims.h"
}
+33
View File
@@ -0,0 +1,33 @@
#[[
This source file is part of the Swift Atomics 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
#]]
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
find_package(dispatch CONFIG)
find_package(Foundation CONFIG)
endif()
find_package(XCTest CONFIG)
add_executable(AtomicsTestBundle
AtomicsTests/main.swift
AtomicsTests/autogenerated/Basics.swift
AtomicsTests/DoubleWord.swift
AtomicsTests/LifetimeTracked.swift
AtomicsTests/LockFreeQueue.swift
AtomicsTests/LockFreeSingleConsumerStack.swift
AtomicsTests/StrongReferenceRace.swift
AtomicsTests/StrongReferenceShuffle.swift
AtomicsTests/UnsafeAtomicLazyReference.swift)
target_link_libraries(AtomicsTestBundle PRIVATE
Atomics
XCTest
$<$<NOT:$<PLATFORM_ID:Darwin>>:dispatch>
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>)
add_test(NAME SwiftAtomics
COMMAND AtomicsTestBundle)
+94
View File
@@ -0,0 +1,94 @@
#[[
This source file is part of the Swift Atomics 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()