# How to check that the current compiler is GCC/MSYS when using Ninja generator?

**URL:** https://discourse.cmake.org/t/how-to-check-that-the-current-compiler-is-gcc-msys-when-using-ninja-generator/6698
**Category:** Code
**Tags:** os:windows, comp:gcc, gen:ninja
**Created:** [October 20, 2022, 7:12am UTC](https://discourse.cmake.org/t/how-to-check-that-the-current-compiler-is-gcc-msys-when-using-ninja-generator/6698 "2022-10-20T07:12:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)
#### Post date: [October 20, 2022, 7:12am UTC](https://discourse.cmake.org/t/how-to-check-that-the-current-compiler-is-gcc-msys-when-using-ninja-generator/6698/1 "2022-10-20T07:12:57Z")

</div>

### Problem Descriptions

There is a variable called [MSYS](https://cmake.org/cmake/help/latest/variable/MSYS.html), which is set **True** when we’re using `MSYS Makefiles` generator. However, it will be **EMPTY** if we’re using `Ninja` or `Ninja Multi-Config` generator.

I’m wondering that is there any other methods that can help us to check whether the current compiler is **GCC/MSYS** (`C:\msys64\usr\bin\gcc.exe`) when using **Ninja** or **Ninja Multi-Config** generator?

---

<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: [October 20, 2022, 5:24pm UTC](https://discourse.cmake.org/t/how-to-check-that-the-current-compiler-is-gcc-msys-when-using-ninja-generator/6698/2 "2022-10-20T17:24:23Z")

</div>

Does [`CMAKE_CXX_COMPILER_ID`](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html) help?

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [October 21, 2022, 9:55pm UTC](https://discourse.cmake.org/t/how-to-check-that-the-current-compiler-is-gcc-msys-when-using-ninja-generator/6698/3 "2022-10-21T21:55:12Z")

</div>

According to the documentation `MSYS` just indicates which make and command line interpreter is used. It’s not saying that you compiler targets for an `MSYS` environment.  
AFAIK you can do also crosscompilation in MSYS. So using that before seems to be wrong.

I would expect [CMAKE\_SYSTEM\_NAME](https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html#variable:CMAKE_SYSTEM_NAME) to hold that kind of information (and the corresponding `$<PLATFORM_ID>` generator expression)

---

<div class="post-metadata">

### Author: ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)
#### Post date: [October 22, 2022, 4:37am UTC](https://discourse.cmake.org/t/how-to-check-that-the-current-compiler-is-gcc-msys-when-using-ninja-generator/6698/4 "2022-10-22T04:37:45Z")

</div>

Actually, there is an idea which is using the output of `gcc -dumpmachine`. (from this [issue](https://github.com/conan-io/cmake-conan/issues/448#issuecomment-1281162537))

- For **GCC/MSYS** , it will print: `x86_64-pc-msys`.
- For **GCC/MINGW32** , it will print: `i686-w64-mingw32`.
- For **GCC/MINGW64** , it will print: `x86_64-w64-mingw32`.

But is there any built-in mechanism in CMake that can differentiate GCC/MSYS from the others?

---

<div class="post-metadata">

### Author: ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)
#### Post date: [November 4, 2022, 7:39am UTC](https://discourse.cmake.org/t/how-to-check-that-the-current-compiler-is-gcc-msys-when-using-ninja-generator/6698/5 "2022-11-04T07:39:02Z")

</div>

@brad.king

Based on what you said in this [issue](https://gitlab.kitware.com/cmake/cmake/-/issues/24125#note_1271317):

> If you want to build for the cygwin- or msys2-runtime libraries, instead of MinGW, you need to use a CMake that’s built for them too. MSYS2 and Cygwin both have packages for that.

And it actually worked. The **CMAKE\_SYSTEM\_NAME** will be evaluated to **“MSYS”** when using the CMake (`/c/msys64/usr/bin/cmake.exe`) installed on **MSYS**.

However, I wondered how to judge the **GCC** currently used is **MSYS2-based** when using the CMake (`C:\Program Files\CMake\bin\cmake.exe`) installed on **Windows**?

### Prerequisites

```bash
pacman -S base-devel
pacman -S gcc
pacman -S cmake
pacman -S ninja

```

### Demonstration

- Example **CMakeLists.txt**

- Example **CMakePresets.json**

- Example **Terminal Log on MSYS shell**

---

<div class="post-metadata">

### Author: ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)
#### Post date: [November 4, 2022, 7:46am UTC](https://discourse.cmake.org/t/how-to-check-that-the-current-compiler-is-gcc-msys-when-using-ninja-generator/6698/6 "2022-11-04T07:46:48Z")

</div>

@brad.king

Another thing I want to confirm is that:

Is it proper to use the CMake(`C:\Program Files\CMake\bin\cmake.exe`) installed on Windows when compiling with the following compilers?

- **GCC/MINGW32**
- **GCC/MINGW64**
- **GCC/UCRT64**
- **CLANG/CLANG32**
- **CLANG/CLANG64**
- **CLANG/CLANGARM64**

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [November 4, 2022, 3:59pm UTC](https://discourse.cmake.org/t/how-to-check-that-the-current-compiler-is-gcc-msys-when-using-ninja-generator/6698/7 "2022-11-04T15:59:26Z")

</div>

If the target platform is `Windows`, regardless of whether the target ABI is GNU-style (MinGW) or MSVC-style, then the `C:\Program Files\CMake\bin\cmake.exe` tool should work. It’s only when targeting cygwin’s or msys2’s runtime environments that one needs a CMake built for them, and such a CMake won’t work for targeting Windows. These platforms are all independent of each other and tooling cannot be mixed among them.

---

<div class="post-metadata">

### Author: ![hwhsu1231](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hwhsu1231/32/5358_2.png) [@hwhsu1231](https://discourse.cmake.org/u/hwhsu1231)
#### Post date: [November 6, 2022, 8:25am UTC](https://discourse.cmake.org/t/how-to-check-that-the-current-compiler-is-gcc-msys-when-using-ninja-generator/6698/8 "2022-11-06T08:25:04Z")

</div>

@brad.king

Is there any other differences or effects between using CMake installed on **Windows** and **MSYS2**?

The only differences that I found are:

- `CMAKE_SYSTEM_NAME`, which will print:

- Path Seperators, which will use:

Because it seems that I can actually compile an executable when using `C:\Program Files\CMake\bin\cmake.exe` with `C:\msys64\usr\bin\gcc.exe` compiler.

I wondered what else effects?
