settingGroups:
  codeSigning:
    base:
      CODE_SIGN_IDENTITY: "$(inherited)"
      CODE_SIGN_ENTITLEMENTS: "$(TARGET_NAME)/$(TARGET_NAME)$(CONFIGURATION).entitlements"
    configs:
      Debug Production:
        CODE_SIGN_ENTITLEMENTS: "$(TARGET_NAME)/$(TARGET_NAME).entitlements"
      Release Development:
        PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]: "match AdHoc ${bundleIdPrefix}.$(PRODUCT_NAME)"
      Release Staging:
        # Provisioning profile is used at two stages: archive and export.
        #
        # During archive the app is built and signed. Technically provisioning profile is not embedded at this stage
        # yet but since the app is signed at this step Xcode will check that the provisioning profile has correct
        # entitlements.
        #
        # During export the provisioning profile will actually be used to package the app. This is the step where
        # Fastlane's match will instruct Xcode to use the right provisioning profile.
        PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]: "match AdHoc $(PRODUCT_BUNDLE_IDENTIFIER)"
      Release Production:
        CODE_SIGN_ENTITLEMENTS: "$(TARGET_NAME)/$(TARGET_NAME).entitlements"
        PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]: "match AdHoc $(PRODUCT_BUNDLE_IDENTIFIER)"
  extension:
    base:
      SKIP_INSTALL: "YES"
      INFOPLIST_KEY_CFBundleDisplayName: "$(TARGET_NAME)"
      LD_RUNPATH_SEARCH_PATHS: "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"
      SWIFT_EMIT_LOC_STRINGS: "YES"
      GENERATE_INFOPLIST_FILE: "YES"
      CURRENT_PROJECT_VERSION: "1"
      MARKETING_VERSION: "1.0"
