diff --git a/cmake/px4_add_common_flags.cmake b/cmake/px4_add_common_flags.cmake index 907bff2ae2..1f125ce779 100644 --- a/cmake/px4_add_common_flags.cmake +++ b/cmake/px4_add_common_flags.cmake @@ -195,7 +195,13 @@ endfunction() function(px4_add_common_flags) - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + # clang-cl emits CMAKE_CXX_COMPILER_ID="Clang" with + # CMAKE_CXX_SIMULATE_ID="MSVC" because it is the LLVM driver running + # on top of the MSVC headers/CRT. Treat it like native MSVC for flag + # selection so we don't try to forward GCC-style switches like + # -fdata-sections that the cl-style driver rejects. + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR + (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND ("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC"))) add_compile_options( /MP /Zi