-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This adds a CMake based build, which enables the build of swift-numerics on Windows. This currently does not add the test suite to the build as there are still some issues to work out in building the full test suite which require additional math operations to fully build.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#[[ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
compnerd
Author
Contributor
|
||
This source file is part of the Swift Numerics open source project | ||
Copyright (c) 2019 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 | ||
#]] | ||
|
||
cmake_minimum_required(VERSION 3.16) | ||
project(swift-numerics | ||
LANGUAGES 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) | ||
|
||
include(SwiftSupport) | ||
|
||
add_subdirectory(Sources) | ||
|
||
get_property(SWIFT_NUMERICS_EXPORTS GLOBAL PROPERTY SWIFT_NUMERICS_EXPORTS) | ||
export(TARGETS ${SWIFT_NUMERICS_EXPORTS} | ||
NAMESPACE SwiftNumerics:: | ||
FILE swift-numerics-config.cmake | ||
EXPORT_LINK_INTERFACE_LIBRARIES) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#[[ | ||
This source file is part of the Swift Numerics open source project | ||
Copyright (c) 2019 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(_NumericsShims) | ||
add_subdirectory(ComplexModule) | ||
add_subdirectory(Numerics) | ||
add_subdirectory(RealModule) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#[[ | ||
This source file is part of the Swift Numerics open source project | ||
Copyright (c) 2019 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_library(ComplexModule | ||
Arithmetic.swift | ||
Complex.swift | ||
Differentiable.swift) | ||
set_target_properties(ComplexModule PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) | ||
target_link_libraries(ComplexModule PUBLIC | ||
RealModule) | ||
|
||
|
||
_install_target(ComplexModule) | ||
set_property(GLOBAL APPEND PROPERTY SWIFT_NUMERICS_EXPORTS ComplexModule) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#[[ | ||
This source file is part of the Swift Numerics open source project | ||
Copyright (c) 2019 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_library(Numerics | ||
Numerics.swift) | ||
set_target_properties(Numerics PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) | ||
target_link_libraries(Numerics PUBLIC | ||
ComplexModule | ||
RealModule) | ||
|
||
|
||
_install_target(Numerics) | ||
set_property(GLOBAL APPEND PROPERTY SWIFT_NUMERICS_EXPORTS Numerics) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#[[ | ||
This source file is part of the Swift Numerics open source project | ||
Copyright (c) 2019 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_library(RealModule | ||
AlgebraicField.swift | ||
Double+Real.swift | ||
ElementaryFunctions.swift | ||
Float+Real.swift | ||
Float80+Real.swift | ||
Real.swift | ||
RealFunctions.swift) | ||
set_target_properties(RealModule PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) | ||
target_link_libraries(RealModule PUBLIC | ||
_NumericsShims) | ||
|
||
|
||
_install_target(RealModule) | ||
set_property(GLOBAL APPEND PROPERTY SWIFT_NUMERICS_EXPORTS RealModule) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#[[ | ||
This source file is part of the Swift Numerics open source project | ||
Copyright (c) 2019 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_library(_NumericsShims INTERFACE) | ||
target_include_directories(_NumericsShims INTERFACE | ||
include) | ||
|
||
set_property(GLOBAL APPEND PROPERTY SWIFT_NUMERICS_EXPORTS _NumericsShims) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module _NumericsShims { | ||
header "_NumericsShims.h" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#[[ | ||
This source file is part of the Swift Numerics open source project | ||
Copyright (c) 2019 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 | ||
#]] | ||
|
||
# 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_arch(swift_arch) | ||
get_swift_host_os(swift_os) | ||
install(TARGETS ${module} | ||
ARCHIVE DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${swift_os} | ||
LIBRARY DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${swift_os} | ||
RUNTIME DESTINATION bin) | ||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin) | ||
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module}.swiftdoc | ||
DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${swift_os}/${mmodule}.swiftmodule | ||
RENAME ${swift_arch}.swiftdoc) | ||
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module}.swiftmodule | ||
DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${swift_os}/${mmodule}.swiftmodule | ||
RENAME ${swift_arch}.swiftmodule) | ||
else() | ||
install(FILES | ||
$<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module}.swiftdoc | ||
$<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module}.swiftmodule | ||
DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${swift_os}/${swift_arch}) | ||
endif() | ||
endfunction() |
@compnerd: Is a CMake-based build still required, given that SPM works on Windows?