targets:
  TutanotaShareExtension:
    templates: [ "formatAndLint" ]
    type: "app-extension"
    sources: "TutanotaShareExtension"
    settings:
      base:
        PRODUCT_NAME: "TutanotaShareExtension"
        PRODUCT_BUNDLE_IDENTIFIER: "$(inherited).TutanotaShareExtension"
        IPHONEOS_DEPLOYMENT_TARGET: "16.0" # Github might be running on slightly lower iOS version
        INFOPLIST_FILE: "TutanotaShareExtension/Info.plist"
        HEADER_SEARCH_PATHS: '"${PROJECT_DIR}/tutanota/include"/**'
        MARKETING_VERSION: "3.104.5"
        CLANG_CXX_LANGUAGE_STANDARD: "gnu++17"
        SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD: "NO"
        SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD: "NO"
      groups:
        - "codeSigning"
        - "extension"
    dependencies:
      - target: "TutanotaSharedFramework"
      - framework: tutasdk.framework
        embed: false
  Sqlcipher:
    type: "framework.static"
    platform: "iOS"
    sources:
      - path: "Sqlcipher"
        headerVisibility: "public"
        excludes: [
          # Exclude the framework that we are about to generate from the sources
          "**/*.a",
          # Exclude the file with explicit rule below
          "sqlite3.c"
        ]
      - path: "Sqlcipher/generated/headers/signal_tokenizer.h"
        optional: true # Generated by build script
      - path: "Sqlcipher/sqlite3.c"
        # Don't show warnings for vendored code
        compilerFlags: "-w"
    dependencies:
      - framework: "Sqlcipher/generated/libsignal_tokenizer.a"
        link: true
    settings:
      PRODUCT_NAME: "Sqlcipher"
      PRODUCT_BUNDLE_IDENTIFIER: "$(inherited).Sqlcipher"
      # HAS_CODEC needs to be here
      # https://www.zetetic.net/sqlcipher/ios-tutorial/
      GCC_PREPROCESSOR_DEFINITIONS: [
        "SQLITE_HAS_CODEC=1",
        "SQLITE_ENABLE_FTS5=1",
        "$(inherited)"
      ]
      LIBRARY_SEARCH_PATHS: "$(inherited) $(PROJECT_DIR)/Sqlcipher/generated"
      GENERATE_INFOPLIST_FILE: "YES"
      OTHER_CFLAGS:
        [
          "-DSQLITE_HAS_CODEC",
          "-DNDEBUG",
          "-DSQLCIPHER_CRYPTO_CC",
          "-DSQLITE_LIKE_DOESNT_MATCH_BLOBS",
          "-DSQLITE_OMIT_DEPRECATED",
          "-DSQLITE_OMIT_DESERIALIZE",
          "-DSQLITE_OMIT_GET_TABLE",
          "-DSQLITE_OMIT_TCL_VARIABLE",
          "-DSQLITE_OMIT_PROGRESS_CALLBACK",
          "-DSQLITE_OMIT_UTF16",
          "-DSQLITE_OMIT_COMPLETE",
          "-DSQLITE_OMIT_AUTHORIZATION",
          "-DSQLITE_DEFAULT_FOREIGN_KEYS=1",
          "-DSQLITE_DQS=0",
          "-DSQLITE_ENABLE_MATH_FUNCTIONS",
          "-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT",
          "-DSQLITE_TEMP_STORE=3",
          "-DSQLITE_THREADSAFE=1",
          "-DSQLITE_EXTRA_INIT=sqlcipher_extra_init",
          "-DSQLITE_EXTRA_SHUTDOWN=sqlcipher_extra_shutdown"
        ]
      IPHONEOS_DEPLOYMENT_TARGET: "16.0"
    preBuildScripts:
      - path: "buildScripts/compile-tokenizer.sh"
        name: "Build tokenizer with Cargo"
        shell: "/bin/bash"
        showEnvVars: true
        basedOnDependencyAnalysis: false
        outputFiles:
          [
            "$(SRCROOT)/Sqlcipher/generated/libsignal_tokenizer.a"
          ]
      - path: "buildScripts/generate-tokenizer-header.sh"
        name: "Generate tokenizer header"
        shell: "/bin/bash"
        showEnvVars: true
        # note: Xcode will show that this command has been run even when it wasn't and also show last build output.
        # Check the assistant view for the build log to verify it.
        # So dependency analysis works.
        basedOnDependencyAnalysis: true
        inputFiles:
          [
            "$(SRCROOT)/Sqlcipher/generated/libsignal_tokenizer.a"
          ]
        outputFiles:
          [
            "$(SRCROOT)/Sqlcipher/generated/headers/signal_tokenizer.h"
          ]
  TutanotaSharedFramework:
    type: "framework"
    platform: "iOS"
    sources:
      - path: "TutanotaSharedFramework"
        headerVisibility: "public"
        # Exclude TUTBigNum.h so we change it's visiblity to 'project' in another source
        excludes: [ "Crypto/TUTBigNum.h", "*.md", "Sql/sqlite3.c" ]
      - path: "TutanotaSharedFramework/Crypto"
        includes: [ "TUTBigNum.h" ]
        headerVisibility: "project"
      - path: "TutanotaSharedFramework/Sql"
        # Don't show warnings for vendored code
        includes: [ "sqlite3.c" ]
        compilerFlags: "-w"
    settings:
      PRODUCT_NAME: "TutanotaSharedFramework"
      PRODUCT_BUNDLE_IDENTIFIER: "$(inherited).TutanotaSharedFramework"
      INSTALL_PATH: "$(LOCAL_LIBRARY_DIR)/Frameworks"
      GCC_PREPROCESSOR_DEFINITIONS: [ "SQLITE_HAS_CODEC=1", "SQLITE_ENABLE_FTS5=1", "$(inherited)" ]
      OTHER_CFLAGS:
        [
          "-DSQLITE_HAS_CODEC",
          "-DSQLITE_TEMP_STORE=3",
          "-DNDEBUG",
          "-DSQLCIPHER_CRYPTO_CC",
        ]
      APPLICATION_EXTENSION_API_ONLY: "YES"
      ENABLE_USER_SCRIPT_SANDBOXING: "YES"
      SKIP_INSTALL: "YES"
      DYLIB_COMPATIBILITY_VERSION: "1"
      DYLIB_CURRENT_VERSION: "1"
      DYLIB_INSTALL_NAME_BASE: "@rpath"
      LD_RUNPATH_SEARCH_PATHS: "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"
      LOCALIZATION_PREFERS_STRING_CATALOGS: "YES"
      SWIFT_EMIT_LOC_STRINGS: "YES"
      DEFINES_MODULE: "YES"
      GENERATE_INFOPLIST_FILE: "YES"
      CODE_SIGN_STYLE: "Manual"
      CODE_SIGN_IDENTITY: "$(inherited)"
      PROVISIONING_PROFILE_SPECIFIER: ""
      CURRENT_PROJECT_VERSION: "1"
      MARKETING_VERSION: "1.0"
      VERSIONING_SYSTEM: "apple-generic"
      GCC_NO_COMMON_BLOCKS: "YES"
      CLANG_CXX_LANGUAGE_STANDARD: "gnu++20"
      ENABLE_MODULE_VERIFIER: "NO"
      MODULE_VERIFIER_SUPPORTED_LANGUAGES: "objective-c objective-c++"
      MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS: "$(GCC_C_LANGUAGE_STANDARD) $(CLANG_CXX_LANGUAGE_STANDARD)"
      SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD: "NO"
      SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD: "NO"
      ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS: "YES"
      IPHONEOS_DEPLOYMENT_TARGET: "16.0"
    dependencies:
      - package: DictionaryCoding
        product: "DictionaryCoding"
      - framework: tutasdk.framework
        # linked statically, no need to embed
        embed: false
      - framework: Sqlcipher.framework
        # linked statically, no need to embed
        embed: false
  TutanotaNotificationExtension:
    type: "app-extension"
    platform: "iOS"
    sources:
      - path: "TutanotaNotificationExtension"
    settings:
      base:
        PRODUCT_NAME: "$(TARGET_NAME)"
        SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD: "NO"
        SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD: "NO"
        GCC_NO_COMMON_BLOCKS: "YES"
        CLANG_CXX_LANGUAGE_STANDARD: "gnu++20"
        ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS: "YES"
        ENABLE_USER_SCRIPT_SANDBOXING: "YES"
        LOCALIZATION_PREFERS_STRING_CATALOGS: "YES"
        INFOPLIST_FILE: "TutanotaNotificationExtension/Info.plist"
        GENERATE_INFOPLIST_FILE: "NO"
        PRODUCT_BUNDLE_IDENTIFIER: "$(inherited).TutanotaNotificationExtension"
        IPHONEOS_DEPLOYMENT_TARGET: "16.0"
      groups:
        - "codeSigning"
        - "extension"
    dependencies:
      - target: "TutanotaSharedFramework"
      - framework: tutasdk.framework
        embed: false
targetTemplates:
  formatAndLint:
    type: "application"
    platform: "iOS"
    supportedDestinations: [ "iOS" ]
    preBuildScripts:
      - path: "buildScripts/format.sh"
        name: "Check formating with swift-format"
        shell: "/bin/sh"
        showEnvVars: true
        basedOnDependencyAnalysis: false
    postCompileScripts:
      - path: "buildScripts/lint-xcode.sh"
        name: "Lint with SwiftLint"
        shell: "/bin/sh"
        showEnvVars: true
        basedOnDependencyAnalysis: false
schemes:
  TutanotaShareExtension:
    build:
      targets:
        TutanotaShareExtension: "all"
  TutanotaSharedFramework:
    build:
      targets:
        TutanotaSharedFramework: "all"
        TutanotaSharedTests: [ "test" ]
    test:
      targets: [ "TutanotaSharedTests" ]
packages:
  DictionaryCoding:
    url: https://github.com/elegantchaos/DictionaryCoding.git
    version: 1.0.9
  Mockingbird:
    url: https://github.com/birdrides/mockingbird.git
    version: 0.20.0
  Atomics:
    url: https://github.com/apple/swift-atomics.git
    version: 1.0.2
