Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make CMake targeting multiple platforms in a single build

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?

like image 808
datenwolf Avatar asked Aug 18 '14 14:08

datenwolf


1 Answers

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.

like image 184
ComicSansMS Avatar answered Sep 23 '22 21:09

ComicSansMS