https://github.com/wenju-he updated https://github.com/llvm/llvm-project/pull/185598
>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 1/2] [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 >From bc8064630419b67beb4236ddee4bdab8f0f71093 Mon Sep 17 00:00:00 2001 From: Wenju He <[email protected]> Date: Tue, 10 Mar 2026 12:17:24 +0100 Subject: [PATCH 2/2] move to libclc_configure_source_list --- libclc/cmake/modules/AddLibclc.cmake | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 2fbb22200e1a5..2ef26f464d82c 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -1,8 +1,23 @@ # Converts a list of relative source paths to absolute paths and exports -# it to the parent scope. +# it to the parent scope. Also adds each source file's parent directory +# as an include path to support .inc files in the same directory. macro(libclc_configure_source_list variable path) set(${variable} ${ARGN}) list(TRANSFORM ${variable} PREPEND "${path}/") + + # Add each source file's parent directory as an include path + foreach(_src ${${variable}}) + cmake_path(GET _src PARENT_PATH _parent_dir) + get_property(_existing SOURCE ${_src} + DIRECTORY ${LIBCLC_SOURCE_DIR} + PROPERTY COMPILE_OPTIONS) + if(NOT "-I${_parent_dir}" IN_LIST _existing) + set_property(SOURCE ${_src} + DIRECTORY ${LIBCLC_SOURCE_DIR} + APPEND PROPERTY COMPILE_OPTIONS "-I${_parent_dir}") + endif() + endforeach() + set(${variable} ${${variable}} PARENT_SCOPE) endmacro() @@ -50,16 +65,6 @@ function(add_libclc_builtin_library target_name) ${ARGN} ) - # Append each source's parent directory as an include path to COMPILE_OPTIONS. - foreach(f ${ARG_SOURCES}) - 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() - add_library(${target_name} STATIC ${ARG_SOURCES}) target_compile_options(${target_name} PRIVATE ${ARG_COMPILE_OPTIONS}) target_include_directories(${target_name} PRIVATE _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
