# Getting CMake to detect a new CXX Compiler (CXX\_COMPILER\_ID) without modying CMake's source

**URL:** https://discourse.cmake.org/t/getting-cmake-to-detect-a-new-cxx-compiler-cxx-compiler-id-without-modying-cmakes-source/916
**Category:** Usage
**Created:** [April 1, 2020, 8:47pm UTC](https://discourse.cmake.org/t/getting-cmake-to-detect-a-new-cxx-compiler-cxx-compiler-id-without-modying-cmakes-source/916 "2020-04-01T20:47:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![seanbaxter](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@seanbaxter](https://discourse.cmake.org/u/seanbaxter)
#### Post date: [April 1, 2020, 8:47pm UTC](https://discourse.cmake.org/t/getting-cmake-to-detect-a-new-cxx-compiler-cxx-compiler-id-without-modying-cmakes-source/916/1 "2020-04-01T20:47:48Z")

</div>

I wrote a new C++ compiler and am trying to get it to work with CMake. Setting CMAKE\_CXX\_COMPILER to my compiler’s path is fine: the right compiler gets invoked.

The problem is CMakeDetermineCompilerId always detects my compiler as Clang or GCC (depending on the implicit macro definitions I add to my compiler), even when I have a project toolchain/ file that sets CXX\_COMPILER\_ID and CMAKE\_CXX\_COMPILER\_ID to my compiler’s name.

How can I force detection of my compiler at project level, or register my compiler for cmake to detect without going in and actually modying cmake’s source, which seems not very scalable…

This is an issue when compiling Bloomberg/BDE, because that project’s build scripts use CXX\_COMPILER\_ID to retrieve compiler-specific command-line arguments, so it’s invoking my compiler with Clang’s arguments (which aren’t all supported).

A more detailed case of my problem is here:

> <https://github.com/bloomberg/bde/issues/258>
>
> Trying to add my compiler to the BDE toolchain, but it keeps handing my compiler the command-line arguments for Clang.
> I added...

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [April 3, 2020, 2:00pm UTC](https://discourse.cmake.org/t/getting-cmake-to-detect-a-new-cxx-compiler-cxx-compiler-id-without-modying-cmakes-source/916/2 "2020-04-03T14:00:31Z")

</div>

@brad.king Do you have any tips on getting this to work?

---

<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: [April 3, 2020, 2:48pm UTC](https://discourse.cmake.org/t/getting-cmake-to-detect-a-new-cxx-compiler-cxx-compiler-id-without-modying-cmakes-source/916/3 "2020-04-03T14:48:43Z")

</div>

It’s not currently possible to add a compiler id externally to CMake. This hasn’t been a problem historically because people just contribute their compiler id to CMake’s builtin set, and it hasn’t happened often.

The compiler id (and version information) is detected from preprocessor macros by compiling a small source file generated from e.g. `Modules/CMakeCCompilerId.c.in`. The generated compiler id detection source has a bunch of `#if` checks. They are collected from per-compiler checks located in `Modules/Compiler/*-DetermineCompiler.cmake` by logic in `Modules/CMakeCompilerIdDetection.cmake`. The latter module contains an ordered list of the builtin compiler ids. The order is important because some compilers define the builtin macros for other compilers as well as themselves.

I encourage you to add your compiler to CMake’s builtin set directly. Additionally or alternatively you could look at adding hooks in `Modules/CMakeCompilerIdDetection.cmake` to add content via externally-controlled settings, e.g. from a toolchain file.

---

<div class="post-metadata">

### Author: ![seanbaxter](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@seanbaxter](https://discourse.cmake.org/u/seanbaxter)
#### Post date: [April 3, 2020, 3:02pm UTC](https://discourse.cmake.org/t/getting-cmake-to-detect-a-new-cxx-compiler-cxx-compiler-id-without-modying-cmakes-source/916/4 "2020-04-03T15:02:06Z")

</div>

Yes, I added it to the ordered\_compilers list in that file, added a determine file, and it all works fine. Thanks.
