llvm.org GIT mirror llvm / f444c52
[CMake] Add LLVM runtimes directory Summary: There are a few LLVM projects that produce runtime libraries. Ideally runtime libraries should be built differently than other projects, specifically they should be built using the just-built toolchain. There is support for building compiler-rt in this way from the clang build. Moving this logic into the LLVM build is interesting because it provides a simpler way to extend the just-built toolchain to include LLD and the LLVM object file tools. Once this functionality is better fleshed out and tested we’ll want to encapsulate it in a module that can be used for clang standalone builds, and we’ll want to make it the default way to build compiler-rt. With this patch applied there is no immediate change in the build. Moving compiler-rt out from llvm/projects into llvm/runtimes enables the functionality. This code has a few improvements over the method provided by LLVM_BUILD_EXTERNAL_COMPILER_RT. Specifically the sub-ninja command is always invoked, so changes to compiler-rt source files will get built properly, so this patch can be used for iterative development with just-built tools. This first patch only works with compiler-rt. Support for other runtime projects will be coming in follow-up patches. Reviewers: chandlerc, bogner Subscribers: kubabrecka, llvm-commits Differential Revision: http://reviews.llvm.org/D20992 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273620 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 4 years ago
4 changed file(s) with 126 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
4545 projects/*
4646 !projects/*.*
4747 !projects/Makefile
48 runtimes/*
49 !runtimes/*.*
4850 # Clang, which is tracked independently.
4951 tools/clang
5052 # LLDB, which is tracked independently.
731731 add_subdirectory(tools)
732732 endif()
733733
734 add_subdirectory(runtimes)
735
734736 if( LLVM_INCLUDE_EXAMPLES )
735737 add_subdirectory(examples)
736738 endif()
741743 llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
742744 USE_TOOLCHAIN
743745 EXCLUDE_FROM_ALL
744 NO_INSTALL)
746 NO_INSTALL
747 ALWAYS_CLEAN)
745748 endif()
746749 add_subdirectory(test)
747750 add_subdirectory(unittests)
1818 # Exclude this project from the all target
1919 # NO_INSTALL
2020 # Don't generate install targets for this project
21 # ALWAYS_CLEAN
22 # Always clean the sub-project before building
2123 # CMAKE_ARGS arguments...
2224 # Optional cmake arguments to pass when configuring the project
2325 # TOOLCHAIN_TOOLS targets...
2628 # Targets that this project depends on
2729 # EXTRA_TARGETS targets...
2830 # Extra targets in the subproject to generate targets for
31 # PASSTHROUGH_PREFIXES prefix...
32 # Extra variable prefixes (name is always included) to pass down
2933 # )
3034 function(llvm_ExternalProject_Add name source_dir)
31 cmake_parse_arguments(ARG "USE_TOOLCHAIN;EXCLUDE_FROM_ALL;NO_INSTALL"
35 cmake_parse_arguments(ARG
36 "USE_TOOLCHAIN;EXCLUDE_FROM_ALL;NO_INSTALL;ALWAYS_CLEAN"
3237 "SOURCE_DIR"
33 "CMAKE_ARGS;TOOLCHAIN_TOOLS;RUNTIME_LIBRARIES;DEPENDS;EXTRA_TARGETS" ${ARGN})
38 "CMAKE_ARGS;TOOLCHAIN_TOOLS;RUNTIME_LIBRARIES;DEPENDS;EXTRA_TARGETS;PASSTHROUGH_PREFIXES"
39 ${ARGN})
3440 canonicalize_tool_name(${name} nameCanon)
3541 if(NOT ARG_TOOLCHAIN_TOOLS)
3642 set(ARG_TOOLCHAIN_TOOLS clang lld)
5157 endif()
5258 endforeach()
5359
60 if(ARG_ALWAYS_CLEAN)
61 set(always_clean clean)
62 endif()
63
5464 list(FIND TOOLCHAIN_TOOLS clang FOUND_CLANG)
5565 if(FOUND_CLANG GREATER -1)
5666 set(CLANG_IN_TOOLCHAIN On)
7080 USES_TERMINAL
7181 )
7282
73 # Find all variables that start with COMPILER_RT and populate a variable with
74 # them.
83 # Find all variables that start with a prefix and propagate them through
7584 get_cmake_property(variableNames VARIABLES)
76 foreach(variableName ${variableNames})
77 if(variableName MATCHES "^${nameCanon}")
78 string(REPLACE ";" "\;" value "${${variableName}}")
79 list(APPEND PASSTHROUGH_VARIABLES
80 -D${variableName}=${value})
81 endif()
85
86 list(APPEND ARG_PASSTHROUGH_PREFIXES ${nameCanon})
87 foreach(prefix ${ARG_PASSTHROUGH_PREFIXES})
88 foreach(variableName ${variableNames})
89 if(variableName MATCHES "^${prefix}")
90 string(REPLACE ";" "\;" value "${${variableName}}")
91 list(APPEND PASSTHROUGH_VARIABLES
92 -D${variableName}=${value})
93 endif()
94 endforeach()
8295 endforeach()
8396
8497 if(ARG_USE_TOOLCHAIN)
116129 CMAKE_ARGS ${${nameCanon}_CMAKE_ARGS}
117130 ${compiler_args}
118131 -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
132 -DLLVM_BINARY_DIR=${PROJECT_BINARY_DIR}
133 -DLLVM_CONFIG_PATH=$
134 -DLLVM_ENABLE_WERROR=${LLVM_ENABLE_WERROR}
135 -DPACKAGE_VERSION=${PACKAGE_VERSION}
136 -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
137 -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
119138 ${ARG_CMAKE_ARGS}
120139 ${PASSTHROUGH_VARIABLES}
121140 INSTALL_COMMAND ""
137156 DEPENDEES configure
138157 ${force_deps}
139158 WORKING_DIRECTORY ${BINARY_DIR}
159 EXCLUDE_FROM_MAIN 1
140160 USES_TERMINAL 1
141161 )
142162 ExternalProject_Add_StepTargets(${name} clean)
0 # This file handles building LLVM runtime sub-projects.
1
2 # Runtimes are different from tools or other drop-in projects because runtimes
3 # should be built with the LLVM toolchain from the build directory. This file is
4 # a first step to formalizing runtime build interfaces.
5
6 # In the current state this file only works with compiler-rt, other runtimes
7 # will work as the runtime build interface standardizes.
8
9 # Find all subdirectories containing CMake projects
10 file(GLOB entries *)
11 foreach(entry ${entries})
12 if(IS_DIRECTORY ${entry} AND EXISTS ${entry}/CMakeLists.txt)
13 list(APPEND runtimes ${entry})
14 endif()
15 endforeach()
16
17 # If this file is acting as a top-level CMake invocation, this code path is
18 # triggered by the external project call for the runtimes target below.
19 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
20
21 cmake_minimum_required(VERSION 3.4.3)
22
23 # Add the root project's CMake modules, and the LLVM build's modules to the
24 # CMake module path.
25 list(INSERT CMAKE_MODULE_PATH 0
26 "${CMAKE_CURRENT_SOURCE_DIR}/../cmake"
27 "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules"
28 "${LLVM_BINARY_DIR}/lib/cmake/llvm"
29 )
30
31 # LLVMConfig.cmake contains a bunch of CMake variables from the LLVM build.
32 # This file is installed as part of LLVM distributions, so this can be used
33 # either from a build directory or an installed LLVM.
34 include(LLVMConfig)
35
36 # Setting these variables will allow the sub-build to put their outputs into
37 # the library and bin directories of the top-level build.
38 set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR})
39 set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_BINARY_DIR})
40
41 foreach(entry ${runtimes})
42 get_filename_component(projName ${entry} NAME)
43
44 # TODO: Clean this up as part of an interface standardization
45 string(REPLACE "-" "_" canon_name ${projName})
46 string(TOUPPER ${canon_name} canon_name)
47 # The subdirectories need to treat this as standalone builds
48 set(${canon_name}_STANDALONE_BUILD On)
49
50 add_subdirectory(${projName})
51 endforeach()
52
53 else() # if this is included from LLVM's CMake
54 include(LLVMExternalProjectUtils)
55
56 # If compiler-rt is present we need to build the builtin libraries first. This
57 # is required because the other runtimes need the builtin libraries present
58 # before the just-built compiler can pass the configuration tests.
59 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt)
60 llvm_ExternalProject_Add(builtins
61 ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt/lib/builtins
62 PASSTHROUGH_PREFIXES COMPILER_RT
63 USE_TOOLCHAIN)
64 set(deps builtins)
65 endif()
66
67 # We create a list the names of all the runtime projects in all uppercase and
68 # with dashes turned to underscores. This gives us the CMake variable prefixes
69 # for all variables that will apply to runtimes.
70 foreach(entry ${runtimes})
71 get_filename_component(projName ${entry} NAME)
72 string(REPLACE "-" "_" canon_name ${projName})
73 string(TOUPPER ${canon_name} canon_name)
74 list(APPEND prefixes ${canon_name})
75 endforeach()
76
77 if(runtimes)
78 # Create a runtimes target that uses this file as its top-level CMake file.
79 # The runtimes target is a configuration of all the runtime libraries
80 # together in a single CMake invocaiton.
81 llvm_ExternalProject_Add(runtimes
82 ${CMAKE_CURRENT_SOURCE_DIR}
83 DEPENDS ${deps} llvm-config
84 # Builtins were built separately above
85 CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
86 PASSTHROUGH_PREFIXES ${prefixes}
87 USE_TOOLCHAIN)
88 endif()
89 endif()