I’m busy porting my build process from msbuild to cmake, to better be able to deal with the gcc toolchain (which generates much faster code for some of the numeric stuff I’m doing).
Now, I’d like cmake to generate several versions of the output, stuff like one version with sse2, another with x64, and so on. However, cmake seems to work most naturally if you simply have a bunch of flags (say, “sse2_enable”, and “platform”) and then generate one output based on those platforms.
What’s the best way to work with multiple output configurations like this? Intuitively, I’d like to iterate over a large number of flag combinations and rerun the same CMakeLists.txt files for each combination – but of course, you can’t express that within the CMakeLists.txt files (AFAIK).
There hasn’t been much activity here, so I’ve come up with a workable solution myself. It’s probably not ideal, so if you have a better idea, please do add it!
Now, it’s hard to iterate over build configs in cmake because cmake’s crucial variables don’t live in function scope – so, for instance, that means if you do
include_directories(X)the X directory will remain in the include list even after the function exits.Directories do have scope – and while normally each input directory corresponds to one output directory, you can have multiple output directories.
So, my solution looks like this:
The normal project dir then contains a
CMakeLists.txtfile with code to set up the appropriate includes and compiler options given the global variables set in theFooAllConfigsproject, and it also determines a build suffix that’s appended to all build outputs – any even indirectly included output (e.g. as generated byadd_executable) must have a unique name.This works fine for me.