Skip to content

Commit 904db9b

Browse files
committed
fixup! [Runtimes][CMake] Add Findmath.cmake and use it in Differentiation
Signed-off-by: Andrew Sukach <[email protected]>
1 parent 66cebdd commit 904db9b

File tree

3 files changed

+70
-44
lines changed

3 files changed

+70
-44
lines changed

Runtimes/Supplemental/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,15 @@ if(SwiftRuntime_ENABLE_stringprocessing)
4747
CMAKE_ARGS
4848
${COMMON_OPTIONS})
4949
endif()
50+
51+
52+
# Differentiation
53+
if(SwiftRuntime_ENABLE_differentiation)
54+
ExternalProject_Add(Differentiation
55+
PREFIX "Differentiation"
56+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Differentiation"
57+
INSTALL_DIR "${CMAKE_INSTALL_PREFIX}"
58+
INSTALL_COMMAND ""
59+
CMAKE_ARGS
60+
${COMMON_OPTIONS})
61+
endif()

Runtimes/Supplemental/Differentiation/CMakeLists.txt

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
cmake_minimum_required(VERSION 3.29)
22

3-
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
4-
5-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules")
6-
73
if($ENV{BUILD_NUMBER})
84
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
95
set(BUILD_NUMBER ".${BUILD_NUMBER}")
@@ -12,6 +8,11 @@ project(SwiftDifferentiation
128
LANGUAGES Swift C
139
VERSION 6.1.0${BUILD_NUMBER})
1410

11+
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
12+
set(CMAKE_Swift_LANGUAGE_VERSION 5)
13+
14+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules")
15+
1516
if(NOT PROJECT_IS_TOP_LEVEL)
1617
message(SEND_ERROR "Swift Differentiation must build as a standalone project")
1718
endif()
@@ -21,14 +22,18 @@ set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR
2122
CACHE FILEPATH "Path to the root source directory of the Swift compiler")
2223

2324
find_package(SwiftCore)
24-
find_package(math)
25+
find_package(SwiftMath)
2526

2627
include(gyb)
28+
include(AvailabilityMacros)
29+
include(CatalystSupport)
30+
include(EmitSwiftInterface)
31+
include(ResourceEmbedding)
2732

