1include(LLVMParseArguments)
2
3set(SANITIZER_GEN_DYNAMIC_LIST
4  ${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/scripts/gen_dynamic_list.py)
5
6set(SANITIZER_LINT_SCRIPT
7  ${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/scripts/check_lint.sh)
8
9# Create a target "<name>-symbols" that would generate the list of symbols
10# that need to be exported from sanitizer runtime "<name>". Function
11# interceptors are exported automatically, user can also provide files with
12# symbol names that should be exported as well.
13#   add_sanitizer_rt_symbols(<name> <files with extra symbols to export>)
14macro(add_sanitizer_rt_symbols name)
15  set(stamp ${CMAKE_CURRENT_BINARY_DIR}/${name}.syms-stamp)
16  add_custom_command(OUTPUT ${stamp}
17    COMMAND ${PYTHON_EXECUTABLE}
18      ${SANITIZER_GEN_DYNAMIC_LIST} $<TARGET_FILE:${name}> ${ARGN}
19      > $<TARGET_FILE:${name}>.syms
20    COMMAND ${CMAKE_COMMAND} -E touch ${stamp}
21    DEPENDS ${name} ${SANITIZER_GEN_DYNAMIC_LIST} ${ARGN}
22    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
23    COMMENT "Generating exported symbols for ${name}"
24    VERBATIM)
25  add_custom_target(${name}-symbols ALL
26    DEPENDS ${stamp}
27    SOURCES ${SANITIZER_GEN_DYNAMIC_LIST} ${ARGN})
28
29  if(NOT CMAKE_VERSION VERSION_LESS 3.0)
30    install(FILES $<TARGET_FILE:${name}>.syms
31            DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
32  else()
33    # Per-config install location.
34    if(CMAKE_CONFIGURATION_TYPES)
35      foreach(c ${CMAKE_CONFIGURATION_TYPES})
36        get_target_property(libfile ${name} LOCATION_${c})
37        install(FILES ${libfile}.syms CONFIGURATIONS ${c}
38          DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
39      endforeach()
40    else()
41      get_target_property(libfile ${name} LOCATION_${CMAKE_BUILD_TYPE})
42      install(FILES ${libfile}.syms DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
43    endif()
44  endif()
45endmacro()
46
47# Add target to check code style for sanitizer runtimes.
48if(UNIX)
49  add_custom_target(SanitizerLintCheck
50    COMMAND LLVM_CHECKOUT=${LLVM_MAIN_SRC_DIR} SILENT=1 TMPDIR=
51      PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
52      COMPILER_RT=${COMPILER_RT_SOURCE_DIR}
53      ${SANITIZER_LINT_SCRIPT}
54    DEPENDS ${SANITIZER_LINT_SCRIPT}
55    COMMENT "Running lint check for sanitizer sources..."
56    VERBATIM)
57endif()
58
59