• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# This file handles building LLVM runtime sub-projects.
2
3# Runtimes are different from tools or other drop-in projects because runtimes
4# should be built with the LLVM toolchain from the build directory. This file is
5# a first step to formalizing runtime build interfaces.
6
7# In the current state this file only works with compiler-rt, other runtimes
8# will work as the runtime build interface standardizes.
9
10# Find all subdirectories containing CMake projects
11file(GLOB entries *)
12foreach(entry ${entries})
13  if(IS_DIRECTORY ${entry} AND EXISTS ${entry}/CMakeLists.txt)
14    list(APPEND runtimes ${entry})
15  endif()
16endforeach()
17
18# If this file is acting as a top-level CMake invocation, this code path is
19# triggered by the external project call for the runtimes target below.
20if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
21
22  cmake_minimum_required(VERSION 3.4.3)
23
24  # Add the root project's CMake modules, and the LLVM build's modules to the
25  # CMake module path.
26  list(INSERT CMAKE_MODULE_PATH 0
27    "${CMAKE_CURRENT_SOURCE_DIR}/../cmake"
28    "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules"
29    "${LLVM_BINARY_DIR}/lib/cmake/llvm"
30  )
31
32  # LLVMConfig.cmake contains a bunch of CMake variables from the LLVM build.
33  # This file is installed as part of LLVM distributions, so this can be used
34  # either from a build directory or an installed LLVM.
35  include(LLVMConfig)
36
37  # Setting these variables will allow the sub-build to put their outputs into
38  # the library and bin directories of the top-level build.
39  set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR})
40  set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_BINARY_DIR})
41
42  foreach(entry ${runtimes})
43    get_filename_component(projName ${entry} NAME)
44
45    # TODO: Clean this up as part of an interface standardization
46    string(REPLACE "-" "_" canon_name ${projName})
47    string(TOUPPER ${canon_name} canon_name)
48    # The subdirectories need to treat this as standalone builds
49    set(${canon_name}_STANDALONE_BUILD On)
50
51    add_subdirectory(${projName})
52  endforeach()
53
54else() # if this is included from LLVM's CMake
55  include(LLVMExternalProjectUtils)
56
57  # If compiler-rt is present we need to build the builtin libraries first. This
58  # is required because the other runtimes need the builtin libraries present
59  # before the just-built compiler can pass the configuration tests.
60  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt)
61    llvm_ExternalProject_Add(builtins
62                             ${CMAKE_CURRENT_SOURCE_DIR}/compiler-rt/lib/builtins
63                             PASSTHROUGH_PREFIXES COMPILER_RT
64                             USE_TOOLCHAIN)
65    set(deps builtins)
66  endif()
67
68  # We create a list the names of all the runtime projects in all uppercase and
69  # with dashes turned to underscores. This gives us the CMake variable prefixes
70  # for all variables that will apply to runtimes.
71  foreach(entry ${runtimes})
72    get_filename_component(projName ${entry} NAME)
73    string(REPLACE "-" "_" canon_name ${projName})
74    string(TOUPPER ${canon_name} canon_name)
75    list(APPEND prefixes ${canon_name})
76  endforeach()
77
78  if(runtimes)
79    # Create a runtimes target that uses this file as its top-level CMake file.
80    # The runtimes target is a configuration of all the runtime libraries
81    # together in a single CMake invocaiton.
82    llvm_ExternalProject_Add(runtimes
83                             ${CMAKE_CURRENT_SOURCE_DIR}
84                             DEPENDS ${deps} llvm-config
85                             # Builtins were built separately above
86                             CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
87                             PASSTHROUGH_PREFIXES ${prefixes}
88                             USE_TOOLCHAIN)
89  endif()
90endif()
91