This patch builds on LLVM r279776.
In this patch I've done some cleanup and abstracted three common steps runtime components have in their CMakeLists files, and added a fourth.
The three steps I abstract are:
(1) Add a top-level target (i.e asan, msan, ...)
(2) Set the target properties for sorting files in IDE generators
(3) Make the compiler-rt target depend on the top-level target
The new step is to check if a command named "runtime_register_component" is defined, and to call it with the component name.
The runtime_register_component command is defined in llvm/runtimes/CMakeLists.txt, and presently just adds the component to a list of sub-components, which later gets used to generate target mappings.
With this patch a new workflow for runtimes builds is supported. The new workflow when building runtimes from the LLVM runtimes directory is:
> cmake [...]
> ninja runtimes-configure
> ninja asan
The "runtimes-configure" target builds all the dependencies for configuring the runtimes projects, and runs CMake on the runtimes projects. Running the runtimes CMake generates a list of targets to bind into the top-level CMake so subsequent build invocations will have access to some of Compiler-RT's targets through the top-level build.
Note: This patch does exclude some top-level targets from compiler-rt libraries because they either don't install files (sanitizer_common), or don't have a cooresponding `check` target (stats).
llvm-svn: 279863
endforeach()
endmacro()
+function(add_compiler_rt_component name)
+ add_custom_target(${name})
+ set_target_properties(${name} PROPERTIES FOLDER "Compiler-RT Misc")
+ if(COMMAND runtime_register_component)
+ runtime_register_component(${name})
+ endif()
+ add_dependencies(compiler-rt ${name})
+endfunction()
+
# Adds static or shared runtime for a list of architectures and operating
# systems and puts it in the proper directory in the build and install trees.
# add_compiler_rt_runtime(<name>
endif()
# Build ASan runtimes shipped with Clang.
-add_custom_target(asan)
-set_target_properties(asan PROPERTIES FOLDER "Compiler-RT Misc")
+add_compiler_rt_component(asan)
if(APPLE)
add_compiler_rt_runtime(clang_rt.asan
endif()
add_compiler_rt_resource_file(asan_blacklist asan_blacklist.txt asan)
-add_dependencies(compiler-rt asan)
add_subdirectory(scripts)
-add_custom_target(cfi)
-set_target_properties(cfi PROPERTIES FOLDER "Compiler-RT Misc")
+add_compiler_rt_component(cfi)
set(CFI_SOURCES cfi.cc)
endforeach()
add_compiler_rt_resource_file(cfi_blacklist cfi_blacklist.txt cfi)
-add_dependencies(compiler-rt cfi)
append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding DFSAN_COMMON_CFLAGS)
# Static runtime library.
-add_custom_target(dfsan)
-set_target_properties(dfsan PROPERTIES FOLDER "Compiler-RT Misc")
+add_compiler_rt_component(dfsan)
foreach(arch ${DFSAN_SUPPORTED_ARCH})
set(DFSAN_CFLAGS ${DFSAN_COMMON_CFLAGS})
add_dependencies(dfsan dfsan_abilist)
install(FILES ${dfsan_abilist_filename}
DESTINATION ${COMPILER_RT_INSTALL_PATH})
-
-add_dependencies(compiler-rt dfsan)
# Build for the EfficiencySanitizer runtime support library.
-add_custom_target(esan)
-set_target_properties(esan PROPERTIES FOLDER "Compiler-RT Misc")
+add_compiler_rt_component(esan)
set(ESAN_RTL_CFLAGS ${SANITIZER_COMMON_CFLAGS})
append_rtti_flag(OFF ESAN_RTL_CFLAGS)
clang_rt.esan-${arch}-symbols)
endforeach()
-add_dependencies(compiler-rt esan)
-
if (COMPILER_RT_INCLUDE_TESTS)
# TODO(bruening): add tests via add_subdirectory(tests)
endif()
set(LSAN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
-add_custom_target(lsan)
-set_target_properties(lsan PROPERTIES FOLDER "Compiler-RT Misc")
-
add_compiler_rt_object_libraries(RTLSanCommon
OS ${SANITIZER_COMMON_SUPPORTED_OS}
ARCHS ${LSAN_COMMON_SUPPORTED_ARCH}
if(COMPILER_RT_HAS_LSAN)
foreach(arch ${LSAN_SUPPORTED_ARCH})
+ add_compiler_rt_component(lsan)
+
add_compiler_rt_runtime(clang_rt.lsan
STATIC
ARCHS ${arch}
PARENT_TARGET lsan)
endforeach()
endif()
-
-add_dependencies(compiler-rt lsan)
set(MSAN_RUNTIME_LIBRARIES)
# Static runtime library.
-add_custom_target(msan)
-set_target_properties(msan PROPERTIES FOLDER "Compiler-RT Misc")
+add_compiler_rt_component(msan)
foreach(arch ${MSAN_SUPPORTED_ARCH})
add_compiler_rt_runtime(clang_rt.msan
endforeach()
add_compiler_rt_resource_file(msan_blacklist msan_blacklist.txt msan)
-add_dependencies(compiler-rt msan)
if(COMPILER_RT_INCLUDE_TESTS)
add_subdirectory(tests)
" COMPILER_RT_TARGET_HAS_FCNTL_LCK)
-add_custom_target(profile)
-set_target_properties(profile PROPERTIES FOLDER "Compiler-RT Misc")
+add_compiler_rt_component(profile)
set(PROFILE_SOURCES
GCDAProfiling.c
SOURCES ${PROFILE_SOURCES}
PARENT_TARGET profile)
endif()
-
-add_dependencies(compiler-rt profile)
-add_custom_target(safestack)
-set_target_properties(safestack PROPERTIES
- FOLDER "Compiler-RT Misc")
+add_compiler_rt_component(safestack)
set(SAFESTACK_SOURCES safestack.cc)
-add_custom_target(scudo)
-set_target_properties(scudo PROPERTIES FOLDER "Compiler-RT Misc")
+add_compiler_rt_component(scudo)
include_directories(..)
PARENT_TARGET scudo)
endforeach()
endif()
-
-add_dependencies(compiler-rt scudo)
-
rtl/tsan_vector.h)
set(TSAN_RUNTIME_LIBRARIES)
-add_custom_target(tsan)
-set_target_properties(tsan PROPERTIES FOLDER "Compiler-RT Misc")
+add_compiler_rt_component(tsan)
if(APPLE)
set(TSAN_ASM_SOURCES rtl/tsan_rtl_amd64.S)
endforeach()
endif()
-add_dependencies(compiler-rt tsan)
-
# Make sure that non-platform-specific files don't include any system headers.
# FreeBSD does not install a number of Clang-provided headers for the compiler
# in the base system due to incompatibilities between FreeBSD's and Clang's
append_rtti_flag(ON UBSAN_CXXFLAGS)
append_list_if(SANITIZER_CAN_USE_CXXABI -DUBSAN_CAN_USE_CXXABI UBSAN_CXXFLAGS)
-add_custom_target(ubsan)
-set_target_properties(ubsan PROPERTIES FOLDER "Compiler-RT Misc")
+add_compiler_rt_component(ubsan)
if(APPLE)
set(UBSAN_COMMON_SOURCES ${UBSAN_SOURCES})
endif()
endif()
endif()
-
-add_dependencies(compiler-rt ubsan)
SOURCES ${XRAY_SOURCES} CFLAGS ${XRAY_CFLAGS}
DEFS ${XRAY_COMMON_DEFINITIONS})
-add_custom_target(xray)
+add_compiler_rt_component(xray)
+
set(XRAY_COMMON_RUNTIME_OBJECT_LIBS
RTSanitizerCommon
RTSanitizerCommonLibc)
PARENT_TARGET xray)
endif ()
endforeach()
-
-add_dependencies(compiler-rt xray)