From 4d8510a9dca77a1849238eee319563577d54ba15 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Thu, 3 Sep 2026 14:55:17 +1200 Subject: [PATCH] build(cmake): reject QGC_BUILD_TESTING on a non-Debug build Every vehicle-level test links MockLink, which Comms/MockLink/CMakeLists.txt only builds for Debug because its app-side entry points sit behind #ifdef QT_DEBUG. Enabling testing on any other build type therefore compiles for thousands of files before dying on a bare "MockLink.h: No such file or directory" from VehicleTest.h, with nothing pointing at the actual cause. The presets already pair testing with Debug exclusively, so this is only reachable by passing -DQGC_BUILD_TESTING=ON on top of a non-Debug preset, which is exactly what tools/configure.py --testing does. Fail at configure time with a message naming both ways out. Multi-config generators are left alone: CMAKE_BUILD_TYPE carries no answer there, and the configuration is not chosen until build time. --- cmake/CustomOptions.cmake | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmake/CustomOptions.cmake b/cmake/CustomOptions.cmake index 850f8d3c8eb..68d3bed271d 100644 --- a/cmake/CustomOptions.cmake +++ b/cmake/CustomOptions.cmake @@ -47,6 +47,19 @@ option(QGC_BUILD_TESTING "Enable unit tests" ${_QGC_DEBUG_BUILD}) option(QGC_DEBUG_QML "Enable QML debugging/profiling" ${_QGC_DEBUG_BUILD}) option(QT_QML_NO_CACHEGEN "Skip qmlcachegen (faster Debug builds, slower QML startup)" ${_QGC_DEBUG_BUILD}) option(QGC_ENABLE_COVERAGE "Enable code coverage instrumentation" OFF) + +# Every vehicle-level test links MockLink, which is only built for Debug (see +# Comms/MockLink/CMakeLists.txt) because its app-side entry points are guarded by +# #ifdef QT_DEBUG. Catch the mismatch here: otherwise the build runs for thousands of +# files before dying on a bare "MockLink.h: No such file or directory". +# Multi-config generators pick the configuration at build time, so CMAKE_BUILD_TYPE +# carries no answer here and they are left to the build-time failure. +if(QGC_BUILD_TESTING AND NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + message(FATAL_ERROR + "QGC_BUILD_TESTING requires CMAKE_BUILD_TYPE=Debug, MockLink is not built for " + "'${CMAKE_BUILD_TYPE}'. Either configure a Debug build or pass -DQGC_BUILD_TESTING=OFF.") +endif() + unset(_QGC_DEBUG_BUILD) option(QGC_ENABLE_CLANG_TIDY "Enable clang-tidy static analysis during build" OFF) option(QGC_TIME_TRACE "Emit per-TU Clang -ftime-trace JSON for build profiling (Clang only)" OFF)