aboutsummaryrefslogtreecommitdiff
path: root/clang/runtime/CMakeLists.txt
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2014-02-27 09:09:39 +0000
committerAlexey Samsonov <samsonov@google.com>2014-02-27 09:09:39 +0000
commit8a25994c25b5612714945e53839d505ac434b385 (patch)
treeb01bcea606d76b064645805deef2c69d607b5aad /clang/runtime/CMakeLists.txt
parent511118c7622bb01563ccaa23fe3bdb93a00ff54d (diff)
downloadllvm-project-8a25994c25b5612714945e53839d505ac434b385.tar.gz
[CMake] Teach build system to build/test compiler-rt with a just-built Clang
With this change, one may set LLVM_BUILD_EXTERNAL_COMPILER_RT option to build compiler-rt libraries with just-built Clang. make compiler-rt in the build tree will build all compiler-rt libraries with just-built Clang and copy them to the proper location in the Clang resource directory. make check-compiler-rt will run the compiler-rt test suite using just-built Clang and runtime libraries. The goal is to make LLVM_BUILD_EXTERNAL_COMPILER_RT the default, so that we can always build compiler-rt libraries with Clang, not the host compiler, and for all the platforms Clang can target. llvm-svn: 202367
Diffstat (limited to 'clang/runtime/CMakeLists.txt')
-rw-r--r--clang/runtime/CMakeLists.txt66
1 files changed, 65 insertions, 1 deletions
diff --git a/clang/runtime/CMakeLists.txt b/clang/runtime/CMakeLists.txt
index 68ee266ecae9..42aa378b934c 100644
--- a/clang/runtime/CMakeLists.txt
+++ b/clang/runtime/CMakeLists.txt
@@ -1,7 +1,8 @@
# TODO: Set the install directory.
+include(ExternalProject)
+
set(known_subdirs
- "compiler-rt"
"libcxx"
)
@@ -10,3 +11,66 @@ foreach (dir ${known_subdirs})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${dir})
endif()
endforeach()
+
+set(COMPILER_RT_SRC_ROOT ${LLVM_MAIN_SRC_DIR}/projects/compiler-rt)
+if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
+ if(CMAKE_GENERATOR MATCHES "Ninja")
+ message(FATAL_ERROR
+ "Ninja generator can't build compiler-rt as ExternalProject."
+ "Unset LLVM_BUILD_EXTERNAL_COMPILER_RT, or don't use Ninja."
+ "See http://www.cmake.org/Bug/view.php?id=14771")
+ endif()
+
+ # Add compiler-rt as an external project.
+ set(COMPILER_RT_PREFIX ${CMAKE_BINARY_DIR}/projects/compiler-rt)
+
+ ExternalProject_Add(compiler-rt
+ PREFIX ${COMPILER_RT_PREFIX}
+ SOURCE_DIR ${COMPILER_RT_SRC_ROOT}
+ CMAKE_ARGS -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
+ -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
+ -DCMAKE_BUILD_TYPE=Release
+ -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config
+ -DCOMPILER_RT_OUTPUT_DIR=${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}
+ -DCOMPILER_RT_EXEC_OUTPUT_DIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
+ -DCOMPILER_RT_INSTALL_PATH=lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}
+ -DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
+ -DCOMPILER_RT_ENABLE_WERROR=ON
+ INSTALL_COMMAND ""
+ )
+ # Due to a bug, DEPENDS in ExternalProject_Add doesn't work
+ # in CMake 2.8.9 and 2.8.10.
+ add_dependencies(compiler-rt llvm-config clang)
+
+ # Add a custom step to always re-configure compiler-rt (in case some of its
+ # sources have changed).
+ ExternalProject_Add_Step(compiler-rt force-reconfigure
+ DEPENDERS configure
+ ALWAYS 1
+ )
+
+ ExternalProject_Add_Step(compiler-rt clobber
+ COMMAND ${CMAKE_COMMAND} -E remove_directory <BINARY_DIR>
+ COMMAND ${CMAKE_COMMAND} -E make_directory <BINARY_DIR>
+ COMMENT "Clobberring compiler-rt build directory..."
+ DEPENDERS configure
+ DEPENDS ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
+ )
+
+ if (CMAKE_GENERATOR MATCHES "Make")
+ # Use special command for Makefiles to support parallelism.
+ set(check_command "$(MAKE)" "check-all")
+ else()
+ set(check_command ${CMAKE_COMMAND} --build . --target check-all
+ --config $<CONFIGURATION>)
+ endif()
+ ExternalProject_Get_Property(compiler-rt BINARY_DIR)
+ add_custom_target(check-compiler-rt
+ COMMAND ${check_command}
+ DEPENDS compiler-rt
+ WORKING_DIRECTORY ${BINARY_DIR}
+ VERBATIM)
+ # Add binaries that compiler-rt tests depend on.
+ add_dependencies(check-compiler-rt FileCheck count
+ not llvm-nm llvm-symbolizer)
+endif()