28-
option(SwiftDifferentiation_ENABLE_VECTOR_TYPES "Enable vector support"
33+
option(${PROJECT_NAME}_ENABLE_VECTOR_TYPES "Enable vector support"
2934
${SwiftCore_ENABLE_VECTOR_TYPES})
3035

31-
option(SwiftDifferentiation_ENABLE_LIBRARY_EVOLUTION "Enable library evolution"
36+
option(${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION "Enable library evolution"
3237
${SwiftCore_ENABLE_LIBRARY_EVOLUTION})
3338

3439
add_compile_options(
@@ -66,7 +71,26 @@ add_library(swift_Differentiation
6671
linker-support/magic-symbols-for-install-name.c)
6772

6873
set_target_properties(swift_Differentiation PROPERTIES
69-
Swift_MODULE_NAME _Differentiation
70-
Swift_COMPILATION_MODE wholemodule)
74+
Swift_MODULE_NAME _Differentiation)
75+
76+
if(APPLE AND BUILD_SHARED_LIBS)
77+
target_link_options(swift_Differentiation PRIVATE "SHELL:-Xlinker -headerpad_max_install_names")
78+
endif()
79+
80+
target_link_libraries(swift_Differentiation PRIVATE swiftCore SwiftMath)
81+
82+
set(${PROJECT_NAME}_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${Supplemental_INSTALL_NESTED_SUBDIR}>:/${Supplemental_PLATFORM_SUBDIR}/${Supplemental_ARCH_SUBDIR}>" CACHE STRING "")
83+
set(${PROJECT_NAME}_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${Supplemental_INSTALL_NESTED_SUBDIR}>:/${Supplemental_PLATFORM_SUBDIR}>" CACHE STRING "")
84+
85+
install(TARGETS swift_Differentiation
86+
EXPORT SwiftSupplementalTargets
87+
COMPONENT SwiftCore_runtime
88+
ARCHIVE DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}"
89+
LIBRARY DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}"
90+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
91+
emit_swift_interface(swift_Differentiation)
92+
install_swift_interface(swift_Differentiation)
7193

72-
target_link_libraries(swift_Differentiation PRIVATE swiftCore math)
94+
# Configure plist creation for Darwin platforms.
95+
generate_plist("${CMAKE_PROJECT_NAME}" "${CMAKE_PROJECT_VERSION}" swift_Differentiation)
96+
embed_manifest(swift_Differentiation)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[=======================================================================[.rst:
2-
Findmath
2+
FindSwiftMath
33
------------
44
55
Find the Swift `_math` module interface, deferring to mathConfig.cmake when
@@ -23,73 +23,63 @@ Hint Variables
2323
This only affects Linux and Windows builds.
2424
Apple builds always use the library provided by the SDK.
2525
26-
``math_STATIC``
27-
Look for the libmath static archive instead of the dynamic library.
28-
2926
Result Variables
3027
^^^^^^^^^^^^^^^^
3128
32-
The module may set the following variables if `math_DIR` is not set.
29+
The module may set the following variables if `SwiftMath_DIR` is not set.
3330
34-
``math_FOUND``
31+
``SwiftMath_FOUND``
3532
true if the `_math` module interface (and required library) were found.
3633
37-
``math_INCLUDE_DIR``
34+
``SwiftMath_INCLUDE_DIR``
3835
The directory containing the `_math.swiftinterface` file
3936
40-
``math_LIBRARIES`` OR ``math_IMPLIB``
37+
``SwiftMath_LIBRARIES`` OR ``SwiftMath_IMPLIB``
4138
the libraries to be linked
4239
4340
#]=======================================================================]
4441

4542
# If the math_DIR is specified, look there instead. The cmake-generated
4643
# config file is more accurate, but requires that the SDK has one available.
47-
if(math_DIR)
48-
if(math_FIND_REQUIRED)
44+
if(SwiftMath_DIR)
45+
if(SwiftMath_FIND_REQUIRED)
4946
list(APPEND args REQUIRED)
5047
endif()
51-
if(math_FIND_QUIETLY)
48+
if(SwiftMath_FIND_QUIETLY)
5249
list(APPEND args QUIET)
5350
endif()
54-
find_package(math NO_MODULE ${args})
51+
find_package(SwiftMath NO_MODULE ${args})
5552
return()
5653
endif()
5754

5855
include(FindPackageHandleStandardArgs)
5956
include(PlatformInfo)
6057

6158
if(APPLE)
62-
find_path(math_INCLUDE_DIR
59+
find_path(SwiftMath_INCLUDE_DIR
6360
NAMES _math.swiftmodule
6461
PATHS ${CMAKE_OSX_SYSROOT}/usr/lib/swift)
65-
find_path(math_IMPLIB
62+
find_path(SwiftMath_IMPLIB
6663
NAMES libm.tbd
6764
PATHS usr/lib)
68-
add_library(math SHARED IMPORTED GLOBAL)
69-
set_target_properties(math PROPERTIES
70-
IMPORTED_IMPLIB ${math_IMPLIB}
71-
INTERFACE_INCLUDE_DIRECTORIES ${math_INCLUDE_DIR})
72-
find_package_handle_standard_args(math DEFAULT_MSG
73-
math_IMPLIB math_INCLUDE_DIR)
65+
add_library(SwiftMath SHARED IMPORTED GLOBAL)
66+
set_target_properties(SwiftMath PROPERTIES
67+
IMPORTED_IMPLIB ${SwiftMath_IMPLIB}
68+
INTERFACE_INCLUDE_DIRECTORIES ${SwiftMath_INCLUDE_DIR})
69+
find_package_handle_standard_args(SwiftMath DEFAULT_MSG
70+
SwiftMath_IMPLIB SwiftMath_INCLUDE_DIR)
7471
elseif(LINUX)
75-
find_path(math_INCLUDE_DIR
72+
find_path(SwiftMath_INCLUDE_DIR
7673
glibc.modulemap
7774
PATHS ${Swift_SDKROOT}/usr/lib/swift/linux/${SwiftSupplemental_ARCH_SUBDIR})
78-
find_path(math_GLIBC_DIR
75+
find_path(SwiftMath_GLIBC_DIR
7976
Glibc.swiftmodule
8077
PATHS ${Swift_SDKROOT}/usr/lib/swift/linux)
81-
find_library(math_LIBRARY NAMES m)
82-
if(math_STATIC)
83-
add_library(math STATIC IMPORTED GLOBAL)
84-
else()
85-
add_library(math SHARED IMPORTED GLOBAL)
86-
endif()
87-
set_target_properties(math PROPERTIES
88-
IMPORTED_LOCATION ${math_LIBRARY}
89-
INTERFACE_INCLUDE_DIRECTORIES ${math_INCLUDE_DIR} ${math_GLIBC_DIR})
90-
find_package_handle_standard_args(math DEFAULT_MSG
91-
math_LIBRARY math_INCLUDE_DIR)
78+
add_library(SwiftMath INTERFACE IMPORTED GLOBAL)
79+
set_target_properties(SwiftMath PROPERTIES
80+
INTERFACE_INCLUDE_DIRECTORIES ${SwiftMath_INCLUDE_DIR} ${SwiftMath_GLIBC_DIR})
81+
find_package_handle_standard_args(SwiftMath DEFAULT_MSG SwiftMath_INCLUDE_DIR)
9282
else()
9383
# TODO: Windows
94-
message(FATAL_ERROR "Findmath.cmake module search not implemented for targeted platform\n")
84+
message(FATAL_ERROR "FindSwiftMath.cmake module search not implemented for targeted platform\n")
9585
endif()

0 commit comments

Comments
 (0)