Good news, everyone! CMake 3.26-rc1 was cut on February 1st. I landed a handful of bug fixes and improvements that will help C++ interoperability, and Swift in general. Here is an overview of what to expect:
Enhancements:
- Enable whole-module-optimizations by default for release builds. (Ninja and Xcode generators)
-
check_source_compiles(Swift ...)
configuration-time checking to determine whether the compiler you're using can compile a given piece of Swift source. (Ninja and Xcode generators) -
check_compiler_flag(Swift ...)
configuration-time checking to determine whether the compiler you're using works with a given flag. (Ninja and Xcode generators)
Bug Fixes:
-
Don't look for output-file-maps when linking a Swift library into a C/C++ library/executable. Builds with earlier versions of CMake would fail with an error like,
error: unable to load output file map 'CMakeFiles/main.dir//output-file-map.json'
when linking Swift into a C/C++ executable. With this fixed, you can now usetarget_link_libraries
to link Swift into a C/C++ executable directly. (Ninja generator) -
Improve swiftmodule dependency tracking. Intermediate static libraries weren't getting rebuilt when the public interface of their dependencies was changed. This adds the appropriate swiftmodule dependency edge from the dependency to the depender, ensuring that the library is rebuilt when the public interface of the dependency changes. This avoids strange link failures in incremental builds. (Ninja generator)
-
Don't report that swift is emitting a swiftmodule from a build target unless it actually is. In earlier CMake versions, CMake would indicate that all Swift products emit a swiftmodule, but did not actually emit a swiftmodule from executables. This resulted in Ninja always seeing the swiftmodule from executables as missing, and rebuilding/relinking the executable target, even when nothing changed. With this fixed, Ninja will see everything it expects to see, and not rebuild/relink anything. In addition, if the executable has the
ENABLE_EXPORTS
set, the target will emit a swiftmodule containing the public interface for for the exporting executable. There is a known bug at this time where an exporting executable cannot be linked into a library, so this is only somewhat useful at the moment. (You can link the executable into the library and import the associated module, but you will still have to set this up with custom commands and custom targets for this version.) (Ninja generator)