Is it possible to link a c++ library that requires cmake

I am unable to find any recent information regarding whether it is possible to easily integrate a swiftpm project with a c++ library that cannot be built by swiftpm.

I have a c++ library which I can build with cmake, and I would like for my swiftpm project to depend on and use it. I have tried unsuccessfully to build the c++ library with cmake first, and then copy the headers into a swiftpm target, and link to the built .a file with cxxSettings, but this did not work ("could not build Objective-C module ...").

Is what I am trying to do even possible, and if so how would I accomplish it?

1 Like

Starting with Swift 6.2 you can use static library dependencies. You can check my project on how to setup everything. If you follow the binaryTarget link inside my Package.swift you can checkout on how to setup the artifactbundle.

2 Likes

Ah, perfect, thanks! I had only found the executable artifactbundles.

Now I've just got to get the modulemap to link to openssl and find the proper include path, which shouldn't be hard

1 Like

Just that short term. But I am looking into ways we can make it easier to integrate with CMake to build such libraries. This is a good use case. Thanks!

4 Likes