I'd like to configure my CMake project in a way, so that a single build execution targets multiple platforms (in my case I'd like to build for Linux and Windows, x86_32 and x86_64 targets each). I have the cross compiler toolchains installed and working, and building for each individual target works.
So the challenge is setting up CMake in a way, that the toolchain and the CMAKE_SYSTEM_…
variables are set appropriately for each sub-build. How can I do that?
This is not possible, in general.
CMake only allows configuring for a single target platform at once. If you want to target a different platform, you need to re-run CMake from scratch. This is even true for switching just architectures when the rest of the toolchain remains the same (for instance, you cannot build x86 and x64 binaries at the same time).
The proper way to automate this would be to have an enclosing build script which invokes CMake once for each target platform and performs several out-of-source builds to distinct binary directories. This enclosing script could also be written in CMake itself (the ExternalProject
module works quite well for this), although a general purpose scripting language like Python or Bash might be a better fit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With