[CMake] Quote variables where "TARGET" may be a value

In CMake, "TARGET" is a special keyword. But it's also an LLVM component, which
means downstreams may request "target" or "TARGET" from CMake. Quote such input
so "TARGET" is interpreted as a string rather than a keyword.

This is a followup to 75a0502fe0053c72b57b61143a55600814d931fd (D150884).

Fixes Meson's test suite and an issue which manifested identically to #61436
but appears to have been a slightly different problem.

Bug: https://github.com/mesonbuild/meson/issues/11642
Bug: https://github.com/llvm/llvm-project/issues/61436

Reviewed By: tstellar

Differential Revision: https://reviews.llvm.org/D152121
This commit is contained in:
Sam James 2023-06-06 02:08:01 +01:00
parent ecf30c31fb
commit ab8d4f5a12

View File

@ -134,7 +134,7 @@ function(llvm_expand_pseudo_components out_components)
endif() endif()
foreach(c ${link_components}) foreach(c ${link_components})
# add codegen, asmprinter, asmparser, disassembler # add codegen, asmprinter, asmparser, disassembler
if(${c} IN_LIST LLVM_TARGETS_TO_BUILD) if("${c}" IN_LIST LLVM_TARGETS_TO_BUILD)
if(LLVM${c}CodeGen IN_LIST LLVM_AVAILABLE_LIBS) if(LLVM${c}CodeGen IN_LIST LLVM_AVAILABLE_LIBS)
list(APPEND expanded_components "${c}CodeGen") list(APPEND expanded_components "${c}CodeGen")
else() else()
@ -149,48 +149,48 @@ function(llvm_expand_pseudo_components out_components)
list(APPEND expanded_components "${c}${subcomponent}") list(APPEND expanded_components "${c}${subcomponent}")
endif() endif()
endforeach() endforeach()
elseif( c STREQUAL "nativecodegen" ) elseif("${c}" STREQUAL "nativecodegen" )
foreach(subcomponent IN ITEMS CodeGen Desc Info) foreach(subcomponent IN ITEMS CodeGen Desc Info)
if(LLVM${LLVM_NATIVE_ARCH}${subcomponent} IN_LIST LLVM_AVAILABLE_LIBS) if(LLVM${LLVM_NATIVE_ARCH}${subcomponent} IN_LIST LLVM_AVAILABLE_LIBS)
list(APPEND expanded_components "${LLVM_NATIVE_ARCH}${subcomponent}") list(APPEND expanded_components "${LLVM_NATIVE_ARCH}${subcomponent}")
endif() endif()
endforeach() endforeach()
elseif( c STREQUAL "AllTargetsCodeGens" ) elseif("${c}" STREQUAL "AllTargetsCodeGens" )
# Link all the codegens from all the targets # Link all the codegens from all the targets
foreach(t ${LLVM_TARGETS_TO_BUILD}) foreach(t ${LLVM_TARGETS_TO_BUILD})
if( TARGET LLVM${t}CodeGen) if( TARGET LLVM${t}CodeGen)
list(APPEND expanded_components "${t}CodeGen") list(APPEND expanded_components "${t}CodeGen")
endif() endif()
endforeach(t) endforeach(t)
elseif( c STREQUAL "AllTargetsAsmParsers" ) elseif("${c}" STREQUAL "AllTargetsAsmParsers" )
# Link all the asm parsers from all the targets # Link all the asm parsers from all the targets
foreach(t ${LLVM_TARGETS_TO_BUILD}) foreach(t ${LLVM_TARGETS_TO_BUILD})
if(LLVM${t}AsmParser IN_LIST LLVM_AVAILABLE_LIBS) if(LLVM${t}AsmParser IN_LIST LLVM_AVAILABLE_LIBS)
list(APPEND expanded_components "${t}AsmParser") list(APPEND expanded_components "${t}AsmParser")
endif() endif()
endforeach(t) endforeach(t)
elseif( c STREQUAL "AllTargetsDescs" ) elseif( "${c}" STREQUAL "AllTargetsDescs" )
# Link all the descs from all the targets # Link all the descs from all the targets
foreach(t ${LLVM_TARGETS_TO_BUILD}) foreach(t ${LLVM_TARGETS_TO_BUILD})
if(LLVM${t}Desc IN_LIST LLVM_AVAILABLE_LIBS) if(LLVM${t}Desc IN_LIST LLVM_AVAILABLE_LIBS)
list(APPEND expanded_components "${t}Desc") list(APPEND expanded_components "${t}Desc")
endif() endif()
endforeach(t) endforeach(t)
elseif( c STREQUAL "AllTargetsDisassemblers" ) elseif("${c}" STREQUAL "AllTargetsDisassemblers" )
# Link all the disassemblers from all the targets # Link all the disassemblers from all the targets
foreach(t ${LLVM_TARGETS_TO_BUILD}) foreach(t ${LLVM_TARGETS_TO_BUILD})
if(LLVM${t}Disassembler IN_LIST LLVM_AVAILABLE_LIBS) if(LLVM${t}Disassembler IN_LIST LLVM_AVAILABLE_LIBS)
list(APPEND expanded_components "${t}Disassembler") list(APPEND expanded_components "${t}Disassembler")
endif() endif()
endforeach(t) endforeach(t)
elseif( c STREQUAL "AllTargetsInfos" ) elseif("${c}" STREQUAL "AllTargetsInfos" )
# Link all the infos from all the targets # Link all the infos from all the targets
foreach(t ${LLVM_TARGETS_TO_BUILD}) foreach(t ${LLVM_TARGETS_TO_BUILD})
if(LLVM${t}Info IN_LIST LLVM_AVAILABLE_LIBS) if(LLVM${t}Info IN_LIST LLVM_AVAILABLE_LIBS)
list(APPEND expanded_components "${t}Info") list(APPEND expanded_components "${t}Info")
endif() endif()
endforeach(t) endforeach(t)
elseif( c STREQUAL "AllTargetsMCAs" ) elseif("${c}" STREQUAL "AllTargetsMCAs" )
# Link all the TargetMCAs from all the targets # Link all the TargetMCAs from all the targets
foreach(t ${LLVM_TARGETS_TO_BUILD}) foreach(t ${LLVM_TARGETS_TO_BUILD})
if( TARGET LLVM${t}TargetMCA ) if( TARGET LLVM${t}TargetMCA )
@ -222,7 +222,7 @@ function(llvm_map_components_to_libnames out_libs)
# process target dependencies. # process target dependencies.
if(NOT LLVM_TARGETS_CONFIGURED) if(NOT LLVM_TARGETS_CONFIGURED)
foreach(c ${link_components}) foreach(c ${link_components})
is_llvm_target_specifier(${c} iltl_result ALL_TARGETS) is_llvm_target_specifier("${c}" iltl_result ALL_TARGETS)
if(iltl_result) if(iltl_result)
message(FATAL_ERROR "Specified target library before target registration is complete.") message(FATAL_ERROR "Specified target library before target registration is complete.")
endif() endif()
@ -250,13 +250,13 @@ function(llvm_map_components_to_libnames out_libs)
if(c_rename) if(c_rename)
set(c ${c_rename}) set(c ${c_rename})
endif() endif()
if( c STREQUAL "native" ) if("${c}" STREQUAL "native" )
# already processed # already processed
elseif( c STREQUAL "backend" ) elseif("${c}" STREQUAL "backend" )
# same case as in `native'. # same case as in `native'.
elseif( c STREQUAL "engine" ) elseif("${c}" STREQUAL "engine" )
# already processed # already processed
elseif( c STREQUAL "all" ) elseif("${c}" STREQUAL "all" )
get_property(all_components GLOBAL PROPERTY LLVM_COMPONENT_LIBS) get_property(all_components GLOBAL PROPERTY LLVM_COMPONENT_LIBS)
list(APPEND expanded_components ${all_components}) list(APPEND expanded_components ${all_components})
else() else()
@ -265,7 +265,7 @@ function(llvm_map_components_to_libnames out_libs)
list(FIND capitalized_libs LLVM${capitalized} lib_idx) list(FIND capitalized_libs LLVM${capitalized} lib_idx)
if( lib_idx LESS 0 ) if( lib_idx LESS 0 )
# The component is unknown. Maybe is an omitted target? # The component is unknown. Maybe is an omitted target?
is_llvm_target_library(${c} iltl_result OMITTED_TARGETS) is_llvm_target_library("${c}" iltl_result OMITTED_TARGETS)
if(iltl_result) if(iltl_result)
# A missing library to a directly referenced omitted target would be bad. # A missing library to a directly referenced omitted target would be bad.
message(FATAL_ERROR "Library '${c}' is a direct reference to a target library for an omitted target.") message(FATAL_ERROR "Library '${c}' is a direct reference to a target library for an omitted target.")
@ -280,7 +280,7 @@ function(llvm_map_components_to_libnames out_libs)
list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib) list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib)
list(APPEND expanded_components ${canonical_lib}) list(APPEND expanded_components ${canonical_lib})
endif( lib_idx LESS 0 ) endif( lib_idx LESS 0 )
endif( c STREQUAL "native" ) endif("${c}" STREQUAL "native" )
endforeach(c) endforeach(c)
set(${out_libs} ${expanded_components} PARENT_SCOPE) set(${out_libs} ${expanded_components} PARENT_SCOPE)