[Lldb-commits] [lldb] [lldb][CMake] Enforce lldbUtility and lldbHost layering invariants (PR #198952)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Thu May 21 03:09:24 PDT 2026
================
@@ -60,6 +60,66 @@ function(_lldb_propagate_links_liblldb name libs)
set_target_properties(${name} PROPERTIES LLDB_LINKS_LIBLLDB ${_links_liblldb})
endfunction()
+# Configure-time scan: every #include "lldb/<Module>/..." in <SOURCES> and in
+# PUBLIC_HEADER_DIR (recursive) must reference OWN_MODULE or a name in
+# ALLOWED_MODULES, otherwise FATAL_ERROR. Catches accidental cross-module
+# includes that succeed at link time (e.g. on macOS) without a corresponding
+# CMake LINK_LIBS dependency.
+function(lldb_check_header_layering target)
+ cmake_parse_arguments(HC "" "PUBLIC_HEADER_DIR;OWN_MODULE"
+ "SOURCES;ALLOWED_MODULES" ${ARGN})
+
+ set(_files)
+ foreach(src ${HC_SOURCES})
+ if(NOT IS_ABSOLUTE "${src}")
+ set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
+ endif()
+ # PARAM_UNPARSED_ARGUMENTS in add_lldb_library carries source files
+ # alongside llvm_add_library keywords like ADDITIONAL_HEADER_DIRS or
+ # LINK_COMPONENTS. Skip anything that isn't an existing file.
+ if(EXISTS "${src}" AND NOT IS_DIRECTORY "${src}")
+ list(APPEND _files "${src}")
+ endif()
+ endforeach()
+
+ if(HC_PUBLIC_HEADER_DIR AND EXISTS "${HC_PUBLIC_HEADER_DIR}")
+ file(GLOB_RECURSE _public_hdrs
+ "${HC_PUBLIC_HEADER_DIR}/*.h" "${HC_PUBLIC_HEADER_DIR}/*.hpp")
+ list(APPEND _files ${_public_hdrs})
+ endif()
+
+ set(_allowed ${HC_ALLOWED_MODULES} ${HC_OWN_MODULE})
+
+ foreach(file ${_files})
+ file(STRINGS "${file}" _includes
+ REGEX "^[ \t]*#[ \t]*include[ \t]+\"lldb/[A-Za-z_][A-Za-z0-9_]*/")
+ foreach(line ${_includes})
+ # Special case: lldb/Host/windows/windows.h is a system-header wrapper
+ # (sets NTDDI_VERSION/NOMINMAX/etc. before <windows.h> and undefs
+ # conflicting macros). It carries no module dependency but is the
+ # canonical way to pull in <windows.h> across the tree, so allow it
+ # from any target regardless of layering rules.
----------------
charles-zablit wrote:
```suggestion
# Allow Windows system-header wrapper.
```
https://github.com/llvm/llvm-project/pull/198952
More information about the lldb-commits
mailing list