Skip to content

Commit e6975c4

Browse files
committed
[CMake] Support runtimes targets without specifying triple
Currently, for BUILTIN_TARGETS and RUNTIME_TARGETS you can either use the special "default" value, or a target triple. For the "default" value, we don't set any target triple and passthrough a subset of CMake variables into the subbuild. This is typically used on Darwin where we build universal binaries and a single target triple therefore isn't sufficient. For the target triple value, you can set arbitrary CMake variables through RUNTIMES_<target>_<variable>, but we always set target triple to <target>. This gives more flexibility, because we can precisely control what variables are set in the subbuild, but is unsuitable for platforms like Darwin. To address this, we would like to introduce a third option which is similar to the second option, except we won't set target triple in the subbuild (you can always do so yourself by setting the appropriate CMake variable, e.g. RUNTIMES_<name>_CMAKE_C_COMPILER_TARGET=<triple>). This change is a first step in that direction, by eliminating the support of target triples from builtin_register_target and runtime_register_target helper functions. Differential Revision: https://reviews.llvm.org/D117263
1 parent 5cd5543 commit e6975c4

File tree

1 file changed

+52
-59
lines changed

1 file changed

+52
-59
lines changed

llvm/runtimes/CMakeLists.txt

Lines changed: 52 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -96,36 +96,33 @@ function(builtin_default_target compiler_rt_path)
9696
${EXTRA_ARGS})
9797
endfunction()
9898

99-
function(builtin_register_target compiler_rt_path target)
100-
cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
101-
102-
check_apple_target(${target} builtin)
99+
function(builtin_register_target compiler_rt_path name)
100+
cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN})
103101

104-
get_cmake_property(variableNames VARIABLES)
105-
foreach(variableName ${variableNames})
106-
string(FIND "${variableName}" "BUILTINS_${target}" out)
102+
set(${name}_extra_args ${ARG_CMAKE_ARGS})
103+
get_cmake_property(variable_names VARIABLES)
104+
foreach(variable_name ${variable_names})
105+
string(FIND "${variable_name}" "BUILTINS_${name}" out)
107106
if("${out}" EQUAL 0)
108-
string(REPLACE "BUILTINS_${target}_" "" new_name ${variableName})
109-
string(REPLACE ";" "|" new_value "${${variableName}}")
110-
list(APPEND ${target}_extra_args "-D${new_name}=${new_value}")
107+
string(REPLACE "BUILTINS_${name}_" "" new_name ${variable_name})
108+
string(REPLACE ";" "|" new_value "${${variable_name}}")
109+
list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")
111110
endif()
112111
endforeach()
113112

114-
llvm_ExternalProject_Add(builtins-${target}
113+
llvm_ExternalProject_Add(builtins-${name}
115114
${compiler_rt_path}/lib/builtins
116115
DEPENDS ${ARG_DEPENDS}
117116
CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
118117
-DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
119-
-DLLVM_DEFAULT_TARGET_TRIPLE=${target}
120118
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
121119
-DCMAKE_C_COMPILER_WORKS=ON
122120
-DCMAKE_ASM_COMPILER_WORKS=ON
123121
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
124122
${COMMON_CMAKE_ARGS}
125-
${${target}_extra_args}
123+
${${name}_extra_args}
126124
USE_TOOLCHAIN
127-
TARGET_TRIPLE ${target}
128-
${EXTRA_ARGS})
125+
${EXTRA_ARGS} ${ARG_EXTRA_ARGS})
129126
endfunction()
130127

131128
# If compiler-rt is present we need to build the builtin libraries first. This
@@ -148,8 +145,12 @@ if(compiler_rt_path)
148145
endif()
149146

150147
foreach(target ${LLVM_BUILTIN_TARGETS})
148+
check_apple_target(${target} builtin)
149+
151150
builtin_register_target(${compiler_rt_path} ${target}
152-
DEPENDS clang-resource-headers)
151+
DEPENDS clang-resource-headers
152+
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
153+
EXTRA_ARGS TARGET_TRIPLE ${target})
153154

154155
add_dependencies(builtins builtins-${target})
155156
add_dependencies(install-builtins install-builtins-${target})
@@ -249,20 +250,13 @@ function(runtime_default_target)
249250
${EXTRA_ARGS})
250251
endfunction()
251252

252-
# runtime_register_target(target)
253+
# runtime_register_target(name)
253254
# Utility function to register external runtime target.
254-
function(runtime_register_target name target)
255-
cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS" ${ARGN})
255+
function(runtime_register_target name)
256+
cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;BASE_NAME;EXTRA_ARGS" ${ARGN})
256257
include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
257258
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
258259

259-
check_apple_target(${target} runtime)
260-
261-
set(${name}_deps ${ARG_DEPENDS})
262-
if(NOT name STREQUAL target)
263-
list(APPEND ${name}_deps runtimes-${target})
264-
endif()
265-
266260
foreach(runtime_name ${runtime_names})
267261
set(${runtime_name}-${name} ${runtime_name})
268262
set(install-${runtime_name}-${name} install-${runtime_name})
@@ -274,9 +268,9 @@ function(runtime_register_target name target)
274268
endif()
275269
endforeach()
276270

