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