Condition SwiftPM switch based on Build Configuration

Is it possible to have selective SPM based on Scheme as dependency .

I have the following SPMs.
MainSPM => can either use SPMDebug or SPMTesting.

Here is how my package file in MainSPM looks like.

import PackageDescription

let package = Package(
    name: "MainSPM",
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "MainSPM",
            targets: ["MainSPM"]),
    ],
    dependencies: [
        .package(name: "SPMDebug", path: "../SPMDebug"),
        .package(name: "SPMTesting", path: "../SPMTesting")
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: "MainSPM",
            dependencies: [
                .byName(name: "SPMDebug"), // When Scheme is Debug
                .byName(name: "SPMTesting") // When Scheme is Test
            ]),
        .testTarget(
            name: "MainSPMTests",
            dependencies: ["MainSPM"]
        ),
    ]
)

Not today, no. And I believe we already have an issue asking for that. If not feel free to add one.

1 Like