### Configure Global Project Options Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Example demonstrating how to set deployment targets and execute a post-generation command like pod install within the project options. ```yaml options: deploymentTarget: watchOS: "2.0" tvOS: "10.0" postGenCommand: pod install ``` -------------------------------- ### Example Project Specification Source: https://github.com/yonaskolb/xcodegen/blob/master/README.md A sample YAML configuration defining project targets, build settings, and dependencies. ```yaml name: MyProject include: - base_spec.yml options: bundleIdPrefix: com.myapp packages: Yams: url: https://github.com/jpsim/Yams from: 2.0.0 targets: MyApp: type: application platform: iOS deploymentTarget: "10.0" sources: [MyApp] settings: configs: debug: CUSTOM_BUILD_SETTING: my_debug_value release: CUSTOM_BUILD_SETTING: my_release_value dependencies: - target: MyFramework - carthage: Alamofire - framework: Vendor/MyFramework.framework - sdk: Contacts.framework - sdk: libc++.tbd - package: Yams MyFramework: type: framework platform: iOS sources: [MyFramework] ``` -------------------------------- ### Installation via Mint Source: https://github.com/yonaskolb/xcodegen/blob/master/README.md Install XcodeGen using the Mint package manager. ```sh mint install yonaskolb/xcodegen ``` -------------------------------- ### Installation via Make Source: https://github.com/yonaskolb/xcodegen/blob/master/README.md Build and install XcodeGen from source using Make. ```shell git clone https://github.com/yonaskolb/XcodeGen.git cd XcodeGen make install ``` -------------------------------- ### Define Group Ordering Patterns Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Example showing how to define the display order of groups within the project structure, including support for regex patterns to match specific group names. ```yaml options: groupOrdering: - order: [Sources, Resources, Tests, Support files, Configurations] - pattern: '^.*Screen$' order: [View, Presenter, Interactor, Entities, Assembly] ``` -------------------------------- ### Installation via Homebrew Source: https://github.com/yonaskolb/xcodegen/blob/master/README.md Install XcodeGen using the Homebrew package manager. ```shell brew install xcodegen ``` -------------------------------- ### Override Build Settings via xcodebuild Environment Variables Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/Usage.md This example demonstrates how to override build settings directly when invoking `xcodebuild` from the command line, often used for CI environments. ```sh DEVELOPMENT_TEAM=XXXXXXXXX xcodebuild ... ``` -------------------------------- ### Utilize Scheme Templates for Reusable Configurations Source: https://context7.com/yonaskolb/xcodegen/llms.txt Define reusable scheme configurations using templates that can be applied to multiple targets. This is useful for standardizing common scheme setups, such as those for modules or features, and allows for attribute customization per target. ```yaml schemeTemplates: ModuleScheme: build: targets: ${scheme_name}: build test: gatherCoverageData: true targets: - name: ${testTarget} parallelizable: true schemes: FeatureA: templates: [ModuleScheme] templateAttributes: testTarget: FeatureATests FeatureB: templates: [ModuleScheme] templateAttributes: testTarget: FeatureBTests ``` -------------------------------- ### Define Custom Build Rules in XcodeGen Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Shows how to add build rules to a target based on file patterns or file types. It includes examples of using custom scripts or built-in compiler specifications. ```yaml targets: MyTarget: buildRules: - filePattern: "*.xcassets" script: generate_assets.py - fileType: sourcecode.swift script: pre_process_swift.py - filePattern: "*.txt" name: My Build Rule compilerSpec: com.apple.xcode.tools.swift.compiler outputFiles: - $(SRCROOT)/Generated.swift runOncePerArchitecture: false ``` -------------------------------- ### Define Breakpoint Actions Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Configures actions to trigger when a breakpoint is hit. This example shows a sound action triggered by a breakpoint. ```yaml actions: - type: Sound sound: Blow ``` -------------------------------- ### Configure Target Sources in project.yml Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md This YAML snippet demonstrates how to define target sources in an XcodeGen project. It includes examples of simple paths, path overrides, glob-based exclusions, compiler flags, and specific build phase configurations like copyFiles. ```yaml targets: MyTarget: sources: MyTargetSource MyOtherTarget: supportedDestinations: [iOS, tvOS] sources: - MyOtherTargetSource1 - path: MyOtherTargetSource2 inferDestinationFiltersByPath: true name: MyNewName excludes: - "ios/*.[mh]" - "configs/server[0-2].json" - "*-Private.h" - "**/*.md" - "ios/**/*Tests.[hm]" compilerFlags: - "-Werror" - "-Wextra" - path: MyOtherTargetSource3 destinationFilters: [iOS] compilerFlags: "-Werror -Wextra" - path: ModuleMaps buildPhase: copyFiles: destination: productsDirectory ``` -------------------------------- ### Configure Project Dependencies Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Demonstrates how to define various dependency types including local targets, Carthage frameworks with static linking, and system SDKs. ```yaml projectReferences: FooLib: path: path/to/FooLib.xcodeproj targets: MyTarget: supportedDestinations: [iOS, tvOS] dependencies: - target: MyFramework destinationFilters: [iOS] - target: FooLib/FooTarget - framework: path/to/framework.framework destinationFilters: [tvOS] - carthage: Result findFrameworks: false linkType: static destinationFilters: [iOS] - sdk: Contacts.framework - sdk: libc++.tbd - sdk: libz.dylib MyFramework: type: framework ``` -------------------------------- ### Define Simple Build Settings Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Demonstrates the basic usage of defining build settings as a simple map of key-value pairs. This approach is suitable for global settings that apply to all configurations. ```yaml settings: GENERATE_INFOPLIST_FILE: NO CODE_SIGNING_ALLOWED: NO WRAPPER_EXTENSION: bundle ``` -------------------------------- ### Advanced Build Settings with Groups and Configs Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Shows how to use advanced settings structures including base settings, configuration-specific overrides, and setting groups. Note that mixing simple maps with these advanced properties is not supported. ```yaml settings: base: PRODUCT_NAME: XcodeGenProduct configs: debug: CODE_SIGN_IDENTITY: iPhone Developer PRODUCT_BUNDLE_IDENTIFIER: com.tomtom.debug_app release: CODE_SIGN_IDENTITY: iPhone Distribution PRODUCT_BUNDLE_IDENTIFIER: com.tomtom.app PROVISIONING_PROFILE_SPECIFIER: "Xcodegen Release" groups: - my_settings ``` -------------------------------- ### Reference Setting Groups for Reusable Build Settings Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/Usage.md Demonstrates how to define reusable groups of build settings in YAML and reference them within a target's settings. This promotes consistency and reduces redundancy. ```yaml settingGroups: app: DEVELOPMENT_TEAM: T45H45J targets: App: settings: groups: [app] ``` -------------------------------- ### XcodeGen Project Specification with Includes (YAML) Source: https://context7.com/yonaskolb/xcodegen/llms.txt Demonstrates splitting project configurations into multiple files using the 'include' directive. Allows for modularity and conditional inclusion of configuration files. ```yaml # main project.yml name: MyApp include: - path: shared/base.yml - path: configs/debug.yml enable: ${INCLUDE_DEBUG_CONFIG} - path: targets/framework.yml relativePaths: false targets: MyApp: templates: [AppTemplate] sourcesREPLACE: # :REPLACE overwrites instead of merging - Sources/NewApp # shared/base.yml settingGroups: common: SWIFT_VERSION: "5.9" ENABLE_BITCODE: NO targetTemplates: AppTemplate: type: application platform: iOS settings: groups: [common] ``` -------------------------------- ### Configure Build Scripts in XcodeGen Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Demonstrates how to define preBuildScripts, postCompileScripts, and postBuildScripts in a target. It shows both path-based scripts and inline multiline scripts with various configuration options like input/output files. ```yaml targets: MyTarget: preBuildScripts: - path: myscripts/my_script.sh name: My Script inputFiles: - $(SRCROOT)/file1 - $(SRCROOT)/file2 inputFileLists: - $(SRCROOT)/inputFiles.xcfilelist outputFiles: - $(DERIVED_FILE_DIR)/file1 - $(DERIVED_FILE_DIR)/file2 outputFileLists: - $(SRCROOT)/outputFiles.xcfilelist discoveredDependencyFile: $(DERIVED_FILE_DIR)/target.d postCompileScripts: - script: swiftlint name: Swiftlint - script: | command do othercommand postBuildScripts: - path: myscripts/my_final_script.sh name: My Final Script ``` -------------------------------- ### Integrate Swift Package Dependencies Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Explains how to declare Swift Packages and link specific products or multiple products from a single package. ```yaml packages: Yams: url: https://github.com/jpsim/Yams majorVersion: 2.0.0 SwiftPM: url: https://github.com/apple/swift-package-manager branch: swift-5.0-branch targets: App: dependencies: - package: Yams - package: SwiftPM product: SPMUtility packages: FooFeature: path: Packages/FooFeature targets: App: dependencies: - package: FooFeature products: - FooDomain - FooUI ``` -------------------------------- ### Define Project and Target Settings in YAML Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/Usage.md This snippet shows how to define build settings for a project and its targets using a YAML configuration. It includes base settings, and configuration-specific settings for Debug and Release. ```yaml settings: DEVELOPMENT_TEAM: T45H45J targets: App: settings: base: CODE_SIGN_ENTITLEMENTS: App/Entitlements.entitlements configs: Debug: DEBUG_MODE: YES Release: DEBUG_MODE: NO ``` -------------------------------- ### Clone and Build XcodeGen Source: https://github.com/yonaskolb/xcodegen/blob/master/CONTRIBUTING.md Commands to clone the repository, navigate to the directory, and build the project using the provided Makefile. ```shell git clone https://github.com/yonaskolb/XcodeGen.git cd XcodeGen make ``` -------------------------------- ### Define SDK Dependencies with Custom Roots Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Shows how to specify SDK dependencies using custom root paths like DEVELOPER_DIR for specialized frameworks. ```yaml targets: MyTestTarget: dependencies: - target: MyFramework - framework: path/to/framework.framework - sdk: Contacts.framework - sdk: Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest root: DEVELOPER_DIR MyFramework: type: framework ``` -------------------------------- ### Configure Location Simulation with GPX File Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Demonstrates how to include a custom GPX file in a target's fileGroups for location simulation. This ensures the file is correctly referenced within the Xcode project structure. ```yaml targets: MyTarget: fileGroups: - location.gpx ``` -------------------------------- ### Configure Scheme Environment Variables and Test Plans Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Demonstrates how to define environment variables for build schemes and integrate external XCTestPlan files within an XcodeGen project configuration. ```yaml schemes: Production: run: environmentVariables: RUN_ENV_VAR: VALUE test: testPlans: - path: app.xctestplan defaultPlan: true environmentVariables: - variable: TEST_ENV_VAR value: VALUE isEnabled: false ``` -------------------------------- ### Project Configuration Options Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md These options configure the overall project settings and behavior. ```APIDOC ## Project Configuration Options ### Description These options define project-wide settings and behaviors for XcodeGen. ### Parameters #### Project Options - **minimumXcodeGenVersion** (String) - The minimum version of XcodeGen required. - **carthageBuildPath** (String) - The path to the carthage build directory. Defaults to `Carthage/Build`. - **carthageExecutablePath** (String) - The path to the carthage executable. Defaults to `carthage`. - **createIntermediateGroups** (Bool) - If true, intermediate groups will be created for path components. - **bundleIdPrefix** (String) - Prefix for autogenerated bundle identifiers if not explicitly set. - **settingPresets** (String) - Controls automatic build settings application. Options: `all`, `project`, `targets`, `none`. Defaults to `all`. - **developmentLanguage** (String) - Sets the development language of the project. Defaults to `en`. - **usesTabs** (Bool) - Overrides user setting for tab vs. space usage. - **indentWidth** (Int) - Overrides user setting for indent width in spaces. - **tabWidth** (Int) - Overrides user setting for tab width in spaces. - **xcodeVersion** (String) - The version of Xcode. Defaults to the latest periodically. - **projectFormat** (String) - The version of Xcode project. Options: `xcode16_3`, `xcode16_0`, `xcode15_3`, `xcode15_0`, `xcode14_0`. Defaults to `xcode16_0`. - **deploymentTarget** ([[Platform]: String]) - Project-wide deployment target for each platform. - **disabledValidations** ([String]) - List of validations to disable. Options: `missingConfigs`, `missingConfigFiles`, `missingTestPlans`. - **defaultConfig** (String) - Default configuration for command line builds. - **groupSortPosition** (String) - Where groups are sorted. Options: `none`, `top`, `bottom`. Defaults to `bottom`. - **groupOrdering** ([[GroupOrdering]]) - An order of groups. ``` -------------------------------- ### Configure Build Settings Source: https://context7.com/yonaskolb/xcodegen/llms.txt Sets project and target-level build settings. Supports base settings and configuration-specific overrides for Debug and Release builds. ```yaml settings: DEVELOPMENT_TEAM: XXXXXXXXXX SWIFT_VERSION: "5.9" targets: MyApp: settings: base: PRODUCT_NAME: MyAwesomeApp configs: Debug: SWIFT_OPTIMIZATION_LEVEL: -Onone Release: SWIFT_OPTIMIZATION_LEVEL: -O ``` -------------------------------- ### Configure Global Project Options Source: https://context7.com/yonaskolb/xcodegen/llms.txt Sets global project behavior including Xcode versions, deployment targets, directory sorting, and pre/post-generation commands. ```yaml name: MyApp options: minimumXcodeGenVersion: "2.40.0" xcodeVersion: "15.0" projectFormat: xcode16_0 bundleIdPrefix: com.mycompany developmentLanguage: en deploymentTarget: iOS: "15.0" macOS: "12.0" createIntermediateGroups: true generateEmptyDirectories: false groupSortPosition: bottom groupOrdering: - order: [Sources, Resources, Tests, Frameworks] - pattern: ".*Feature$" order: [View, ViewModel, Model] transitivelyLinkDependencies: false findCarthageFrameworks: true localPackagesGroup: Dependencies settingPresets: all defaultSourceDirectoryType: group disabledValidations: - missingConfigs - missingConfigFiles preGenCommand: ./scripts/pre-gen.sh postGenCommand: pod install fileTypes: proto: buildPhase: sources xcstrings: buildPhase: resources ``` -------------------------------- ### Scheme Build Configuration in XcodeGen Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Illustrates the configuration of build options within an XcodeGen scheme. This includes specifying which targets should be built for different build types and controlling parallelization and implicit dependency building. ```yaml targets: MyTarget: all FooLib/FooTarget: [test, run] parallelizeBuild: true buildImplicitDependencies: true ``` -------------------------------- ### Configure xcconfig File References for Build Settings Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/Usage.md This YAML configuration shows how to associate specific .xcconfig files with project-level or target-level configurations (e.g., Debug, Release). ```yaml configFiles: Debug: debug.xcconfig Release: release.xcconfig targets: App: configFiles: Debug: App/debug.xcconfig Release: App/release.xcconfig ``` -------------------------------- ### Define Scheme Templates Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Shows how to create reusable scheme templates using attribute replacement syntax to standardize build and test configurations across modular components. ```yaml schemes: MyModule: templates: - FeatureModuleScheme templateAttributes: testTargetName: MyModuleTests schemeTemplates: FeatureModuleScheme: templates: - TestScheme build: targets: ${scheme_name}: build TestScheme: test: gatherCoverageData: true targets: - name: ${testTargetName} parallelizable: true randomExecutionOrder: true ``` -------------------------------- ### Generate Plist and Entitlements Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Defines paths and key-value properties for generating Info.plist and .entitlements files during project generation. ```yaml targets: App: info: path: App/Info.plist properties: UISupportedInterfaceOrientations: [UIInterfaceOrientationPortrait] UILaunchStoryboardName: LaunchScreen entitlements: path: App/App.entitlements properties: com.apple.security.application-groups: group.com.app ``` -------------------------------- ### Target Template Usage in XcodeGen Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Demonstrates how to use target templates to define reusable configurations for targets. It shows how template attributes like 'frameworkName' can be used to customize generated targets, with `${target_name}` and `${attribute_name}` placeholders. ```yaml targets: MyFramework: templates: - Framework templateAttributes: frameworkName: AwesomeFramework sources: - SomeSources targetTemplates: Framework: platform: iOS type: framework sources: - ${frameworkName}/${target_name} ``` -------------------------------- ### Integrate Carthage Dependencies Source: https://context7.com/yonaskolb/xcodegen/llms.txt Configures automatic discovery and linking of Carthage frameworks. XcodeGen handles search paths and build phases automatically. ```yaml options: carthageBuildPath: Carthage/Build carthageExecutablePath: mint run Carthage/Carthage findCarthageFrameworks: true targets: MyApp: type: application platform: iOS dependencies: - carthage: Alamofire - carthage: ReactiveCocoa findFrameworks: true - carthage: Kingfisher linkType: static destinationFilters: [iOS] ``` -------------------------------- ### Add Build Tool Plug-ins Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Configures build tool plugins by referencing the plugin name and the package containing it. ```yaml targets: App: buildToolPlugins: - plugin: MyPlugin package: MyPackage packages: MyPackage: url: https://github.com/MyPackage from: 1.3.0 ``` -------------------------------- ### Configure Legacy Target Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Sets up a 'Legacy Target' which functions as an 'External Build Tool' in Xcode. This is useful for scripts that need to run as dependencies but should only execute once, even if depended upon by multiple targets. ```yaml legacyTarget: toolPath: "/path/to/build/tool" arguments: "build --config release" passSettings: false workingDirectory: "/path/to/working/dir" ``` -------------------------------- ### Generate Xcode Project Source: https://github.com/yonaskolb/xcodegen/blob/master/CONTRIBUTING.md Uses Swift Package Manager to generate an Xcode project file from the package definition. ```shell swift package generate-xcodeproj ``` -------------------------------- ### Define Target with Supported Destinations in YAML Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md This YAML snippet shows how to configure a target using `supportedDestinations` in XcodeGen. It specifies that the target should support iOS and tvOS destinations, with platform-specific deployment targets. It also demonstrates how to define source directories, including inferring destination filters by path and explicitly setting them. ```yaml targets: MyFramework: type: framework supportedDestinations: [iOS, tvOS] deploymentTarget: iOS: 9.0 tvOS: 10.0 sources: - path: MySources inferDestinationFiltersByPath: true - path: OtherSources destinationFilters: [iOS] ``` -------------------------------- ### Integrate XcodeGen via Swift Package Manager Source: https://context7.com/yonaskolb/xcodegen/llms.txt Configure the Package.swift file to include XcodeGen dependencies and demonstrate how to programmatically load a project specification and generate an Xcode project using the library's API. ```swift // Package.swift dependencies: [ .package(url: "https://github.com/yonaskolb/XcodeGen.git", from: "2.45.3"), ] targets: [ .target(name: "MyTool", dependencies: [ .product(name: "XcodeGenKit", package: "XcodeGen"), .product(name: "ProjectSpec", package: "XcodeGen"), ]), ] ``` ```swift import ProjectSpec import XcodeGenKit import PathKit // Load and generate project programmatically let specPath = Path("project.yml") let spec = try SpecLoader.loadSpec(path: specPath) let projectGenerator = ProjectGenerator(spec: spec) let xcodeProject = try projectGenerator.generateXcodeProject() try xcodeProject.write(path: Path("MyProject.xcodeproj")) ``` -------------------------------- ### Configuration Settings Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Defines build configurations (debug, release) and reusable setting groups for project build settings. ```APIDOC ## Configs ### Description Maps build types (`debug`, `release`) to default `Build Settings`. - **Debug**: Applies default debug build settings. - **Release**: Applies default release build settings. - Other values (e.g., `none`): No default build settings are applied. If no configs are specified, default `Debug` and `Release` configs are created automatically. ### Example Usage ```yaml configs: Debug: debug Beta: release AppStore: release ``` ## Setting Groups ### Description Named groups of `Build Settings` that can be reused across targets. - Each preset is a [Settings](#settings) schema. - Can include other `groups` or define settings by `configs`. ### Example Usage ```yaml settingGroups: preset_generic: CUSTOM_SETTING: value_custom preset_debug: BUILD_SETTING: value_debug preset_release: base: BUILD_SETTING: value_release preset_all: groups: - preset_generic configs: debug: groups: - preset_debug release: groups: - preset_release targets: Application: settings: groups: - preset_all ``` ``` -------------------------------- ### Link System SDK Dependencies Source: https://context7.com/yonaskolb/xcodegen/llms.txt Links system frameworks and libraries, including support for weak linking and custom SDK roots. ```yaml targets: MyApp: type: application platform: iOS dependencies: - sdk: UIKit.framework - sdk: libsqlite3.tbd weak: true - sdk: Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework root: DEVELOPER_DIR ``` -------------------------------- ### Link External Frameworks Source: https://context7.com/yonaskolb/xcodegen/llms.txt Links pre-built frameworks or XCFrameworks, with options for embedding and code signing. ```yaml targets: MyApp: type: application platform: iOS dependencies: - framework: Vendor/Analytics.framework embed: true codeSign: true - framework: Vendor/MyXCFramework.xcframework embed: true ``` -------------------------------- ### Configure Custom Xcode Schemes with Detailed Settings Source: https://context7.com/yonaskolb/xcodegen/llms.txt Gain full control over your Xcode scheme configurations, including build targets, run settings, test configurations, profiling, analysis, and archiving. This allows for fine-grained customization of the build and execution process. ```yaml schemes: MyApp-Debug: build: targets: MyApp: all MyFramework: [build, run, test] MyTests: [test] parallelizeBuild: true buildImplicitDependencies: true run: config: Debug executable: MyApp commandLineArguments: "-Debug": true environmentVariables: - variable: API_URL value: https://localhost isEnabled: true disableMainThreadChecker: false language: en region: US simulateLocation: allow: true defaultLocation: San Francisco, CA, USA storeKitConfiguration: StoreKit.storekit test: config: Debug gatherCoverageData: true coverageTargets: - MyApp - MyFramework targets: - name: MyAppTests parallelizable: true randomExecutionOrder: true - name: MyAppUITests skippedTests: - SlowTests/testPerformance testPlans: - path: TestPlans/Full.xctestplan defaultPlan: true - path: TestPlans/Smoke.xctestplan profile: config: Release askForAppToLaunch: false analyze: config: Debug archive: config: Release customArchiveName: MyApp-Release revealArchiveInOrganizer: true ``` -------------------------------- ### Generate Xcode Project with xcodegen Source: https://github.com/yonaskolb/xcodegen/blob/master/README.md Run this command in your project directory to generate an Xcode project. It looks for 'project.yml' by default. You can specify a different spec file using '--spec'. ```shell xcodegen generate ``` -------------------------------- ### Product Types Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Defines the type of product a target will build, influencing default build settings. Supports a wide range of Apple product types. ```APIDOC ### Product Type This will provide default build settings for a certain product type. It can be any of the following: - `application` - `application.on-demand-install-capable` - `application.messages` - `application.watchapp` - `application.watchapp2` - `application.watchapp2-container` - `app-extension` - `app-extension.intents-service` - `app-extension.messages` - `app-extension.messages-sticker-pack` - `bundle` - `bundle.ocunit-test` - `bundle.ui-testing` - `bundle.unit-test` - `extensionkit-extension` - `framework` - `instruments-package` - `library.dynamic` - `library.static` - `framework.static` - `tool` - `tv-app-extension` - `watchkit-extension` - `watchkit2-extension` - `xcode-extension` - `driver-extension` - `system-extension` - `xpc-service` - ``""`` (used for legacy targets) ``` -------------------------------- ### Integrate Swift Package Dependencies Source: https://context7.com/yonaskolb/xcodegen/llms.txt Configures remote and local Swift packages. Supports version constraints, branch references, and specific product selection for targets. ```yaml packages: Alamofire: url: https://github.com/Alamofire/Alamofire from: "5.8.0" Yams: github: jpsim/Yams from: "5.0.0" MyLocalPackage: path: ../Packages/MyLocalPackage targets: MyApp: type: application platform: iOS dependencies: - package: Alamofire - package: MyLocalPackage products: [Core, UI] embed: true ``` -------------------------------- ### Define Build Configurations Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Maps custom build configurations to standard debug or release build types. This determines the default build settings applied to the project. ```yaml configs: Debug: debug Beta: release AppStore: release ``` -------------------------------- ### Platforms Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Specifies the target platform, influencing build settings. Supports single or multiple platforms, with options for deployment targets and platform-specific settings. ```APIDOC ### Platform This will provide default build settings for a certain platform. It can be any of the following: - `auto` (available only when we use `supportedDestinations`) - `iOS` - `tvOS` - `macOS` - `watchOS` - `visionOS` (`visionOS` doesn't support Carthage usage) Note that when we use supported destinations with Xcode 14+ we can avoid the definition of platform that fallbacks to the `auto` value. **Multi Platform targets** You can also specify an array of platforms. This will generate a target for each platform. If `deploymentTarget` is specified for a multi platform target, it can have different values per platform similar to how it's defined in [Options](#options). See below for an example. If you reference the string `${platform}` anywhere within the target spec, that will be replaced with the platform. The generated targets by default will have a suffix of `_${platform}` applied, you can change this by specifying a `platformSuffix` or `platformPrefix`. If no `PRODUCT_NAME` build setting is specified for a target, this will be set to the target name, so that this target can be imported under a single name. ```yaml targets: MyFramework: sources: MyFramework platform: [iOS, tvOS] deploymentTarget: iOS: 9.0 tvOS: 10.0 type: framework settings: base: INFOPLIST_FILE: MyApp/Info.plist PRODUCT_BUNDLE_IDENTIFIER: com.myapp MY_SETTING: platform ${platform} groups: - ${platform} ``` The above will generate 2 targets named `MyFramework_iOS` and `MyFramework_tvOS`, with all the relevant platform build settings. They will both have a `PRODUCT_NAME` of `MyFramework` ``` -------------------------------- ### Basic XcodeGen Project Specification (YAML) Source: https://context7.com/yonaskolb/xcodegen/llms.txt Defines a basic Xcode project structure including name, options, configurations, settings, and targets. Specifies application type, platform, sources, and dependencies. ```yaml name: MyApp options: bundleIdPrefix: com.mycompany deploymentTarget: iOS: "15.0" macOS: "12.0" configs: Debug: debug Release: release settings: DEVELOPMENT_TEAM: XXXXXXXXXX SWIFT_VERSION: "5.9" targets: MyApp: type: application platform: iOS sources: [Sources/App] dependencies: - target: MyFramework MyFramework: type: framework platform: iOS sources: [Sources/Framework] ``` -------------------------------- ### Sources Configuration Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Specifies the source directories for a target, supporting single paths or lists of paths. XcodeGen parses source files, resources, headers, and localization files appropriately. ```APIDOC ### Sources Specifies the source directories for a target. This can either be a single source or a list of sources. Applicable source files, resources, headers, and `.lproj` files will be parsed appropriately. A source can be provided via a string (the path) or an object of the form: ``` -------------------------------- ### Create Reusable Target Templates Source: https://context7.com/yonaskolb/xcodegen/llms.txt Defines reusable target configurations to reduce duplication in the project spec. Templates can be applied to targets and overridden with specific attributes. ```yaml targetTemplates: Framework: type: framework platform: iOS deploymentTarget: "15.0" settings: base: PRODUCT_NAME: ${target_name} PRODUCT_BUNDLE_IDENTIFIER: com.mycompany.${target_name} INFOPLIST_FILE: ${target_name}/Info.plist SKIP_INSTALL: YES groups: [CommonFramework] sources: - path: ${target_name}/Sources createIntermediateGroups: true scheme: testTargets: - ${target_name}Tests FrameworkTests: type: bundle.unit-test platform: iOS sources: ${target_name}/Tests dependencies: - target: ${frameworkTarget} targets: NetworkKit: templates: [Framework] NetworkKitTests: templates: [FrameworkTests] templateAttributes: frameworkTarget: NetworkKit UIComponents: templates: [Framework] sources: - UIComponents/Sources - UIComponents/Resources ``` -------------------------------- ### Define Reusable Setting Groups Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md Creates named groups of build settings that can be reused across targets. Supports hierarchical structures and conditional settings based on build configurations. ```yaml settingGroups: preset_generic: CUSTOM_SETTING: value_custom preset_debug: BUILD_SETTING: value_debug preset_release: base: BUILD_SETTING: value_release preset_all: groups: - preset_generic configs: debug: groups: - preset_debug release: groups: - preset_release targets: Application: settings: groups: - preset_all ``` -------------------------------- ### Define Custom Build Rules Source: https://context7.com/yonaskolb/xcodegen/llms.txt Configures custom build rules for specific file types like Protobuf or Metal files. It allows specifying scripts and output files to be processed during the build phase. ```yaml targets: MyApp: type: application platform: iOS buildRules: - filePattern: "*.proto" name: Protobuf Compiler script: | protoc --swift_out=${DERIVED_FILE_DIR} ${INPUT_FILE_PATH} outputFiles: - $(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).pb.swift runOncePerArchitecture: false - fileType: sourcecode.metal script: custom-metal-compiler.sh outputFiles: - $(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).air ``` -------------------------------- ### XcodeGen Target Sources Configuration (YAML) Source: https://context7.com/yonaskolb/xcodegen/llms.txt Configures target sources with advanced options like excludes, includes, custom build phases (resources, headers, copy files), and optional files. ```yaml targets: MyApp: type: application platform: iOS sources: - path: Sources excludes: - "**/*Tests.swift" - "Internal/**" - "*.generated.swift" includes: - "**/*.swift" - "**/*.m" createIntermediateGroups: true - path: Resources type: folder buildPhase: resources - path: Headers headerVisibility: public buildPhase: headers - path: CopyFiles buildPhase: copyFiles: destination: frameworks subpath: Vendor - path: Generated optional: true # Won't fail if missing compilerFlags: ["-w"] ``` -------------------------------- ### Integrating Carthage Dependencies with XcodeGen Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/Usage.md XcodeGen simplifies Carthage integration by automatically linking and embedding frameworks. It supports automatic discovery of multiple frameworks vendored by a single Carthage dependency and allows customization of the Carthage executable path and build directory. ```yaml targets: App: dependencies: - target: Framework - carthage: Kingfisher Framework: dependencies: - carthage: Alamofire ``` ```yaml targets: App: dependencies: - carthage: ReactiveCocoa - carthage: ReactiveMapKit ``` ```yaml options: findCarthageFrameworks: true targets: App: dependencies: - carthage: ReactiveCocoa # will find ReactiveMapKit as well - carthage: OtherCarthageDependency findFrameworks: false # disables the global option ``` ```yaml options: carthageExecutablePath: mint run Carthage/Carthage ``` ```yaml options: carthageBuildPath: ../../Carthage/Build ``` -------------------------------- ### Define Reusable Setting Groups for Build Configurations Source: https://context7.com/yonaskolb/xcodegen/llms.txt Organize and reuse build settings across different targets and configurations using named setting groups. This promotes consistency and reduces duplication in your project's build settings. ```yaml settingGroups: CommonSettings: CLANG_ENABLE_MODULES: YES SWIFT_VERSION: "5.9" ENABLE_BITCODE: NO DebugSettings: ONLY_ACTIVE_ARCH: YES ENABLE_TESTABILITY: YES ReleaseSettings: ONLY_ACTIVE_ARCH: NO COPY_PHASE_STRIP: YES iOSApp: groups: [CommonSettings] base: TARGETED_DEVICE_FAMILY: "1,2" configs: Debug: groups: [DebugSettings] Release: groups: [ReleaseSettings] targets: MyApp: settings: groups: [iOSApp] base: PRODUCT_BUNDLE_IDENTIFIER: com.mycompany.app ``` -------------------------------- ### Run XcodeGen via Swift Package Manager Source: https://github.com/yonaskolb/xcodegen/blob/master/README.md Execute XcodeGen directly from the source repository using Swift Package Manager. ```shell git clone https://github.com/yonaskolb/XcodeGen.git cd XcodeGen swift run xcodegen ``` -------------------------------- ### Linking SDK Frameworks and Libraries with XcodeGen Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/Usage.md XcodeGen enables linking system frameworks and libraries using the 'sdk' dependency type. This can be done by specifying the filename with extensions like .framework, .tbd, or .dylib. ```yaml targets: App: dependencies: - sdk: Contacts.framework - sdk: libc++.tbd - sdk: libz.dylib ``` -------------------------------- ### Integrate Custom Build Scripts into Build Phases Source: https://context7.com/yonaskolb/xcodegen/llms.txt Add custom scripts to various build phases (pre-build, post-compile, post-build) of your targets. This allows for automation of tasks such as resource generation, code linting, or uploading build artifacts. ```yaml targets: MyApp: type: application platform: iOS preBuildScripts: - script: | echo "Running pre-build..." ./scripts/generate-resources.sh name: Generate Resources inputFiles: - $(SRCROOT)/Resources/config.json outputFiles: - $(DERIVED_FILE_DIR)/Generated.swift basedOnDependencyAnalysis: true postCompileScripts: - path: scripts/swiftlint.sh name: SwiftLint showEnvVars: false postBuildScripts: - script: "${PODS_ROOT}/Fabric/run" name: Upload dSYM inputFiles: - $(DWARF_DSYM_FOLDER_PATH)/$(DWARF_DSYM_FILE_NAME)/Contents/Resources/DWARF/$(TARGET_NAME) inputFileLists: - $(SRCROOT)/inputFiles.xcfilelist outputFileLists: - $(SRCROOT)/outputFiles.xcfilelist runOnlyWhenInstalling: true ``` -------------------------------- ### Reference External xcconfig Files for Build Settings Source: https://context7.com/yonaskolb/xcodegen/llms.txt Incorporate settings from external .xcconfig files into your project's build configurations. This allows for centralized management of build settings, especially for different environments like Debug and Release. ```yaml configFiles: Debug: Config/Project-Debug.xcconfig Release: Config/Project-Release.xcconfig targets: MyApp: type: application platform: iOS configFiles: Debug: Config/App-Debug.xcconfig Release: Config/App-Release.xcconfig # xcconfig settings override settingPresets but are overridden by settings ``` -------------------------------- ### Auto-Generate Info.plist and Entitlements Source: https://context7.com/yonaskolb/xcodegen/llms.txt Configures automatic generation of Info.plist and entitlements files directly from the XcodeGen spec, allowing for structured property management. ```yaml targets: MyApp: type: application platform: iOS info: path: Generated/Info.plist properties: CFBundleDisplayName: My Awesome App UILaunchStoryboardName: LaunchScreen UISupportedInterfaceOrientations: - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight UIBackgroundModes: - fetch - remote-notification NSCameraUsageDescription: Camera access for photos ITSAppUsesNonExemptEncryption: false UIApplicationSceneManifest: UIApplicationSupportsMultipleScenes: false UISceneConfigurations: {} entitlements: path: Generated/App.entitlements properties: com.apple.security.application-groups: - group.com.mycompany.app aps-environment: development com.apple.developer.associated-domains: - applinks:example.com ``` -------------------------------- ### Configure Multi-Platform Target Settings in YAML Source: https://github.com/yonaskolb/xcodegen/blob/master/Docs/ProjectSpec.md This YAML configuration demonstrates how to define a multi-platform target in XcodeGen. It specifies different deployment targets for iOS and tvOS, and uses a placeholder `${platform}` in a build setting to customize it per platform. The generated targets will have platform-specific suffixes. ```yaml targets: MyFramework: sources: MyFramework platform: [iOS, tvOS] deploymentTarget: iOS: 9.0 tvOS: 10.0 type: framework settings: base: INFOPLIST_FILE: MyApp/Info.plist PRODUCT_BUNDLE_IDENTIFIER: com.myapp MY_SETTING: platform ${platform} groups: - ${platform} ``` -------------------------------- ### Auto-Generate Target Schemes with Config Variants Source: https://context7.com/yonaskolb/xcodegen/llms.txt Automatically generate Xcode schemes for targets based on defined configuration variants. This includes setting up test targets, coverage data collection, command-line arguments, environment variables, and pre/post-build actions. ```yaml configs: Development Debug: debug Development Release: release Staging Debug: debug Staging Release: release Production Debug: debug Production Release: release targets: MyApp: type: application platform: iOS scheme: configVariants: - Development - Staging - Production testTargets: - MyAppTests - MyAppUITests gatherCoverageData: true coverageTargets: - MyFramework commandLineArguments: "-EnableLogging": true "-MockAPI": false environmentVariables: API_URL: https://dev.example.com DEBUG_MODE: "1" preActions: - script: echo "Building..." name: Pre-build postActions: - script: echo "Done!" settingsTarget: MyApp # Generates: MyApp Development, MyApp Staging, MyApp Production ``` -------------------------------- ### Generate Xcode Project CLI Commands Source: https://context7.com/yonaskolb/xcodegen/llms.txt Commands for generating Xcode projects using xcodegen. Supports specifying spec files, output directories, caching, and suppressing output. ```bash xcodegen generate xcodegen generate --spec path/to/project.yml xcodegen generate --spec project1.yml,project2.yml xcodegen generate --project path/to/output xcodegen generate --use-cache xcodegen generate --use-cache --cache-path ~/.my-cache/project xcodegen generate --quiet ```