From 9efaebecaa8156d6c8a3afba9b1d514f20190d62 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Fri, 8 Sep 2017 22:26:50 +0000 Subject: [CMake][runtimes] Use the same configuration for non-target and "default" target The default host target for builtins and runtimes has special behavior on some platforms, e.g. on Linux both i386 and x86_64 targets are being built. Specifying "default" as a target name should lead to the same behavior, which wasn't the case in the past. This patch unifies the configuration between the non-target and "default" target to produce the same behavior by moving the default configuration into a function that can be used from both paths. Differential Revision: https://reviews.llvm.org/D37450 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312831 91177308-0d34-0410-b5e6-96231b3b80d8 --- runtimes/CMakeLists.txt | 203 +++++++++++++++++++++++++----------------------- 1 file changed, 106 insertions(+), 97 deletions(-) (limited to 'runtimes') diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt index 0af7c47e6fe8..7c6c01853812 100644 --- a/runtimes/CMakeLists.txt +++ b/runtimes/CMakeLists.txt @@ -209,57 +209,69 @@ else() # if this is included from LLVM's CMake set(EXTRA_ARGS EXCLUDE_FROM_ALL) endif() + function(builtin_default_target) + llvm_ExternalProject_Add(builtins + ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt/lib/builtins + CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR} + -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR} + -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE} + -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE} + PASSTHROUGH_PREFIXES COMPILER_RT + USE_TOOLCHAIN + ${EXTRA_ARGS}) + endfunction() + + function(builtin_register_target target) + string(REPLACE "-" ";" builtin_target_list ${target}) + foreach(item ${builtin_target_list}) + string(TOLOWER "${item}" item_lower) + if(item_lower MATCHES "darwin") + message(FATAL_ERROR "LLVM_BUILTIN_TARGETS isn't implemented for Darwin platform!") + endif() + endforeach() + + get_cmake_property(variableNames VARIABLES) + foreach(variableName ${variableNames}) + if(variableName MATCHES "^BUILTINS_${target}") + string(REPLACE "BUILTINS_${target}_" "" new_name ${variableName}) + list(APPEND ${target}_extra_args "-D${new_name}=${${variableName}}") + endif() + endforeach() + + llvm_ExternalProject_Add(builtins-${target} + ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt/lib/builtins + CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR} + -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR} + -DCMAKE_C_COMPILER_TARGET=${target} + -DCMAKE_ASM_COMPILER_TARGET=${target} + -DCMAKE_C_COMPILER_WORKS=On + -DCMAKE_ASM_COMPILER_WORKS=On + -DCOMPILER_RT_DEFAULT_TARGET_ONLY=On + ${${target}_extra_args} + TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib + PASSTHROUGH_PREFIXES COMPILER_RT + USE_TOOLCHAIN + ${EXTRA_ARGS}) + endfunction() + # If compiler-rt is present we need to build the builtin libraries first. This # is required because the other runtimes need the builtin libraries present # before the just-built compiler can pass the configuration tests. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt) if(NOT LLVM_BUILTIN_TARGETS) - llvm_ExternalProject_Add(builtins - ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt/lib/builtins - CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR} - -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR} - -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE} - -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE} - PASSTHROUGH_PREFIXES COMPILER_RT - USE_TOOLCHAIN - ${EXTRA_ARGS}) + builtin_default_target() else() - get_cmake_property(variableNames VARIABLES) - add_custom_target(builtins) - add_custom_target(install-builtins) + if("default" IN_LIST LLVM_BUILTIN_TARGETS) + builtin_default_target() + list(REMOVE_ITEM LLVM_BUILTIN_TARGETS "default") + else() + add_custom_target(builtins) + add_custom_target(install-builtins) + endif() + foreach(target ${LLVM_BUILTIN_TARGETS}) - if(target STREQUAL "default") - set(target ${LLVM_DEFAULT_TARGET_TRIPLE}) - endif() + builtin_register_target(${target}) - string(REPLACE "-" ";" builtin_target_list ${target}) - foreach(item ${builtin_target_list}) - string(TOLOWER "${item}" item_lower) - if(item_lower MATCHES "darwin") - message(FATAL_ERROR "LLVM_BUILTIN_TARGETS isn't implemented for Darwin platform!") - endif() - endforeach() - - foreach(variableName ${variableNames}) - if(variableName MATCHES "^BUILTINS_${target}") - string(REPLACE "BUILTINS_${target}_" "" new_name ${variableName}) - list(APPEND ${target}_extra_args "-D${new_name}=${${variableName}}") - endif() - endforeach() - llvm_ExternalProject_Add(builtins-${target} - ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt/lib/builtins - CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR} - -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR} - -DCMAKE_C_COMPILER_TARGET=${target} - -DCMAKE_ASM_COMPILER_TARGET=${target} - -DCMAKE_C_COMPILER_WORKS=On - -DCMAKE_ASM_COMPILER_WORKS=On - -DCOMPILER_RT_DEFAULT_TARGET_ONLY=On - ${${target}_extra_args} - TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib - PASSTHROUGH_PREFIXES COMPILER_RT - USE_TOOLCHAIN - ${EXTRA_ARGS}) add_dependencies(builtins builtins-${target}) add_dependencies(install-builtins install-builtins-${target}) endforeach() @@ -288,16 +300,45 @@ else() # if this is included from LLVM's CMake list(APPEND runtime_names ${projName}) endforeach() + function(runtime_default_target deps prefixes) + include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake) + + foreach(runtime_name ${runtime_names}) + list(APPEND extra_targets + ${runtime_name} + install-${runtime_name}) + if(LLVM_INCLUDE_TESTS) + list(APPEND test_targets check-${runtime_name}) + endif() + endforeach() + + if(LLVM_INCLUDE_TESTS) + list(APPEND test_targets runtimes-test-depends check-runtimes) + endif() + + llvm_ExternalProject_Add(runtimes + ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${deps} + # Builtins were built separately above + CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off + -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS} + -DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR} + PASSTHROUGH_PREFIXES ${prefixes} + EXTRA_TARGETS ${extra_targets} + ${test_targets} + ${SUB_COMPONENTS} + ${SUB_CHECK_TARGETS} + ${SUB_INSTALL_TARGETS} + USE_TOOLCHAIN + ${EXTRA_ARGS}) + endfunction() + # runtime_register_target(target) # Utility function to register external runtime target. - function(runtime_register_target name target) - if(name STREQUAL LLVM_DEFAULT_TARGET_TRIPLE) - include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL) - set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake) - else() - include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL) - set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake) - endif() + function(runtime_register_target name target deps prefixes) + include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake) set(${name}_deps ${deps}) if(NOT name STREQUAL target) @@ -339,10 +380,6 @@ else() # if this is included from LLVM's CMake endif() endforeach() - if(NOT target STREQUAL LLVM_DEFAULT_TARGET_TRIPLE) - list(APPEND ${name}_extra_args "-DLLVM_RUNTIMES_TARGET=${name}") - endif() - llvm_ExternalProject_Add(runtimes-${name} ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${${name}_deps} @@ -357,6 +394,7 @@ else() # if this is included from LLVM's CMake -DCMAKE_CXX_COMPILER_WORKS=ON -DCMAKE_ASM_COMPILER_WORKS=ON -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON + -DLLVM_RUNTIMES_TARGET=${name} ${${name}_extra_args} TOOLCHAIN_TOOLS clang lld llvm-ar llvm-ranlib PASSTHROUGH_PREFIXES ${prefixes} @@ -371,52 +409,23 @@ else() # if this is included from LLVM's CMake # The runtimes target is a configuration of all the runtime libraries # together in a single CMake invocaiton. if(NOT LLVM_RUNTIME_TARGETS) - include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL) - set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake) - - foreach(runtime_name ${runtime_names}) - list(APPEND extra_targets - ${runtime_name} - install-${runtime_name}) + runtime_default_target(${deps} ${prefixes}) + else() + if("default" IN_LIST LLVM_RUNTIME_TARGETS) + runtime_default_target(${deps} ${prefixes}) + list(REMOVE_ITEM LLVM_RUNTIME_TARGETS "default") + else() + add_custom_target(runtimes) + add_custom_target(runtimes-configure) + add_custom_target(install-runtimes) if(LLVM_INCLUDE_TESTS) - list(APPEND test_targets check-${runtime_name}) + add_custom_target(check-runtimes) + add_custom_target(runtimes-test-depends) + set(test_targets "") endif() - endforeach() - - if(LLVM_INCLUDE_TESTS) - list(APPEND test_targets runtimes-test-depends check-runtimes) - endif() - - llvm_ExternalProject_Add(runtimes - ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS ${deps} - # Builtins were built separately above - CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off - -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS} - -DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR} - PASSTHROUGH_PREFIXES ${prefixes} - EXTRA_TARGETS ${extra_targets} - ${test_targets} - ${SUB_COMPONENTS} - ${SUB_CHECK_TARGETS} - ${SUB_INSTALL_TARGETS} - USE_TOOLCHAIN - ${EXTRA_ARGS}) - else() - add_custom_target(runtimes) - add_custom_target(runtimes-configure) - add_custom_target(install-runtimes) - if(LLVM_INCLUDE_TESTS) - add_custom_target(check-runtimes) - add_custom_target(runtimes-test-depends) - set(test_targets "") endif() foreach(name ${LLVM_RUNTIME_TARGETS}) - if(name STREQUAL "default") - set(name ${LLVM_DEFAULT_TARGET_TRIPLE}) - endif() - set(target ${name}) string(REPLACE ":" ";" target_list ${target}) list(GET target_list 0 name) @@ -425,7 +434,7 @@ else() # if this is included from LLVM's CMake list(GET target_list 1 target) endif() - runtime_register_target(${name} ${target}) + runtime_register_target(${name} ${target} ${deps} ${prefixes}) add_dependencies(runtimes runtimes-${name}) add_dependencies(runtimes-configure runtimes-${name}-configure) -- cgit v1.2.1