Standalone iOS: Archiving, exporting to ipa on the command line

I’m writing script for CI to build and ultimately end up with an ipa that can be submitted to Apple with altool

Building a properly signed .app works for me with cmake --build but it’s unclear how to get an xcarchive and from that an ipa from the built app.

How are you all doing that?

Is there a way to get CMake to do it for me or do I have to do xcodebuild archive ... and then xcodebuild -exportArchive -archivePath ... -exportPath ... -exportOptionsPlist etc?

Edit: I understand now it’s not necessary to do a cmake --build. After generating the Xcode project with CMake it’s enough to then go straight to xcodebuild archive ... and then export the result to IPA.