From b2c9e5ea10b6029b9330207b5655c894e0bae9e2 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 4 Jul 2025 05:25:27 +0200 Subject: [PATCH] cmake: gather options recursively in `curl_add_clang_tidy_test_target` Also look into `INTERFACE_INCLUDE_DIRECTORIES` target properties for include directories. Ref: #16973 Closes #17812 --- CMake/Macros.cmake | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/CMake/Macros.cmake b/CMake/Macros.cmake index 2dec0ffe6a..49ae47e706 100644 --- a/CMake/Macros.cmake +++ b/CMake/Macros.cmake @@ -96,16 +96,17 @@ macro(curl_prefill_type_size _type _size) set(SIZEOF_${_type}_CODE "#define SIZEOF_${_type} ${_size}") endmacro() -# Create a clang-tidy target for test targets -macro(curl_add_clang_tidy_test_target _target_clang_tidy _target) - if(CURL_CLANG_TIDY) - - # Collect header directories and macro definitions from lib dependencies - set(_includes_l "") - set(_definitions_l "") - get_target_property(_libs ${_target} LINK_LIBRARIES) +# Internal: Recurse into target libraries and collect their include directories +# and macro definitions. +macro(curl_collect_target_options _target) + get_target_property(_libs ${_target} LINK_LIBRARIES) + if(_libs) foreach(_lib IN LISTS _libs) if(TARGET "${_lib}") + get_target_property(_val ${_lib} INTERFACE_INCLUDE_DIRECTORIES) + if(_val) + list(APPEND _includes_l ${_val}) + endif() get_target_property(_val ${_lib} INCLUDE_DIRECTORIES) if(_val) list(APPEND _includes_l ${_val}) @@ -114,8 +115,20 @@ macro(curl_add_clang_tidy_test_target _target_clang_tidy _target) if(_val) list(APPEND _definitions_l ${_val}) endif() + curl_collect_target_options(${_lib}) endif() endforeach() + endif() +endmacro() + +# Create a clang-tidy target for test targets +macro(curl_add_clang_tidy_test_target _target_clang_tidy _target) + if(CURL_CLANG_TIDY) + + # Collect header directories and macro definitions from lib dependencies + set(_includes_l "") + set(_definitions_l "") + curl_collect_target_options(${_target}) # Collect header directories applying to the target get_directory_property(_includes_d INCLUDE_DIRECTORIES) -- 2.47.2