Skip to content

Commit f30f73e

Browse files
committed
build: add initial CMake based build system
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.
1 parent c634b5d commit f30f73e

File tree

8 files changed

+209
-0
lines changed

8 files changed

+209
-0
lines changed

CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#[[
2+
This source file is part of the Swift Numerics open source project
3+
4+
Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
#]]
9+
10+
cmake_minimum_required(VERSION 3.16)
11+
project(swift-numerics
12+
LANGUAGES Swift)
13+
14+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
15+
16+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
17+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
18+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
19+
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
20+
21+
include(SwiftSupport)
22+
23+
add_subdirectory(Sources)
24+
25+
get_property(SWIFT_NUMERICS_EXPORTS GLOBAL PROPERTY SWIFT_NUMERICS_EXPORTS)
26+
export(TARGETS ${SWIFT_NUMERICS_EXPORTS}
27+
NAMESPACE SwiftNumerics::
28+
FILE swift-numerics-config.cmake
29+
EXPORT_LINK_INTERFACE_LIBRARIES)

Sources/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[[
2+
This source file is part of the Swift Numerics open source project
3+
4+
Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
#]]
9+
10+
add_subdirectory(_NumericsShims)
11+
add_subdirectory(ComplexModule)
12+
add_subdirectory(Numerics)
13+
add_subdirectory(RealModule)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[[
2+
This source file is part of the Swift Numerics open source project
3+
4+
Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
#]]
9+
10+
add_library(ComplexModule
11+
Arithmetic.swift
12+
Complex.swift
13+
Differentiable.swift)
14+
set_target_properties(ComplexModule PROPERTIES
15+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
16+
target_link_libraries(ComplexModule PUBLIC
17+
RealModule)
18+
19+
20+
_install_target(ComplexModule)
21+
set_property(GLOBAL APPEND PROPERTY SWIFT_NUMERICS_EXPORTS ComplexModule)

Sources/Numerics/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#[[
2+
This source file is part of the Swift Numerics open source project
3+
4+
Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
#]]
9+
10+
add_library(Numerics
11+
Numerics.swift)
12+
set_target_properties(Numerics PROPERTIES
13+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
14+
target_link_libraries(Numerics PUBLIC
15+
ComplexModule
16+
RealModule)
17+
18+
19+
_install_target(Numerics)
20+
set_property(GLOBAL APPEND PROPERTY SWIFT_NUMERICS_EXPORTS Numerics)

Sources/RealModule/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#[[
2+
This source file is part of the Swift Numerics open source project
3+
4+
Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
#]]
9+
10+
add_library(RealModule
11+
AlgebraicField.swift
12+
Double+Real.swift
13+
ElementaryFunctions.swift
14+
Float+Real.swift
15+
Float80+Real.swift
16+
Real.swift
17+
RealFunctions.swift)
18+
set_target_properties(RealModule PROPERTIES
19+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
20+
target_link_libraries(RealModule PUBLIC
21+
_NumericsShims)
22+
23+
24+
_install_target(RealModule)
25+
set_property(GLOBAL APPEND PROPERTY SWIFT_NUMERICS_EXPORTS RealModule)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#[[
2+
This source file is part of the Swift Numerics open source project
3+
4+
Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
#]]
9+
10+
add_library(_NumericsShims INTERFACE)
11+
target_include_directories(_NumericsShims INTERFACE
12+
include)
13+
14+
set_property(GLOBAL APPEND PROPERTY SWIFT_NUMERICS_EXPORTS _NumericsShims)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module _NumericsShims {
2+
header "_NumericsShims.h"
3+
}

cmake/modules/SwiftSupport.cmake

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#[[
2+
This source file is part of the Swift Numerics open source project
3+
4+
Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
#]]
9+
10+
# Returns the architecture name in a variable
11+
#
12+
# Usage:
13+
# get_swift_host_arch(result_var_name)
14+
#
15+
# Sets ${result_var_name} with the converted architecture name derived from
16+
# CMAKE_SYSTEM_PROCESSOR.
17+
function(get_swift_host_arch result_var_name)
18+
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
19+
set("${result_var_name}" "x86_64" PARENT_SCOPE)
20+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
21+
set("${result_var_name}" "aarch64" PARENT_SCOPE)
22+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
23+
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
24+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
25+
set("${result_var_name}" "powerpc64le" PARENT_SCOPE)
26+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
27+
set("${result_var_name}" "s390x" PARENT_SCOPE)
28+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
29+
set("${result_var_name}" "armv6" PARENT_SCOPE)
30+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
31+
set("${result_var_name}" "armv7" PARENT_SCOPE)
32+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
33+
set("${result_var_name}" "armv7" PARENT_SCOPE)
34+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
35+
set("${result_var_name}" "x86_64" PARENT_SCOPE)
36+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
37+
set("${result_var_name}" "itanium" PARENT_SCOPE)
38+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
39+
set("${result_var_name}" "i686" PARENT_SCOPE)
40+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
41+
set("${result_var_name}" "i686" PARENT_SCOPE)
42+
else()
43+
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
44+
endif()
45+
endfunction()
46+
47+
# Returns the os name in a variable
48+
#
49+
# Usage:
50+
# get_swift_host_os(result_var_name)
51+
#
52+
#
53+
# Sets ${result_var_name} with the converted OS name derived from
54+
# CMAKE_SYSTEM_NAME.
55+
function(get_swift_host_os result_var_name)
56+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
57+
set(${result_var_name} macosx PARENT_SCOPE)
58+
else()
59+
string(TOLOWER ${CMAKE_SYSTEM_NAME} cmake_system_name_lc)
60+
set(${result_var_name} ${cmake_system_name_lc} PARENT_SCOPE)
61+
endif()
62+
endfunction()
63+
64+
function(_install_target module)
65+
get_swift_host_arch(swift_arch)
66+
get_swift_host_os(swift_os)
67+
install(TARGETS ${module}
68+
ARCHIVE DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${swift_os}
69+
LIBRARY DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${swift_os}
70+
RUNTIME DESTINATION bin)
71+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
72+
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module}.swiftdoc
73+
DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${swift_os}/${mmodule}.swiftmodule
74+
RENAME ${swift_arch}.swiftdoc)
75+
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module}.swiftmodule
76+
DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${swift_os}/${mmodule}.swiftmodule
77+
RENAME ${swift_arch}.swiftmodule)
78+
else()
79+
install(FILES
80+
$<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module}.swiftdoc
81+
$<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module}.swiftmodule
82+
DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${swift_os}/${swift_arch})
83+
endif()
84+
endfunction()

0 commit comments

Comments
 (0)