Building statically using SwiftPM + CMake

In an ideal world I could build a static library using SPM on Windows. That feature hasn't landed yet, however.

@compnerd has suggested using CMake, but it seems like (based off of some examples on GitHub) to be an all-or-nothing alternative. Is there a way to use SPM to do the heavy lifting of the dependency-graph and use CMake to do the actual static building?

1 Like

Is there anything you have learned from exploring this topic? This is exactly the topic I need right now. For example, I am happy just to be able to build a library like The Composable Architecture with SPM and use the results in CMake.

Some of what I currently understand is
Artifacts built with SPM generate various files under paths like .build//. Here's what I've learned: building as a static lib generates a .o for each swiftmodule or target. I'm thinking that I can probably link it in CMake if I specify the swift modulename appropriately. swiftmodule is purely a header file that I'm thinking of using.

The problem is macros; I need to have CMake load macros directly as swiftc options. The module name is also needed in that case. I don't think this can be resolved automatically.

If I successfully use SPM as a library and analyze it, can I use it to build with CMake? I am not sure about this yet.