From 306c277c049b3cf71a031e78f606ac9c4b42e4b7 Mon Sep 17 00:00:00 2001 From: Jan Strauss Date: Fri, 11 Jul 2025 16:49:58 +0200 Subject: [PATCH] Set -Wmissing-prototypes for clang builds. GCC defines -Wmissing-declarations as specialization of -Wmissing-prototypes for C++ (See https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmissing-declarations and https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmissing-prototypes) while Clang uses -Wmissing-prototypes for both languages and -Wmissing-declarations is a different diagnostic (See https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes and https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations). Use MATCHES against CMAKE_CXX_COMPILER_ID (See https://stackoverflow.com/a/10055571, https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html) as conditional to handle both AppleClang and Clang. Clang enables -Wmissing-declarations by default so no point in setting it only if !Clang. See also: https://github.com/llvm/llvm-project/issues/16660 https://reviews.llvm.org/D119361 --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5e032400e..ac9bb20326 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -358,6 +358,11 @@ else () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=objc-method-access") endif() + # Clang -Wmissing-declarations differs from GCC, set -Wmissing-prototypes for parity + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes") + endif() + # On mingw all code is already PIC, this will avoid compiler error on redefining this option if (NOT MINGW) set(CMAKE_POSITION_INDEPENDENT_CODE ON)