Why CMAKE_CXX_COMPILER_ID is overwritten when using colcon?

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

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.
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

   message("WARNING "Code coverage requires Clang or GCC, ...Aborting.")

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?

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

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.