# How to configure cmake on Windows to use clang-cl with ninja multi config for intel 32 bits, intel 64 bits and arm64 coming from Visual Studio

**URL:** https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430
**Category:** Usage
**Tags:** comp:clang, os:windows, gen:ninja
**Created:** [May 28, 2021, 1:58pm UTC](https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430 "2021-05-28T13:58:46Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![abique](https://discourse.cmake.org/user_avatar/discourse.cmake.org/abique/32/1486_2.png) [@abique](https://discourse.cmake.org/u/abique)
#### Post date: [May 28, 2021, 1:58pm UTC](https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430/1 "2021-05-28T13:58:46Z")

</div>

Hi,

How to configure cmake on Windows to use clang-cl with ninja multi config for intel 32 bits, intel 64 bits and arm64 bundled with Visual Studio?

Thank you very much!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 28, 2021, 2:04pm UTC](https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430/2 "2021-05-28T14:04:36Z")

</div>

Each of those will need a separate build tree. CMake’s multi config is about flag selection more than anything else. There’s still only a single toolchain allowed for a given language per build. If the toolchain supports fat binaries (e.g., macOS), then the compiler can be told to write multiple architectures at once, but AFAIK, Windows does not support such things.

---

<div class="post-metadata">

### Author: ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)
#### Post date: [May 28, 2021, 6:31pm UTC](https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430/3 "2021-05-28T18:31:09Z")

</div>

I believe what you want is possible using Ninja + VS + CMake:

> **[Configure and build with CMake Presets](https://docs.microsoft.com/en-us/cpp/build/cmake-presets-vs?view=msvc-160)**
>
> Reference for using CMake Presets to configure and build CMake projects.

> **[Clang/LLVM support in Visual Studio CMake projects](https://docs.microsoft.com/en-us/cpp/build/clang-support-cmake?view=msvc-160)**
>
> Learn more about: Clang/LLVM support in Visual Studio CMake projects

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [May 28, 2021, 6:37pm UTC](https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430/4 "2021-05-28T18:37:48Z")

</div>

Unfortunately, no. What OP is asking is whether it’s possible to use different compilers in a single Ninja Multi-Config build directory, which it is not. You can of course always create separate build directories with different compilers.

`CMakePresets.json` is great for storing the settings for different compilers, but it won’t allow different compilers in the same build directory.

---

<div class="post-metadata">

### Author: ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)
#### Post date: [May 28, 2021, 6:39pm UTC](https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430/5 "2021-05-28T18:39:45Z")

</div>

Oh I didn’t realize he was asking to using multiple compilers with the same build directory. Yeah that isn’t possible.

I thought the question was how to use clang-cl for x86, x64, and arm64.

---

<div class="post-metadata">

### Author: ![abique](https://discourse.cmake.org/user_avatar/discourse.cmake.org/abique/32/1486_2.png) [@abique](https://discourse.cmake.org/u/abique)
#### Post date: [May 28, 2021, 10:10pm UTC](https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430/6 "2021-05-28T22:10:37Z")

</div>

Hello, thake you for your help.  
I always planed to have 3 directories:

- cmake-builds/x86
- cmake-builds/x86\_64
- cmake-builds/aarch64

My main issue was that I needed to start a visual studio prompt first and then it could only configure correctly one target for example the x86\_64 if I started the intel 64 bits prompt, but then it would not configure correctly the intel 32 bits build directory and use the 64 bit compiler instead.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 28, 2021, 11:46pm UTC](https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430/7 "2021-05-28T23:46:10Z")

</div>

Ah. Yes, the Ninja generator requires a loaded compiler environment. FWIW, this is the same on other platforms (modules on Unix, `DEVELOPER_DIR` on Xcode). These platforms also tend to have toolchains that just work out of the box, but there’s not much to be done about that. There’s no plan to change that because there’s no way to have `ninja` reexec from `build.ninja` with the right environment (or any other generator that doesn’t itself know how to use the right toolchain as the IDE generators do).

---

<div class="post-metadata">

### Author: ![abique](https://discourse.cmake.org/user_avatar/discourse.cmake.org/abique/32/1486_2.png) [@abique](https://discourse.cmake.org/u/abique)
#### Post date: [May 29, 2021, 8:57am UTC](https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430/8 "2021-05-29T08:57:31Z")

</div>

This makes the visual studio back-end much more convenient. Because I just load the intel 64 bits environment and I can configure which architecture I want from it.  
By the way we do compile using `cmake --build` so we would not require `ninja` to reexec `ninja`.  
Also when we configure cmake, doesn’t cmake use absolute path to the tools?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 29, 2021, 11:01am UTC](https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430/9 "2021-05-29T11:01:28Z")

</div>

> [@abique](#):
>
> By the way we do compile using `cmake --build` so we would not require `ninja` to reexec `ninja`.

There’s no way to force execution through `cmake --build`, so it’s not a solution either.

> [@abique](#):
>
> Also when we configure cmake, doesn’t cmake use absolute path to the tools?

While true, the MSVC toolchains bring in the system include paths and other things through the environment; they’re not baked into the compiler or automatically derived from the compiler’s location.

---

<div class="post-metadata">

### Author: ![abique](https://discourse.cmake.org/user_avatar/discourse.cmake.org/abique/32/1486_2.png) [@abique](https://discourse.cmake.org/u/abique)
#### Post date: [May 29, 2021, 1:17pm UTC](https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430/10 "2021-05-29T13:17:58Z")

</div>

Thank you very much Ben for all those details!

How would it work then for VSCode to switch from one build directory (arm) to another (x86\_64)?  
Would I need to ensure that I have the right environment variables?

To me it would be amazing to rely upon `cmake --build` to wrap `ninja` execution and make sure the environment is correct.

I’ve more of a Linux background and for me it is very difficult to work on Windows.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 29, 2021, 5:20pm UTC](https://discourse.cmake.org/t/how-to-configure-cmake-on-windows-to-use-clang-cl-with-ninja-multi-config-for-intel-32-bits-intel-64-bits-and-arm64-coming-from-visual-studio/3430/11 "2021-05-29T17:20:54Z")

</div>

> [@abique](#):
>
> How would it work then for VSCode to switch from one build directory (arm) to another (x86\_64)?

No idea. Personally, I generally edit on my main machine and use git to pull code back down on Windows when doing development iterations.

> [@abique](#):
>
> To me it would be amazing to rely upon `cmake --build` to wrap `ninja` execution and make sure the environment is correct.

Unfortunately, the stable interface _is_ `vcvarsall.bat`, so CMake would have to start `cmd` to execute that and either have _that_ run `ninja` or somehow extract the environment settings out of it. With such a…poorly defined interface, getting CMake to do this is not really feasible.

> [@abique](#):
>
> I’ve more of a Linux background and do me it is very difficult to work on Windows.

You’re not the only one 🙂 . I would recommend using PowerShell and something like [this script](https://gitlab.kitware.com/cmake/cmake/-/blob/master/.gitlab/ci/vcvarsall.ps1) to get information from `vcvarsall.bat`.
