0

I am building a crossplatform library on Windows, to target Windows, Linux, Mac, Android and iOS.

I very recently switched to CLion for several unrelated reasons. With VS, I would simply build for Windows x86/x64 through two separate configurations.

I'm trying to optimise my workflow now. My goal is to be able to hit build once, and have CLion output 32 and 64 bit builds for all of the target platforms.

How can I, if it's possible, configure CLion to build the same project through separate toolchains, with multiple architectures (i.e. x86 and x64 through MSVC, x86 and x64 through WSL, retarget for ARM, etc.)?

Daedalus
  • 86
  • 10
  • 1
    Thanks @squareskittles, I did run into that but in hindsight this is more of a CLion-specific question than CMake. I have this working now, will post an answer for reference. – Daedalus Oct 30 '19 at 21:00

1 Answers1

0

I'm posting this for future reference incase it can save anyone some time messing around. It's straightforward, I'm just not used to CLion's way of handling this and it was difficult to search for specifics.

In short;

  • Settings>Build, Execution, Deployment>CMake; create CMake profiles for your targets and their architecture variants(Win_x86_DEBUG/RELEASE, Win_x64_DEBUG/RELEASE, etc.)
  • If using MSVC, go to Settings>Build, Execution, Deployment>Toolchains and create two Visual Studio toolchains. Assign one an x86 arch and the other a x64 (you can also specify ARM variants here, though read the rest of the post as you might not have to).
  • Go back to the CMake profiles and assign the appropriate toolchain for each profile.

I had initially tried to specify compiler options directly through CMake (i.e. the -G generator flag, alongside platform specifics such as setting -m32/64 for GCC). This is fine for everything but 32-bit Windows targets. CLion uses NMAKE internally for Windows, and it does not accept the same architecture definitions which the options expose, meaning that (as far as I can tell) the specific pipe CLion is using can only send the architecture flags to CMake for generation, but it throws, and won't let you specify an architecture for Win_x86. I worked around this by creating multiple toolchains as described above. Again, the original method was fine on Win_x64- I just had the CMake profile pass the generator directly (-G "Visual Studio 15 2017 Win64").

From there you can just build all of the profiles, allowing you to compile the same project for multiple platforms and architectures at once.

Daedalus
  • 86
  • 10