Skip to content

Add CMake support for Swift targets and test configurations#485

Open
mitras-git wants to merge 6 commits into
apple:mainfrom
mitras-git:feature/cmake-support
Open

Add CMake support for Swift targets and test configurations#485
mitras-git wants to merge 6 commits into
apple:mainfrom
mitras-git:feature/cmake-support

Conversation

@mitras-git

@mitras-git mitras-git commented Jul 12, 2026

Copy link
Copy Markdown

Add CMake build support to the project to enable toolchain integration and bootstrapping compatibility.

Motivation:

Currently, swift-log does not support building with CMake. This addition resolves issue #484, allowing swift-log to be resolved and compiled within CMake-based environments (like the repos swift-certificates and swift-argument-parser which aer mentioned in the issue).

Modifications:

  1. Project Root Config: Added CMakeLists.txt configuring the CMake project with Swift 6 and C, alongside setting up compiler flags for MSVC runtime library on Windows.
  2. Helper Modules: Added the cmake/ folder:
    • SwiftSupport.cmake: dylib/module installations and triple detection helper.
    • SwiftLogConfig.cmake.in: package config export templates.
  3. Target CMake Configurations: Created:
    • Sources/Logging/CMakeLists.txt & Sources/InMemoryLogging/CMakeLists.txt to define the library targets. Included generator expressions pointing INTERFACE_INCLUDE_DIRECTORIES to target output directories for Xcode generator support.
    • Tests/LoggingTests/CMakeLists.txt & Tests/InMemoryLoggingTests/CMakeLists.txt to declare test targets as loadable MODULE .xctest bundles on Apple platforms, linking toolchain Testing framework and macro plugins.
  4. SwiftPM Exclusions: Excluded the new CMake files from target targets inside Package.swift and Package@swift-6.1.swift to keep SwiftPM targets warning-free.

Result:

  • SwiftPM: All 164 unit tests compile and pass successfully under swift test with no warnings.
  • CMake: Successfully compiles (** BUILD SUCCEEDED **) under Xcode generator (cmake -B build -G Xcode && cmake --build build).

Issue Tracking:

Fixes #484

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support building with CMake

1 participant