diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -96,36 +96,33 @@ ${EXTRA_ARGS}) endfunction() -function(builtin_register_target compiler_rt_path target) - cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN}) - - check_apple_target(${target} builtin) +function(builtin_register_target compiler_rt_path name) + cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;EXTRA_ARGS" ${ARGN}) - get_cmake_property(variableNames VARIABLES) - foreach(variableName ${variableNames}) - string(FIND "${variableName}" "BUILTINS_${target}" out) + 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_${target}_" "" new_name ${variableName}) - string(REPLACE ";" "|" new_value "${${variableName}}") - list(APPEND ${target}_extra_args "-D${new_name}=${new_value}") + string(REPLACE "BUILTINS_${name}_" "" new_name ${variable_name}) + string(REPLACE ";" "|" new_value "${${variable_name}}") + list(APPEND ${name}_extra_args "-D${new_name}=${new_value}") endif() endforeach() - llvm_ExternalProject_Add(builtins-${target} + llvm_ExternalProject_Add(builtins-${name} ${compiler_rt_path}/lib/builtins DEPENDS ${ARG_DEPENDS} CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR} -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR} - -DLLVM_DEFAULT_TARGET_TRIPLE=${target} -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON -DCMAKE_C_COMPILER_WORKS=ON -DCMAKE_ASM_COMPILER_WORKS=ON -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON ${COMMON_CMAKE_ARGS} - ${${target}_extra_args} + ${${name}_extra_args} USE_TOOLCHAIN - TARGET_TRIPLE ${target} - ${EXTRA_ARGS}) + ${EXTRA_ARGS} ${ARG_EXTRA_ARGS}) endfunction() # If compiler-rt is present we need to build the builtin libraries first. This @@ -148,8 +145,12 @@ endif() foreach(target ${LLVM_BUILTIN_TARGETS}) + check_apple_target(${target} builtin) + builtin_register_target(${compiler_rt_path} ${target} - DEPENDS clang-resource-headers) + DEPENDS clang-resource-headers + CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${target} + EXTRA_ARGS TARGET_TRIPLE ${target}) add_dependencies(builtins builtins-${target}) add_dependencies(install-builtins install-builtins-${target}) @@ -254,20 +255,13 @@ ${EXTRA_ARGS}) endfunction() -# runtime_register_target(target) +# runtime_register_target(name) # Utility function to register external runtime target. -function(runtime_register_target name target) - cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS" ${ARGN}) +function(runtime_register_target name) + cmake_parse_arguments(ARG "" "" "DEPENDS;CMAKE_ARGS;EXTRA_NAMES;EXTRA_ARGS" ${ARGN}) include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake) - check_apple_target(${target} runtime) - - set(${name}_deps ${ARG_DEPENDS}) - if(NOT name STREQUAL target) - list(APPEND ${name}_deps runtimes-${target}) - endif() - foreach(runtime_name ${runtime_names}) set(${runtime_name}-${name} ${runtime_name}) set(install-${runtime_name}-${name} install-${runtime_name}) @@ -279,9 +273,9 @@ endif() endforeach() - foreach(target_name IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS) - set(${target_name}-${name} ${target_name}) - list(APPEND ${name}_extra_targets ${target_name}-${name}) + foreach(target IN LISTS SUB_COMPONENTS SUB_INSTALL_TARGETS) + set(${target}-${name} ${target}) + list(APPEND ${name}_extra_targets ${target}-${name}) endforeach() foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS}) @@ -296,47 +290,38 @@ set(check-runtimes-${name} check-runtimes) list(APPEND ${name}_test_targets runtimes-test-depends-${name} check-runtimes-${name}) list(APPEND test_targets ${${name}_test_targets}) - foreach(target_name IN LISTS SUB_CHECK_TARGETS) - set(${target_name}-${name} ${target_name}) - list(APPEND ${name}_test_targets ${target_name}-${name}) - list(APPEND test_targets ${target_name}-${name}) + foreach(target IN LISTS SUB_CHECK_TARGETS) + set(${target}-${name} ${target}) + list(APPEND ${name}_test_targets ${target}-${name}) + list(APPEND test_targets ${target}-${name}) endforeach() set(test_targets "${test_targets}" PARENT_SCOPE) endif() set(${name}_extra_args ${ARG_CMAKE_ARGS}) - get_cmake_property(variableNames VARIABLES) - foreach(variableName ${variableNames}) - string(FIND "${variableName}" "RUNTIMES_${target}_" out) - if("${out}" EQUAL 0) - string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName}) - string(REPLACE ";" "|" new_value "${${variableName}}") - list(APPEND ${name}_extra_args "-D${new_name}=${new_value}") - endif() - endforeach() - if(NOT "${name}" STREQUAL "${target}") - foreach(variableName ${variableNames}) - string(FIND "${variableName}" "RUNTIMES_${name}_" out) + get_cmake_property(variable_names VARIABLES) + foreach(extra_name IN LISTS ARG_EXTRA_NAMES ITEMS ${name}) + foreach(variable_name ${variable_names}) + string(FIND "${variable_name}" "RUNTIMES_${extra_name}_" out) if("${out}" EQUAL 0) - string(REPLACE "RUNTIMES_${name}_" "" new_name ${variableName}) - string(REPLACE ";" "|" new_value "${${variableName}}") + string(REPLACE "RUNTIMES_${extra_name}_" "" new_name ${variable_name}) + string(REPLACE ";" "|" new_value "${${variable_name}}") list(APPEND ${name}_extra_args "-D${new_name}=${new_value}") endif() endforeach() - endif() + endforeach() - if(NOT RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES AND NOT RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES) + if(NOT RUNTIMES_${name}_LLVM_ENABLE_RUNTIMES) string(REPLACE ";" "|" LLVM_ENABLE_RUNTIMES_PASSTHROUGH "${LLVM_ENABLE_RUNTIMES}") list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH}) endif() llvm_ExternalProject_Add(runtimes-${name} ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes - DEPENDS ${${name}_deps} + DEPENDS ${ARG_DEPENDS} # Builtins were built separately above - CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off + CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS} - -DLLVM_DEFAULT_TARGET_TRIPLE=${target} -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED} -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON -DCMAKE_C_COMPILER_WORKS=ON @@ -350,8 +335,7 @@ EXTRA_TARGETS ${${name}_extra_targets} ${${name}_test_targets} USE_TOOLCHAIN - TARGET_TRIPLE ${target} - ${EXTRA_ARGS}) + ${EXTRA_ARGS} ${ARG_EXTRA_ARGS}) endfunction() if(runtimes) @@ -403,8 +387,12 @@ endif() foreach(name ${LLVM_RUNTIME_TARGETS}) - runtime_register_target(${name} ${name} - DEPENDS ${deps}) + check_apple_target(${name} runtime) + + runtime_register_target(${name} + DEPENDS ${deps} + CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} + EXTRA_ARGS TARGET_TRIPLE ${name}) add_dependencies(runtimes runtimes-${name}) add_dependencies(runtimes-configure runtimes-${name}-configure) @@ -428,10 +416,14 @@ foreach(multilib ${LLVM_RUNTIME_MULTILIBS}) foreach(name ${LLVM_RUNTIME_MULTILIB_${multilib}_TARGETS}) - runtime_register_target(${name}+${multilib} ${name} + runtime_register_target(${name}+${multilib} DEPENDS runtimes-${name} - CMAKE_ARGS -DLLVM_RUNTIMES_PREFIX=${name}/ - -DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}) + CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} + -DLLVM_RUNTIMES_PREFIX=${name}/ + -DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib} + EXTRA_NAMES ${name} + EXTRA_ARGS TARGET_TRIPLE ${name}) + add_dependencies(runtimes runtimes-${name}+${multilib}) add_dependencies(runtimes-configure runtimes-${name}+${multilib}-configure) add_dependencies(install-runtimes install-runtimes-${name}+${multilib})