# Why CMAKE\_CXX\_COMPILER\_ID is overwritten when using colcon?

**URL:** <https://discourse.cmake.org/t/why-cmake-cxx-compiler-id-is-overwritten-when-using-colcon/8151>\
**Category:** Code\
**Created:** [May 18, 2023, 6:04am UTC](https://discourse.cmake.org/t/why-cmake-cxx-compiler-id-is-overwritten-when-using-colcon/8151 "2023-05-18T06:04:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![theateist](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/e79b87/32.png) [@theateist](https://discourse.cmake.org/u/theateist)\
**Post date:** [May 18, 2023, 6:04am UTC](https://discourse.cmake.org/t/why-cmake-cxx-compiler-id-is-overwritten-when-using-colcon/8151/1 "2023-05-18T06:04:57Z")

</div>

I’m building a workspace with `colcon build` on Windows 10 and it’s aborted with the following message:

```auto
CMake Warning at C:/colcon_ws/install/ros_industrial_cmake_boilerplate/lib/cmake/ros_industrial_cmake_boilerplate/cmake/code_coverage.cmake:182 (message):
  Code coverage requires Clang or GCC, current compilers are and MSVC.
  Aborting.
Call Stack (most recent call first):
  CMakeLists.txt:30 (initialize_code_coverage)

```

I checked `code_coverage.cmake` file and it expects `CMAKE_CXX_COMPILER_ID=Clang`

```auto
if(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang") 
   ...
else()
   message("WARNING "Code coverage requires Clang or GCC, ...Aborting.")
endif()

```

To check what `CMAKE_CXX_COMPILER_ID` is set to I added  
`message("CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")` before `if` condition and `CMAKE_CXX_COMPILER_ID` is indeed set to `MSVC`.

I decided to add `CMAKE_CXX_COMPILER_ID=Clang` to environment variables and re-opened the terminal. But, when I run `colcon build` the `CMAKE_CXX_COMPILER_ID` is set to `MSVC` again.

I checked all `CMakeLists.txt` files and none of them sets `CMAKE_CXX_COMPILER_ID`. So, who sets it? Why it’s overwritten?

---

<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 18, 2023, 12:08pm UTC](https://discourse.cmake.org/t/why-cmake-cxx-compiler-id-is-overwritten-when-using-colcon/8151/2 "2023-05-18T12:08:03Z")

</div>

It looks like you’ll have to turn off coverage if you’re building that project on Windows.

> [@theateist](#):
>
> I checked all `CMakeLists.txt` files and none of them sets `CMAKE_CXX_COMPILER_ID`. So, who sets it? Why it’s overwritten?

CMake detects it from the compiler provided. It’s not something users should ever set manually outside of a toolchain file (which describes the compiler to use). Claiming that MSVC is Clang is also unlikely to end in anything working either.
