Index: runtimes/CMakeLists.txt =================================================================== --- runtimes/CMakeLists.txt +++ runtimes/CMakeLists.txt @@ -55,14 +55,19 @@ # Setting these variables will allow the sub-build to put their outputs into # the library and bin directories of the top-level build. - set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR}) - set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR}) + if(LLVM_RUNTIMES_TARGET) + set(LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR}/${LLVM_RUNTIMES_TARGET}") + set(LLVM_RUNTIME_OUTPUT_INTDIR "${LLVM_TOOLS_BINARY_DIR}/${LLVM_RUNTIMES_TARGET}") + else() + set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR}) + set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR}) + endif() # This variable makes sure that e.g. llvm-lit is found. set(LLVM_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR}) if(APPLE) - set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "") + set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "") endif() set(SAFE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) @@ -96,6 +101,12 @@ # The subdirectories need to treat this as standalone builds set(${canon_name}_STANDALONE_BUILD On) + if(LLVM_RUNTIMES_TARGET) + if(NOT "${entry}" MATCHES "compiler-rt") + set(${canon_name}_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/lib/${LLVM_RUNTIMES_TARGET}" CACHE PATH "" FORCE) + endif() + endif() + # Setting a variable to let sub-projects detect which other projects # will be included under here. set(HAVE_${canon_name} On) @@ -190,6 +201,10 @@ add_custom_target(builtins) add_custom_target(install-builtins) foreach(target ${LLVM_BUILTIN_TARGETS}) + if(target STREQUAL "default") + set(target ${LLVM_DEFAULT_TARGET_TRIPLE}) + endif() + string(REPLACE "-" ";" builtin_target_list ${target}) foreach(item ${builtin_target_list}) string(TOLOWER "${item}" item_lower) @@ -247,39 +262,108 @@ endforeach() if(runtimes) + # Create a runtimes target that uses this file as its top-level CMake file. + # The runtimes target is a configuration of all the runtime libraries + # together in a single CMake invocaiton. + if(NOT LLVM_RUNTIME_TARGETS) + foreach(runtime_name ${runtime_names}) + list(APPEND extra_targets + ${runtime_name} + install-${runtime_name} + check-${runtime_name}) + endforeach() - foreach(runtime_name ${runtime_names}) - list(APPEND extra_targets - ${runtime_name} - install-${runtime_name} - check-${runtime_name}) - endforeach() + if(LLVM_INCLUDE_TESTS) + set(test_targets runtimes-test-depends check-runtimes) + foreach(component ${SUB_COMPONENTS}) + list(APPEND SUB_COMPONENT_CHECK_TARGETS check-${component}) + endforeach() + endif() - if(LLVM_INCLUDE_TESTS) - set(test_targets runtimes-test-depends check-runtimes) - foreach(component ${SUB_COMPONENTS}) - list(APPEND SUB_COMPONENT_CHECK_TARGETS check-${component}) + 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} + PASSTHROUGH_PREFIXES ${prefixes} + EXTRA_TARGETS ${extra_targets} + ${test_targets} + ${SUB_COMPONENTS} + ${SUB_COMPONENT_CHECK_TARGETS} + ${SUB_INSTALL_TARGETS} + USE_TOOLCHAIN + ${EXTRA_ARGS}) + else() + get_cmake_property(variableNames VARIABLES) + add_custom_target(runtimes) + add_custom_target(install-runtimes) + if(LLVM_INCLUDE_TESTS) + add_custom_target(check-runtimes) + add_custom_target(runtimes-test-depends) + endif() + foreach(target ${LLVM_RUNTIME_TARGETS}) + if(target STREQUAL "default") + set(target ${LLVM_DEFAULT_TARGET_TRIPLE}) + endif() + + foreach(runtime_name ${runtime_names}) + list(APPEND ${target}_extra_targets + ${runtime_name}-${target} + install-${runtime_name}-${target} + check-${runtime_name}-${target}) + endforeach() + + if(LLVM_INCLUDE_TESTS) + set(${target}_test_targets runtimes-test-depends-${target} check-runtimes-${target}) + foreach(component ${SUB_COMPONENTS}) + list(APPEND SUB_COMPONENT_CHECK_TARGETS check-${component}-${target}) + endforeach() + endif() + + foreach(variableName ${variableNames}) + if(variableName MATCHES "^RUNTIMES_${target}") + string(REPLACE "RUNTIMES_${target}_" "" new_name ${variableName}) + list(APPEND ${target}_extra_args "-D${new_name}=${${variableName}}") + endif() + endforeach() + + if(NOT target STREQUAL LLVM_DEFAULT_TARGET_TRIPLE) + list(APPEND ${target}_extra_args "-DLLVM_RUNTIMES_TARGET=${target}") + endif() + + llvm_ExternalProject_Add(runtimes-${target} + ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${deps} + # Builtins were built separately above + CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off + -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS} + -DCMAKE_C_COMPILER_TARGET=${target} + -DCMAKE_CXX_COMPILER_TARGET=${target} + -DCMAKE_ASM_COMPILER_TARGET=${target} + -DCMAKE_C_COMPILER_WORKS=ON + -DCMAKE_CXX_COMPILER_WORKS=ON + -DCMAKE_ASM_COMPILER_WORKS=ON + -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON + ${${target}_extra_args} + PASSTHROUGH_PREFIXES ${prefixes} + EXTRA_TARGETS ${${target}_extra_targets} + ${${target}_test_targets} + ${SUB_COMPONENTS} + ${SUB_COMPONENT_CHECK_TARGETS} + ${SUB_INSTALL_TARGETS} + USE_TOOLCHAIN + ${EXTRA_ARGS}) + + add_dependencies(runtimes runtimes-${target}) + add_dependencies(install-runtimes install-runtimes-${target}) + if(LLVM_INCLUDE_TESTS) + add_dependencies(check-runtimes check-runtimes-${target}) + add_dependencies(runtimes-test-depends runtimes-test-depends-${target}) + endif() endforeach() endif() - # Create a runtimes target that uses this file as its top-level CMake file. - # The runtimes target is a configuration of all the runtime libraries - # together in a single CMake invocaiton. - 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} - PASSTHROUGH_PREFIXES ${prefixes} - EXTRA_TARGETS ${extra_targets} - ${test_targets} - ${SUB_COMPONENTS} - ${SUB_COMPONENT_CHECK_TARGETS} - ${SUB_INSTALL_TARGETS} - USE_TOOLCHAIN - ${EXTRA_ARGS}) - # TODO: This is a hack needed because the libcxx headers are copied into the # build directory during configuration. Without that step the clang in the # build directory cannot find the C++ headers in certain configurations.