Skip to content

Commit e787ef8

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 59cb470 commit e787ef8

File tree

1 file changed

+58
-71
lines changed

1 file changed

+58
-71
lines changed

llvm/runtimes/CMakeLists.txt

Lines changed: 58 additions & 71 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})
@@ -254,20 +255,13 @@ function(runtime_default_target)
254255
${EXTRA_ARGS})
255256
endfunction()
256257

257-
# runtime_register_target(target)
258+
# runtime_register_target(name)
258259
# Utility function to register external runtime target.
259-
function(runtime_register_target name target)
260-
cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS" ${ARGN})
260+
function(runtime_register_target name)
261+
cmake_parse_arguments(ARG "" "BASE_NAME" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN})
261262
include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
262263
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)
263264

264-
check_apple_target(${target} runtime)
265-
266-
set(${name}_deps ${ARG_DEPENDS})
267-
if(NOT name STREQUAL target)
268-
list(APPEND ${name}_deps runtimes-${target})
269-
endif()
270-
271265
foreach(runtime_name ${runtime_names})
272266
set(${runtime_name}-${name} ${runtime_name})
273267
set(install-${runtime_name}-${name} install-${runtime_name})
@@ -279,15 +273,15 @@ function(runtime_register_target name target)
279273
endif()
280274
endforeach()
281275

282-
foreach(target_name IN LISTS SUB_COMPONENTS)
283-
set(${target_name}-${name} ${target_name})
284-
list(APPEND ${name}_extra_targets ${target_name}-${name})
276+
foreach(component IN LISTS SUB_COMPONENTS)
277+
set(${component}-${name} ${component})
278+
list(APPEND ${name}_extra_targets ${component}-${name})
285279
endforeach()
286280

287-
foreach(target_name IN LISTS SUB_INSTALL_TARGETS)
288-
set(${target_name}-${name} ${target_name})
289-
set(${target_name}-${name}-stripped ${target_name}-stripped)
290-
list(APPEND ${name}_extra_targets ${target_name}-${name} ${target_name}-${name}-stripped)
281+
foreach(target IN LISTS SUB_INSTALL_TARGETS)
282+
set(${target}-${name} ${target})
283+
set(${target}-${name}-stripped ${target}-stripped)
284+
list(APPEND ${name}_extra_targets ${target}-${name} ${target}-${name}-stripped)
291285
endforeach()
292286

293287
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
@@ -313,53 +307,39 @@ function(runtime_register_target name target)
313307
endif()
314308
endforeach()
315309

316-
foreach(target_name IN LISTS SUB_CHECK_TARGETS component_check_targets)
317-
set(${target_name}-${name} ${target_name})
318-
list(APPEND ${name}_test_targets ${target_name}-${name})
319-
list(APPEND test_targets ${target_name}-${name})
310+
foreach(target IN LISTS SUB_CHECK_TARGETS component_check_targets)
311+
set(${target}-${name} ${target})
312+
list(APPEND ${name}_test_targets ${target}-${name})
313+
list(APPEND test_targets ${target}-${name})
320314
endforeach()
321315
set(test_targets "${test_targets}" PARENT_SCOPE)
322316
endif()
323317

324318
set(${name}_extra_args ${ARG_CMAKE_ARGS})
325-
get_cmake_property(variableNames VARIABLES)
326-
foreach(variableName ${variableNames})
327-
string(FIND "${variableName}" "RUNTIMES_${target}_" out)
328-
if("${out}" EQUAL 0)
329-
string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName})
330-
string(REPLACE ";" "|" new_value "${${variableName}}")
331-
list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")
332-
endif()
333-
endforeach()
334-
if(NOT "${name}" STREQUAL "${target}")
335-
foreach(variableName ${variableNames})
336-
string(FIND "${variableName}" "RUNTIMES_${name}_" out)
319+
string(REPLACE ";" "|" LVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}")
320+
list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})
321+
list(APPEND ${name}_extra_args -DLLVM_USE_LINKER=${LLVM_USE_LINKER})
322+
323+
get_cmake_property(variable_names VARIABLES)
324+
foreach(extra_name IN ITEMS ${ARG_BASE_NAME} ${name})
325+
foreach(variable_name ${variable_names})
326+
string(FIND "${variable_name}" "RUNTIMES_${extra_name}_" out)
337327
if("${out}" EQUAL 0)
338-
string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName})
339-
string(REPLACE ";" "|" new_value "${${variableName}}")
328+
string(REPLACE "RUNTIMES_${extra_name}_" "" new_name ${variable_name})
329+
string(REPLACE ";" "|" new_value "${${variable_name}}")
340330
list(APPEND ${name}_extra_args "-D${new_name}=${new_value}")
341331
endif()
342332
endforeach()
343-
endif()
344-
345-
if(NOT RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES AND NOT RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES)
346-
string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}")
347-
list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})
348-
endif()
349-
350-
if(NOT RUNTIMES_${name}_LLVM_USE_LINKER AND NOT RUNTIMES_${target}_LLVM_USE_LINKER)
351-
list(APPEND ${name}_extra_args -DLLVM_USE_LINKER=${LLVM_USE_LINKER})
352-
endif()
333+
endforeach()
353334

354335
set_enable_per_target_runtime_dir()
355336

356337
llvm_ExternalProject_Add(runtimes-${name}
357338
${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
358-
DEPENDS ${${name}_deps}
339+
DEPENDS ${ARG_DEPENDS}
359340
# Builtins were built separately above
360-
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
341+
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF
361342
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
362-
-DLLVM_DEFAULT_TARGET_TRIPLE=${target}
363343
-DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
364344
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
365345
-DCMAKE_C_COMPILER_WORKS=ON
@@ -372,8 +352,7 @@ function(runtime_register_target name target)
372352
EXTRA_TARGETS ${${name}_extra_targets}
373353
${${name}_test_targets}
374354
USE_TOOLCHAIN
375-
TARGET_TRIPLE ${target}
376-
${EXTRA_ARGS})
355+
${EXTRA_ARGS} ${ARG_EXTRA_ARGS})
377356
endfunction()
378357

379358
if(runtimes)
@@ -452,9 +431,13 @@ if(runtimes)
452431
set(builtins_dep_name ${builtins_dep})
453432
endif()
454433
endif()
455-
runtime_register_target(${name} ${name}
434+
435+
check_apple_target(${name} runtime)
436+
437+
runtime_register_target(${name}
456438
DEPENDS ${builtins_dep_name} ${libc_tools}
457-
CMAKE_ARGS ${libc_cmake_args})
439+
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${libc_cmake_args}
440+
EXTRA_ARGS TARGET_TRIPLE ${name})
458441

459442
add_dependencies(runtimes runtimes-${name})
460443
add_dependencies(runtimes-configure runtimes-${name}-configure)
@@ -478,10 +461,14 @@ if(runtimes)
478461

479462
foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
480463
foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS})
481-
runtime_register_target(${name}+${multilib} ${name}
464+
runtime_register_target(${name}+${multilib}
482465
DEPENDS runtimes-${name}
483-
CMAKE_ARGS -DLLVM_RUNTIMES_PREFIX=${name}/
484-
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib})
466+
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name}
467+
-DLLVM_RUNTIMES_PREFIX=${name}/
468+
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
469+
BASE_NAME ${name}
470+
EXTRA_ARGS TARGET_TRIPLE ${name})
471+
485472
add_dependencies(runtimes runtimes-${name}+${multilib})
486473
add_dependencies(runtimes-configure runtimes-${name}+${multilib}-configure)
487474
add_dependencies(install-runtimes install-runtimes-${name}+${multilib})

0 commit comments

Comments
 (0)