https://github.com/wenju-he created 
https://github.com/llvm/llvm-project/pull/185598

Previously, add_libclc_builtin_library added all source files' parent 
directories to include directories, resulting in many unnecessary -I flags.

Some source files include .inc files from their own directory, so adding only 
the source file's parent directory as an include path is sufficient.

Add deduplication check because different targets can share the same file.

>From 523031bd53cf893e343507ee0e6c8b3c81c03182 Mon Sep 17 00:00:00 2001
From: Wenju He <[email protected]>
Date: Tue, 10 Mar 2026 09:36:37 +0100
Subject: [PATCH] [libclc][CMake] Use per-source include flags instead of
 target-level includes

Previously, add_libclc_builtin_library added all source files' parent
directories to include directories, resulting in many unnecessary -I flags.

Some source files include .inc files from their own directory, so adding
only the source file's parent directory as an include path is sufficient.

Add deduplication check because different targets can share the same file.
---
 libclc/cmake/modules/AddLibclc.cmake | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/libclc/cmake/modules/AddLibclc.cmake 
b/libclc/cmake/modules/AddLibclc.cmake
index db99f53c8b421..2fbb22200e1a5 100644
--- a/libclc/cmake/modules/AddLibclc.cmake
+++ b/libclc/cmake/modules/AddLibclc.cmake
@@ -50,17 +50,20 @@ function(add_libclc_builtin_library target_name)
     ${ARGN}
   )
 
-  set(_inc_dirs)
+  # Append each source's parent directory as an include path to 
COMPILE_OPTIONS.
   foreach(f ${ARG_SOURCES})
-    get_filename_component(dir ${f} DIRECTORY)
-    list(APPEND _inc_dirs ${dir})
+    cmake_path(GET f PARENT_PATH parent_dir)
+    get_property(_existing SOURCE "${f}" DIRECTORY ${LIBCLC_SOURCE_DIR} 
PROPERTY COMPILE_OPTIONS)
+    if(NOT "-I${parent_dir}" IN_LIST _existing)
+      set_property(SOURCE "${f}" DIRECTORY ${LIBCLC_SOURCE_DIR}
+        APPEND PROPERTY COMPILE_OPTIONS "-I${parent_dir}")
+    endif()
   endforeach()
-  list(REMOVE_DUPLICATES _inc_dirs)
 
   add_library(${target_name} STATIC ${ARG_SOURCES})
   target_compile_options(${target_name} PRIVATE ${ARG_COMPILE_OPTIONS})
   target_include_directories(${target_name} PRIVATE
-    ${ARG_INCLUDE_DIRS} ${_inc_dirs}
+    ${ARG_INCLUDE_DIRS}
   )
   target_compile_definitions(${target_name} PRIVATE ${ARG_COMPILE_DEFINITIONS})
   set_target_properties(${target_name} PROPERTIES

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to