From ce12bbaefd99ad2d1efcd6897a3469cd6c0c7f03 Mon Sep 17 00:00:00 2001 From: Nuno Marques Date: Thu, 7 May 2026 18:05:59 -0700 Subject: [PATCH] build(cmake): treat clang-cl like MSVC in px4_add_common_flags clang-cl emits CMAKE_CXX_COMPILER_ID="Clang" with CMAKE_CXX_SIMULATE_ID="MSVC" because it is the LLVM driver running on top of MSVC's headers and CRT. The previous flag selector keyed strictly on CMAKE_CXX_COMPILER_ID == "MSVC", so clang-cl fell into the GCC/Clang flag branch and tried to forward switches the cl-style driver rejects (e.g. -fdata-sections, GCC-style warning toggles). Recognise the (Clang + SIMULATE_ID=MSVC) combination as the MSVC driver path so the same MSVC-flavoured flag set is applied. Native clang/AppleClang is unaffected because SIMULATE_ID is empty there. Signed-off-by: Nuno Marques --- cmake/px4_add_common_flags.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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