Skip to content

Commit

Permalink
[CMake] Propagate top-level targets for compiler-rt runtimes and test…
Browse files Browse the repository at this point in the history
…-suites

from (external) compiler-rt build tree into LLVM/Clang build tree in
LLVM_BUILD_EXTERNAL_COMPILER_RT mode.

For instance, running
  make asan -j12
in LLVM/Clang build tree will now build Clang, use it to configure
compiler-rt build tree, and invoke "make asan -j12" there. ASan runtime will
be built in the proper location, where Clang driver expects to find it.

Running
  make check-asan
will build Clang, use it to configure compiler-rt build tree, build everything
there, and then run "make check-asan" in compiler-rt build tree using just-built
Clang and ASan runtime.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204463 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Alexey Samsonov committed Mar 21, 2014
1 parent 59aca27 commit fb9697c
Showing 1 changed file with 46 additions and 14 deletions.
60 changes: 46 additions & 14 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ foreach (dir ${known_subdirs})
endif()
endforeach()

function(get_ext_project_build_command out_var target)
if (CMAKE_GENERATOR MATCHES "Make")
# Use special command for Makefiles to support parallelism.
set(${out_var} "$(MAKE)" "${target}" PARENT_SCOPE)
else()
set(${out_var} ${CMAKE_COMMAND} --build . --target ${target}
--config $<CONFIGURATION> PARENT_SCOPE)
endif()
endfunction()

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")
Expand All @@ -37,6 +47,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
-DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
-DCOMPILER_RT_ENABLE_WERROR=ON
INSTALL_COMMAND ""
STEP_TARGETS configure build
)
# Due to a bug, DEPENDS in ExternalProject_Add doesn't work
# in CMake 2.8.9 and 2.8.10.
Expand All @@ -57,20 +68,41 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
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)
set(COMPILER_RT_BINARY_DIR ${BINARY_DIR})

# Add top-level targets that build specific compiler-rt runtimes.
set(COMPILER_RT_RUNTIMES asan builtins dfsan lsan msan profile tsan ubsan)
foreach(runtime ${COMPILER_RT_RUNTIMES})
get_ext_project_build_command(build_runtime_cmd ${runtime})
add_custom_target(${runtime}
COMMAND ${build_runtime_cmd}
DEPENDS compiler-rt-configure
WORKING_DIRECTORY ${COMPILER_RT_BINARY_DIR}
VERBATIM)
endforeach()

# Add binaries that compiler-rt tests depend on.
add_dependencies(check-compiler-rt FileCheck count
not llvm-nm llvm-symbolizer)
set(COMPILER_RT_TEST_DEPENDENCIES
FileCheck count not llvm-nm llvm-symbolizer)

# Add top-level targets for various compiler-rt test suites.
set(COMPILER_RT_TEST_SUITES check-asan check-dfsan check-lsan check-msan
check-sanitizer check-tsan check-ubsan)
foreach(test_suite ${COMPILER_RT_TEST_SUITES})
get_ext_project_build_command(run_test_suite ${test_suite})
add_custom_target(${test_suite}
COMMAND ${run_test_suite}
DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
WORKING_DIRECTORY ${COMPILER_RT_BINARY_DIR}
VERBATIM)
endforeach()

# Add special target to run all compiler-rt test suites.
get_ext_project_build_command(run_check_compiler_rt check-all)
add_custom_target(check-compiler-rt
COMMAND ${run_check_compiler_rt}
DEPENDS compiler-rt-build ${COMPILER_RT_TEST_DEPENDENCIES}
WORKING_DIRECTORY ${COMPILER_RT_BINARY_DIR}
VERBATIM)
endif()

0 comments on commit fb9697c

Please sign in to comment.