<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 11, 2015 at 8:14 AM, Chris Bieneman via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: cbieneman<br>
Date: Wed Nov 11 10:14:03 2015<br>
New Revision: 252747<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=252747&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=252747&view=rev</a><br>
Log:<br>
[CMake] Add support for building the llvm test-suite as part of an LLVM build using clang and lld<br></blockquote><div><br></div><div>Just out of curiosity, will this work (or be extended to work later) without lld? That seems somewhat optional (test-suite has been around since long before the LLVM project had a linker & was used to test the compiler & just assume a sane platform linker would do a good enough job there).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Summary:<br>
This patch adds a new CMake module for working with ExternalProjects. This wrapper for ExternalProject supports using just-built tools and can hook up dependencies properly so that projects get cleared out.<br>
<br>
The example usage here is for the llvm test-suite. In this example, the test-suite is setup as dependent on clang and lld if they are in-tree. If the clang or lld binaries change the test-suite is re-configured, cleaned, and rebuilt.<br>
<br>
This cleanup and abstraction wrapping ExternalProject can be extended and applied to other runtime libraries like compiler-rt and libcxx.<br>
<br>
Reviewers: samsonov, jroelofs, rengolin, jmolloy<br>
<br>
Subscribers: jmolloy, llvm-commits<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D14513" rel="noreferrer" target="_blank">http://reviews.llvm.org/D14513</a><br>
<br>
Added:<br>
llvm/trunk/cmake/modules/LLVMExternalProjectUtils.cmake<br>
Modified:<br>
llvm/trunk/CMakeLists.txt<br>
<br>
Modified: llvm/trunk/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/CMakeLists.txt?rev=252747&r1=252746&r2=252747&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/CMakeLists.txt?rev=252747&r1=252746&r2=252747&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/CMakeLists.txt (original)<br>
+++ llvm/trunk/CMakeLists.txt Wed Nov 11 10:14:03 2015<br>
@@ -683,6 +683,13 @@ if( LLVM_INCLUDE_EXAMPLES )<br>
endif()<br>
<br>
if( LLVM_INCLUDE_TESTS )<br>
+ if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)<br>
+ include(LLVMExternalProjectUtils)<br>
+ llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite<br>
+ USE_TOOLCHAIN<br>
+ EXCLUDE_FROM_ALL<br>
+ NO_INSTALL)<br>
+ endif()<br>
add_subdirectory(test)<br>
add_subdirectory(unittests)<br>
if (MSVC)<br>
<br>
Added: llvm/trunk/cmake/modules/LLVMExternalProjectUtils.cmake<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/LLVMExternalProjectUtils.cmake?rev=252747&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/LLVMExternalProjectUtils.cmake?rev=252747&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/cmake/modules/LLVMExternalProjectUtils.cmake (added)<br>
+++ llvm/trunk/cmake/modules/LLVMExternalProjectUtils.cmake Wed Nov 11 10:14:03 2015<br>
@@ -0,0 +1,194 @@<br>
+include(ExternalProject)<br>
+<br>
+# llvm_ExternalProject_BuildCmd(out_var target)<br>
+# Utility function for constructing command lines for external project targets<br>
+function(llvm_ExternalProject_BuildCmd out_var target)<br>
+ if (CMAKE_GENERATOR MATCHES "Make")<br>
+ # Use special command for Makefiles to support parallelism.<br>
+ set(${out_var} "$(MAKE)" "${target}" PARENT_SCOPE)<br>
+ else()<br>
+ set(${out_var} ${CMAKE_COMMAND} --build . --target ${target}<br>
+ --config $<CONFIGURATION> PARENT_SCOPE)<br>
+ endif()<br>
+endfunction()<br>
+<br>
+# llvm_ExternalProject_Add(name source_dir ...<br>
+# USE_TOOLCHAIN<br>
+# Use just-built tools (see TOOLCHAIN_TOOLS)<br>
+# EXCLUDE_FROM_ALL<br>
+# Exclude this project from the all target<br>
+# NO_INSTALL<br>
+# Don't generate install targets for this project<br>
+# CMAKE_ARGS arguments...<br>
+# Optional cmake arguments to pass when configuring the project<br>
+# TOOLCHAIN_TOOLS targets...<br>
+# Targets for toolchain tools (defaults to clang;lld)<br>
+# DEPENDS targets...<br>
+# Targets that this project depends on<br>
+# EXTRA_TARGETS targets...<br>
+# Extra targets in the subproject to generate targets for<br>
+# )<br>
+function(llvm_ExternalProject_Add name source_dir)<br>
+ cmake_parse_arguments(ARG "USE_TOOLCHAIN;EXCLUDE_FROM_ALL;NO_INSTALL"<br>
+ "SOURCE_DIR"<br>
+ "CMAKE_ARGS;TOOLCHAIN_TOOLS;RUNTIME_LIBRARIES;DEPENDS;EXTRA_TARGETS" ${ARGN})<br>
+ canonicalize_tool_name(${name} nameCanon)<br>
+ if(NOT ARG_TOOLCHAIN_TOOLS)<br>
+ set(ARG_TOOLCHAIN_TOOLS clang lld)<br>
+ endif()<br>
+ foreach(tool ${ARG_TOOLCHAIN_TOOLS})<br>
+ if(TARGET ${tool})<br>
+ list(APPEND TOOLCHAIN_TOOLS ${tool})<br>
+ list(APPEND TOOLCHAIN_BINS $<TARGET_FILE:${tool}>)<br>
+ endif()<br>
+ endforeach()<br>
+<br>
+ if(NOT ARG_RUNTIME_LIBRARIES)<br>
+ set(ARG_RUNTIME_LIBRARIES compiler-rt libcxx)<br>
+ endif()<br>
+ foreach(lib ${ARG_RUNTIME_LIBRARIES})<br>
+ if(TARGET ${lib})<br>
+ list(APPEND RUNTIME_LIBRARIES ${lib})<br>
+ endif()<br>
+ endforeach()<br>
+<br>
+ list(FIND TOOLCHAIN_TOOLS clang FOUND_CLANG)<br>
+ if(FOUND_CLANG GREATER -1)<br>
+ set(CLANG_IN_TOOLCHAIN On)<br>
+ endif()<br>
+<br>
+ if(RUNTIME_LIBRARIES AND CLANG_IN_TOOLCHAIN)<br>
+ list(APPEND TOOLCHAIN_BINS ${RUNTIME_LIBRARIES})<br>
+ endif()<br>
+<br>
+ if(CMAKE_VERSION VERSION_GREATER 3.1.0)<br>
+ set(cmake_3_1_EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL 1)<br>
+ endif()<br>
+<br>
+ if(CMAKE_VERSION VERSION_GREATER 3.3.20150708)<br>
+ set(cmake_3_4_USES_TERMINAL_OPTIONS<br>
+ USES_TERMINAL_CONFIGURE 1<br>
+ USES_TERMINAL_BUILD 1<br>
+ USES_TERMINAL_INSTALL 1<br>
+ )<br>
+ set(cmake_3_4_USES_TERMINAL USES_TERMINAL 1)<br>
+ endif()<br>
+<br>
+ if(CMAKE_VERSION VERSION_GREATER 3.1.20141116)<br>
+ set(cmake_3_2_USES_TERMINAL USES_TERMINAL)<br>
+ endif()<br>
+<br>
+ set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${name}-stamps/)<br>
+ set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${name}-bins/)<br>
+<br>
+ add_custom_target(${name}-clear<br>
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR}<br>
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR}<br>
+ COMMENT "Clobbering ${name} build and stamp directories"<br>
+ ${cmake_3_2_USES_TERMINAL}<br>
+ )<br>
+<br>
+ # Find all variables that start with COMPILER_RT and populate a variable with<br>
+ # them.<br>
+ get_cmake_property(variableNames VARIABLES)<br>
+ foreach(varaibleName ${variableNames})<br>
+ if(${varaibleName} MATCHES "^${nameCanon}")<br>
+ list(APPEND PASSTHROUGH_VARIABLES<br>
+ -D${varaibleName}=${${varaibleName}})<br>
+ endif()<br>
+ endforeach()<br>
+<br>
+ if(ARG_USE_TOOLCHAIN)<br>
+ if(CLANG_IN_TOOLCHAIN)<br>
+ set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang<br>
+ -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)<br>
+ endif()<br>
+ list(APPEND ARG_DEPENDS ${TOOLCHAIN_TOOLS})<br>
+ endif()<br>
+<br>
+ add_custom_command(<br>
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp<br>
+ DEPENDS ${ARG_DEPENDS}<br>
+ COMMAND ${CMAKE_COMMAND} -E touch ${BINARY_DIR}/CMakeCache.txt<br>
+ COMMAND ${CMAKE_COMMAND} -E touch ${STAMP_DIR}/${name}-mkdir<br>
+ COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp<br>
+ COMMENT "Clobbering bootstrap build and stamp directories"<br>
+ )<br>
+<br>
+ add_custom_target(${name}-clobber<br>
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp)<br>
+<br>
+ if(ARG_EXCLUDE_FROM_ALL)<br>
+ set(exclude ${cmake_3_1_EXCLUDE_FROM_ALL})<br>
+ endif()<br>
+<br>
+ ExternalProject_Add(${name}<br>
+ DEPENDS ${ARG_DEPENDS}<br>
+ ${name}-clobber<br>
+ PREFIX ${CMAKE_BINARY_DIR}/projects/${name}<br>
+ SOURCE_DIR ${source_dir}<br>
+ STAMP_DIR ${STAMP_DIR}<br>
+ BINARY_DIR ${BINARY_DIR}<br>
+ ${exclude}<br>
+ CMAKE_ARGS ${${nameCanon}_CMAKE_ARGS}<br>
+ ${compiler_args}<br>
+ -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}<br>
+ ${ARG_CMAKE_ARGS}<br>
+ ${PASSTHROUGH_VARIABLES}<br>
+ INSTALL_COMMAND ""<br>
+ STEP_TARGETS configure build<br>
+ ${cmake_3_4_USES_TERMINAL_OPTIONS}<br>
+ )<br>
+<br>
+ if(ARG_USE_TOOLCHAIN)<br>
+ ExternalProject_Add_Step(${name} force-rebuild<br>
+ COMMENT "Forcing rebuild becaues tools have changed"<br>
+ DEPENDERS configure<br>
+ DEPENDS ${TOOLCHAIN_BINS}<br>
+ ${cmake_3_4_USES_TERMINAL} )<br>
+ endif()<br>
+<br>
+ if(ARG_USE_TOOLCHAIN)<br>
+ set(force_deps DEPENDS ${TOOLCHAIN_BINS})<br>
+ endif()<br>
+<br>
+ llvm_ExternalProject_BuildCmd(run_clean clean)<br>
+ ExternalProject_Add_Step(${name} clean<br>
+ COMMAND ${run_clean}<br>
+ COMMENT "Cleaning ${name}..."<br>
+ DEPENDEES configure<br>
+ ${force_deps}<br>
+ WORKING_DIRECTORY ${BINARY_DIR}<br>
+ ${cmake_3_4_USES_TERMINAL}<br>
+ )<br>
+ ExternalProject_Add_StepTargets(${name} clean)<br>
+<br>
+ if(ARG_USE_TOOLCHAIN)<br>
+ add_dependencies(${name}-clean ${name}-clobber)<br>
+ set_target_properties(${name}-clean PROPERTIES<br>
+ SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp)<br>
+ endif()<br>
+<br>
+ if(NOT ARG_NO_INSTALL)<br>
+ install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${BINARY_DIR}/cmake_install.cmake \)"<br>
+ COMPONENT ${name})<br>
+<br>
+ add_custom_target(install-${name}<br>
+ DEPENDS ${name}<br>
+ COMMAND "${CMAKE_COMMAND}"<br>
+ -DCMAKE_INSTALL_COMPONENT=${name}<br>
+ -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"<br>
+ ${cmake_3_2_USES_TERMINAL})<br>
+ endif()<br>
+<br>
+ # Add top-level targets<br>
+ foreach(target ${ARG_EXTRA_TARGETS})<br>
+ llvm_ExternalProject_BuildCmd(build_runtime_cmd ${target})<br>
+ add_custom_target(${target}<br>
+ COMMAND ${build_runtime_cmd}<br>
+ DEPENDS ${name}-configure<br>
+ WORKING_DIRECTORY ${BINARY_DIR}<br>
+ VERBATIM<br>
+ ${cmake_3_2_USES_TERMINAL})<br>
+ endforeach()<br>
+endfunction()<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>