From 31cfd140848b440357f7d4b98dec7817951cfa5d Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Tue, 19 May 2026 14:56:23 +0300 Subject: [PATCH] [cmake][runtimes] Refactor passthrough option handling into a macro Deduplicates code and enables making fixes in just one place instead of two. --- llvm/runtimes/CMakeLists.txt | 59 ++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt index f369ec6957d6c..998b644bc5bcf 100644 --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -91,6 +91,30 @@ macro(set_enable_per_target_runtime_dir) endif() endmacro() +macro(append_passthrough_options out type names) + get_cmake_property(variable_names VARIABLES) + + # Support multiple names for layering (e.g. multilibs). + foreach(name IN ITEMS ${names}) + foreach(variable_name ${variable_names}) + string(FIND "${variable_name}" "${type}_${name}_" found) + + if(found EQUAL 0) + string(REPLACE "${type}_${name}_" "" new_name ${variable_name}) + + if(new_name STREQUAL CACHE_FILES) + foreach(cache IN LISTS ${variable_name}) + list(APPEND ${out} -C ${cache}) + endforeach() + else() + string(REPLACE ";" "|" new_value "${${variable_name}}") + list(APPEND ${out} "-D${new_name}=${new_value}") + endif() + endif() + endforeach() + endforeach() +endmacro() + function(builtin_default_target compiler_rt_path) cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN}) @@ -122,21 +146,7 @@ function(builtin_register_target compiler_rt_path name) cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN}) set(${name}_extra_args ${ARG_CMAKE_ARGS}) - get_cmake_property(variable_names VARIABLES) - foreach(variable_name ${variable_names}) - string(FIND "${variable_name}" "BUILTINS_${name}" out) - if("${out}" EQUAL 0) - string(REPLACE "BUILTINS_${name}_" "" new_name ${variable_name}) - if(new_name STREQUAL CACHE_FILES) - foreach(cache IN LISTS ${variable_name}) - list(APPEND ${name}_extra_args -C ${cache}) - endforeach() - else() - string(REPLACE ";" "|" new_value "${${variable_name}}") - list(APPEND ${name}_extra_args "-D${new_name}=${new_value}") - endif() - endif() - endforeach() + append_passthrough_options(${name}_extra_args BUILTINS ${name}) llvm_ExternalProject_Add(builtins-${name} ${compiler_rt_path}/lib/builtins @@ -404,24 +414,7 @@ function(runtime_register_target name) string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}") list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH}) list(APPEND ${name}_extra_args -DLLVM_USE_LINKER=${LLVM_USE_LINKER}) - - get_cmake_property(variable_names VARIABLES) - foreach(extra_name IN ITEMS ${ARG_BASE_NAME} ${name}) - foreach(variable_name ${variable_names}) - string(FIND "${variable_name}" "RUNTIMES_${extra_name}_" out) - if("${out}" EQUAL 0) - string(REPLACE "RUNTIMES_${extra_name}_" "" new_name ${variable_name}) - if(new_name STREQUAL CACHE_FILES) - foreach(cache IN LISTS ${variable_name}) - list(APPEND ${name}_extra_args -C ${cache}) - endforeach() - else() - string(REPLACE ";" "|" new_value "${${variable_name}}") - list(APPEND ${name}_extra_args "-D${new_name}=${new_value}") - endif() - endif() - endforeach() - endforeach() + append_passthrough_options(${name}_extra_args RUNTIMES "${ARG_BASE_NAME};${name}") set_enable_per_target_runtime_dir()