277-
foreach(target_name IN LISTS SUB_COMPONENTS)
278-
set(${target_name}-${name} ${target_name})
279-
list(APPEND ${name}_extra_targets ${target_name}-${name})
271+
foreach(target IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS)
272+
set(${target}-${name} ${target})
273+
list(APPEND ${name}_extra_targets ${target}-${name})
280274
endforeach()
281275

282276
foreach(target_name IN LISTS SUB_INSTALL_TARGETS)
@@ -308,36 +302,28 @@ function(runtime_register_target name target)
308302
endif()
309303
endforeach()
310304

311-
foreach(target_name IN LISTS SUB_CHECK_TARGETS component_check_targets)
312-
set(${target_name}-${name} ${target_name})
313-
list(APPEND ${name}_test_targets ${target_name}-${name})
314-
list(APPEND test_targets ${target_name}-${name})
305+
foreach(target IN LISTS SUB_CHECK_TARGETS component_check_targets)
306+
set(${target}-${name} ${target})
307+
list(APPEND ${name}_test_targets ${target}-${name})
308+
list(APPEND test_targets ${target}-${name})
315309
endforeach()
316310
set(test_targets "${test_targets}" PARENT_SCOPE)
317311
endif()
318312

319313
set(${name}_extra_args ${ARG_CMAKE_ARGS})
320-
get_cmake_property(variableNames VARIABLES)
321-
foreach(variableName ${variableNames})
322-
string(FIND "${variableName}" "RUNTIMES_${target}_" out)
323-
if("${out}" EQUAL 0)
324-
string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName})
325-
string(REPLACE ";" "|" new_value "${${variableName}}")
326-
list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")
327-
endif()
328-
endforeach()
329-
if(NOT "${name}" STREQUAL "${target}")
330-
foreach(variableName ${variableNames})
331-
string(FIND "${variableName}" "RUNTIMES_${name}_" out)
314+
get_cmake_property(variable_names VARIABLES)
315+
foreach(extra_name IN ITEMS ${name} ${ARG_BASE_NAME})
316+
foreach(variable_name ${variable_names})
317+
string(FIND "${variable_name}" "RUNTIMES_${extra_name}_" out)
332318
if("${out}" EQUAL 0)
333-
string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName})
334-
string(REPLACE ";" "|" new_value "${${variableName}}")
319+
string(REPLACE "RUNTIMES_${extra_name}_" "" new_name ${variable_name})
320+
string(REPLACE ";" "|" new_value "${${variable_name}}")
335321
list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")
336322
endif()
337323
endforeach()
338-
endif()
324+
endforeach()
339325

340-
if(NOT RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES AND NOT RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES)
326+
if(NOT RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES)
341327
string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}")
342328
list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})
343329
endif()
@@ -350,11 +336,10 @@ function(runtime_register_target name target)
350336

351337
llvm_ExternalProject_Add(runtimes-${name}
352338
${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
353-
DEPENDS ${${name}_deps}
339+
DEPENDS ${ARG_DEPENDS}
354340
# Builtins were built separately above
355-
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
341+
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF
356342
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
357-
-DLLVM_DEFAULT_TARGET_TRIPLE=${target}
358343
-DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
359344
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
360345
-DCMAKE_C_COMPILER_WORKS=ON
@@ -367,8 +352,7 @@ function(runtime_register_target name target)
367352
EXTRA_TARGETS ${${name}_extra_targets}
368353
${${name}_test_targets}
369354
USE_TOOLCHAIN
370-
TARGET_TRIPLE ${target}
371-
${EXTRA_ARGS})
355+
${EXTRA_ARGS} ${ARG_EXTRA_ARGS})
372356
endfunction()
373357

374358
if(runtimes)
@@ -427,8 +411,13 @@ if(runtimes)
427411
set(builtins_dep_name ${builtins_dep})
428412
endif()
429413
endif()
430-
runtime_register_target(${name} ${name}
431-
DEPENDS ${builtins_dep_name})
414+
415+
check_apple_target(${name} runtime)
416+
417+
runtime_register_target(${name}
418+
DEPENDS ${builtins_dep_name}
419+
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
420+
EXTRA_ARGS TARGET_TRIPLE ${name})
432421

433422
add_dependencies(runtimes runtimes-${name})
434423
add_dependencies(runtimes-configure runtimes-${name}-configure)
@@ -452,10 +441,14 @@ if(runtimes)
452441

453442
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
454443
foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
455-
runtime_register_target(${name}+${multilib} ${name}
444+
runtime_register_target(${name}+${multilib}
456445
DEPENDS runtimes-${name}
457-
CMAKE_ARGS -DLLVM_RUNTIMES_PREFIX=${name}/
458-
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib})
446+
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
447+
-DLLVM_RUNTIMES_PREFIX=${name}/
448+
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
449+
BASE_NAME ${name}
450+
EXTRA_ARGS TARGET_TRIPLE ${name})
451+
459452
add_dependencies(runtimes runtimes-${name}+${multilib})
460453
add_dependencies(runtimes-configure runtimes-${name}+${multilib}-configure)
461454
add_dependencies(install-runtimes install-runtimes-${name}+${multilib})

0 commit comments

Comments
 (0)