diff --git a/README.md b/README.md index a3ed1e2..0281198 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,17 @@ What it does: - Checks for Ninja/Visual Studio generator (required for modules) - Sets up clang-tidy if enabled - Adds compile_commands.json copy target +- Globally injects `-Qunused-arguments` into `CMAKE_CXX_FLAGS` for Clang/AppleClang + +> [!NOTE] +> +> `-Qunused-arguments` is appended to `CMAKE_CXX_FLAGS` (not +> `add_compile_options`) so it is visible to CMake's C++20 module dependency +> scanning commands for imported targets. During scanning, `clang-scan-deps` +> passes both `--precompile` and `-c` to the compiler, making `-c` unused and +> producing noisy `clang++: warning: argument unused during compilation: '-c'` +> diagnostics. `-Qunused-arguments` suppresses this at the Clang driver level, +> where `-Wno-unused-command-line-argument` does not. ```cmake libhal_project_init() diff --git a/v5/cmake/LibhalCMakeUtilConfig.cmake b/v5/cmake/LibhalCMakeUtilConfig.cmake index 7bb4baf..2ee6a40 100644 --- a/v5/cmake/LibhalCMakeUtilConfig.cmake +++ b/v5/cmake/LibhalCMakeUtilConfig.cmake @@ -38,6 +38,17 @@ function(libhal_project_init) message(FATAL_ERROR "C++20 modules require Ninja or Visual Studio generator") endif() + # Suppress clang's "argument unused during compilation: '-c'" warning that + # fires during CMake's C++20 module dependency scanning phase. + # clang-scan-deps passes both --precompile and -c to the compiler, making + # -c unused. Using -Qunused-arguments via CMAKE_CXX_FLAGS (not + # add_compile_options) ensures the flag is visible to module scanning + # commands for imported targets. + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang") + string(APPEND CMAKE_CXX_FLAGS " -Qunused-arguments") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE) + endif() + # Set up clang-tidy if enabled libhal_setup_clang_tidy()