|
| 1 | +cmake_minimum_required(VERSION 3.29) |
| 2 | + |
| 3 | +if($ENV{BUILD_NUMBER}) |
| 4 | + math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535") |
| 5 | + set(BUILD_NUMBER ".${BUILD_NUMBER}") |
| 6 | +endif() |
| 7 | +project(SwiftDifferentiation |
| 8 | + LANGUAGES Swift C |
| 9 | + VERSION 6.1.0${BUILD_NUMBER}) |
| 10 | + |
| 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 | + |
| 16 | +if(NOT PROJECT_IS_TOP_LEVEL) |
| 17 | + message(SEND_ERROR "Swift Differentiation must build as a standalone project") |
| 18 | +endif() |
| 19 | + |
| 20 | +set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR |
| 21 | + "${PROJECT_SOURCE_DIR}/../../../" |
| 22 | + CACHE FILEPATH "Path to the root source directory of the Swift compiler") |
| 23 | + |
| 24 | +find_package(SwiftCore) |
| 25 | + |
| 26 | +include(gyb) |
| 27 | +include(AvailabilityMacros) |
| 28 | +include(CatalystSupport) |
| 29 | +include(EmitSwiftInterface) |
| 30 | +include(ResourceEmbedding) |
| 31 | +include(InstallSwiftInterface) |
| 32 | + |
| 33 | +option(${PROJECT_NAME}_ENABLE_VECTOR_TYPES "Enable vector support" |
| 34 | + ${SwiftCore_ENABLE_VECTOR_TYPES}) |
| 35 | + |
| 36 | +option(${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION "Enable library evolution" |
| 37 | + ${SwiftCore_ENABLE_LIBRARY_EVOLUTION}) |
| 38 | + |
| 39 | +add_compile_options( |
| 40 | + $<$<COMPILE_LANGUAGE:Swift>:-explicit-module-build> |
| 41 | + $<$<COMPILE_LANGUAGE:Swift>:-nostdlibimport> |
| 42 | + $<$<COMPILE_LANGUAGE:Swift>:-parse-stdlib> |
| 43 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-library-level api>" |
| 44 | + $<$<COMPILE_LANGUAGE:Swift>:-enforce-exclusivity=unchecked> |
| 45 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-target-min-inlining-version min>" |
| 46 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NoncopyableGenerics2>" |
| 47 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SuppressedAssociatedTypes>" |
| 48 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SE427NoInferenceOnExtension>" |
| 49 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NonescapableTypes>" |
| 50 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependence>" |
| 51 | + "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature MemberImportVisibility>" |
| 52 | + $<$<AND:$<BOOL:${SwiftDifferentiation_ENABLE_LIBRARY_EVOLUTION}>,$<COMPILE_LANGUAGE:Swift>>:-enable-library-evolution>) |
| 53 | + |
| 54 | +if(SwiftDifferentiation_ENABLE_VECTOR_TYPES) |
| 55 | + gyb_expand(SIMDDifferentiation.swift.gyb SIMDDifferentiation.swift) |
| 56 | +endif() |
| 57 | +gyb_expand(TgmathDerivatives.swift.gyb TgmathDerivatives.swift) |
| 58 | +gyb_expand(FloatingPointDifferentiation.swift.gyb |
| 59 | + FloatingPointDifferentiation.swift) |
| 60 | + |
| 61 | +add_library(swift_Differentiation |
| 62 | + AnyDifferentiable.swift |
| 63 | + ArrayDifferentiation.swift |
| 64 | + Differentiable.swift |
| 65 | + DifferentialOperators.swift |
| 66 | + DifferentiationUtilities.swift |
| 67 | + OptionalDifferentiation.swift |
| 68 | + $<$<BOOL:${SwiftDifferentiation_ENABLE_VECTOR_TYPES}>:SIMDDifferentiation.swift> |
| 69 | + TgmathDerivatives.swift |
| 70 | + FloatingPointDifferentiation.swift |
| 71 | + linker-support/magic-symbols-for-install-name.c) |
| 72 | + |
| 73 | +set_target_properties(swift_Differentiation PROPERTIES |
| 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) |
| 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 ${PROJECT_NAME}_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) |
| 93 | + |
| 94 | +# Configure plist creation for Darwin platforms. |
| 95 | +generate_plist("${CMAKE_PROJECT_NAME}" "${CMAKE_PROJECT_VERSION}" swift_Differentiation) |
| 96 | +embed_manifest(swift_Differentiation) |
0 commit comments