# should be built with the LLVM toolchain from the build directory. This file is
# a first step to formalizing runtime build interfaces.
-# In the current state this file only works with compiler-rt, other runtimes
-# will work as the runtime build interface standardizes.
+# Setting CMake minimum required version should be at the very top of the file
+# if this is the entry point.
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+ cmake_minimum_required(VERSION 3.4.3)
+ project(Runtimes C CXX ASM)
+endif()
# Find all subdirectories containing CMake projects
file(GLOB entries *)
cmake_minimum_required(VERSION 3.4.3)
project(Runtimes C CXX ASM)
+ find_package(LLVM PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
+
# Add the root project's CMake modules, and the LLVM build's modules to the
# CMake module path.
list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_CURRENT_SOURCE_DIR}/../cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules"
- "${LLVM_LIBRARY_DIR}/cmake/llvm"
)
# Some of the runtimes will conditionally use the compiler-rt sanitizers
endif()
endif()
- # LLVMConfig.cmake contains a bunch of CMake variables from the LLVM build.
- # This file is installed as part of LLVM distributions, so this can be used
- # either from a build directory or an installed LLVM.
- include(LLVMConfig)
-
# 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_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR})
set(LLVM_CMAKE_PATH ${LLVM_MAIN_SRC_DIR}/cmake/modules)
+ # This variable is used by individual runtimes to locate LLVM files.
+ set(LLVM_PATH ${LLVM_BUILD_MAIN_SRC_DIR})
+
if(APPLE)
set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
endif()
# Remove the -nostdlib++ option we've added earlier.
string(REPLACE "-nostdlib++" "" CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
+ # Use libtool instead of ar if you are both on an Apple host, and targeting Apple.
+ if(CMAKE_HOST_APPLE AND APPLE)
+ include(UseLibtool)
+ endif()
+
# This can be used to detect whether we're in the runtimes build.
set(RUNTIMES_BUILD ON)
string(REPLACE "-" "_" canon_name ${projName})
string(TOUPPER ${canon_name} canon_name)
- if(LLVM_RUNTIMES_LIBDIR_SUFFIX)
- set(${canon_name}_LIBDIR_SUFFIX "${LLVM_RUNTIMES_LIBDIR_SUFFIX}" CACHE STRING "" FORCE)
+ # The subdirectories need to treat this as standalone builds. D57992 tried
+ # to get rid of this, but the runtimes treat *_STANDALONE_BUILD=OFF as if
+ # llvm & clang are configured in the same CMake, and setup dependencies
+ # against their targets.
+ set(${canon_name}_STANDALONE_BUILD ON)
+
+ if(LLVM_RUNTIMES_LIBDIR_SUBDIR)
+ set(${canon_name}_LIBDIR_SUBDIR "${LLVM_RUNTIMES_LIBDIR_SUBDIR}" CACHE STRING "" FORCE)
endif()
# Setting a variable to let sub-projects detect which other projects
else() # if this is included from LLVM's CMake
include(LLVMExternalProjectUtils)
+ if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR AND "libcxx" IN_LIST LLVM_ENABLE_RUNTIMES)
+ # This looks wrong, but libcxx's build actually wants the header dir to be
+ # the root build dir, not the include directory.
+ set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR})
+ set(CXX_HEADER_TARGET runtime-libcxx-headers)
+ add_subdirectory(${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR}/include ${CXX_HEADER_TARGET})
+ endif()
if(NOT LLVM_BUILD_RUNTIMES)
set(EXTRA_ARGS EXCLUDE_FROM_ALL)
cmake_parse_arguments(ARG "" "" "DEPENDS;PREFIXES" ${ARGN})
include(${LLVM_BINARY_DIR}/runtimes/Components.cmake OPTIONAL)
+ set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)
foreach(runtime_name ${runtime_names})
llvm_ExternalProject_Add(runtimes
${CMAKE_CURRENT_SOURCE_DIR}
- DEPENDS ${ARG_DEPENDS}
+ DEPENDS ${ARG_DEPENDS} ${CXX_HEADER_TARGET}
# Builtins were built separately above
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
- -DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
-DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE}
+ -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
-DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
-DCMAKE_CXX_COMPILER_TARGET=${TARGET_TRIPLE}
llvm_ExternalProject_Add(runtimes-${name}
${CMAKE_CURRENT_SOURCE_DIR}
- DEPENDS ${${name}_deps}
+ DEPENDS ${${name}_deps} ${CXX_HEADER_TARGET}
# Builtins were built separately above
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
- -DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
-DLLVM_DEFAULT_TARGET_TRIPLE=${target}
+ -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
-DCMAKE_C_COMPILER_TARGET=${target}
-DCMAKE_CXX_COMPILER_TARGET=${target}
runtime_default_target(
DEPENDS ${deps}
PREFIXES ${prefixes})
+ set(test_targets check-runtimes)
else()
if("default" IN_LIST LLVM_RUNTIME_TARGETS)
runtime_default_target(
runtime_register_target(${name}+${multilib} ${name}
DEPENDS runtimes-${name}
CMAKE_ARGS -DLLVM_RUNTIMES_PREFIX=${name}/
- -DLLVM_RUNTIMES_LIBDIR_SUFFIX=/${multilib})
+ -DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib})
add_dependencies(runtimes runtimes-${name}+${multilib})
add_dependencies(runtimes-configure runtimes-${name}+${multilib}-configure)
add_dependencies(install-runtimes install-runtimes-${name}+${multilib})
obj2yaml
sancov
sanstats
+ gtest_main
+ gtest
)
foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS})