Home | History | Annotate | Download | only in Modules
      1 set(SANITIZER_GEN_DYNAMIC_LIST
      2   ${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/scripts/gen_dynamic_list.py)
      3 
      4 set(SANITIZER_LINT_SCRIPT
      5   ${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/scripts/check_lint.sh)
      6 
      7 # Create a target "<name>-<arch>-symbols" that would generate the list of
      8 # symbols that need to be exported from sanitizer runtime "<name>". Function
      9 # interceptors are exported automatically, user can also provide files with
     10 # symbol names that should be exported as well.
     11 #   add_sanitizer_rt_symbols(<name>
     12 #                            ARCHS <architectures>
     13 #                            PARENT_TARGET <convenience parent target>
     14 #                            EXTRA <files with extra symbols to export>)
     15 macro(add_sanitizer_rt_symbols name)
     16   cmake_parse_arguments(ARG
     17     ""
     18     "PARENT_TARGET"
     19     "ARCHS;EXTRA"
     20     ${ARGN})
     21   foreach(arch ${ARG_ARCHS})
     22     set(target_name ${name}-${arch})
     23     set(stamp ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.syms-stamp)
     24     set(extra_args)
     25     foreach(arg ${ARG_EXTRA})
     26       list(APPEND extra_args "--extra" ${arg})
     27     endforeach()
     28     add_custom_command(OUTPUT ${stamp}
     29       COMMAND ${PYTHON_EXECUTABLE}
     30         ${SANITIZER_GEN_DYNAMIC_LIST} ${extra_args} $<TARGET_FILE:${target_name}>
     31         > $<TARGET_FILE:${target_name}>.syms
     32       COMMAND ${CMAKE_COMMAND} -E touch ${stamp}
     33       DEPENDS ${target_name} ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA}
     34       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
     35       COMMENT "Generating exported symbols for ${target_name}"
     36       VERBATIM)
     37     add_custom_target(${target_name}-symbols ALL
     38       DEPENDS ${stamp}
     39       SOURCES ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA})
     40 
     41     if(NOT CMAKE_VERSION VERSION_LESS 3.0)
     42       install(FILES $<TARGET_FILE:${target_name}>.syms
     43               DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
     44     else()
     45       # Per-config install location.
     46       if(CMAKE_CONFIGURATION_TYPES)
     47         foreach(c ${CMAKE_CONFIGURATION_TYPES})
     48           get_target_property(libfile ${target_name} LOCATION_${c})
     49           install(FILES ${libfile}.syms CONFIGURATIONS ${c}
     50             DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
     51         endforeach()
     52       else()
     53         get_target_property(libfile ${target_name} LOCATION_${CMAKE_BUILD_TYPE})
     54         install(FILES ${libfile}.syms DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
     55       endif()
     56     endif()
     57     if(ARG_PARENT_TARGET)
     58       add_dependencies(${ARG_PARENT_TARGET} ${target_name}-symbols)
     59     endif()
     60   endforeach()
     61 endmacro()
     62 
     63 macro(add_sanitizer_rt_version_list name)
     64   set(vers ${CMAKE_CURRENT_BINARY_DIR}/${name}.vers)
     65   cmake_parse_arguments(ARG "" "" "LIBS;EXTRA" ${ARGN})
     66   set(args)
     67   foreach(arg ${ARG_EXTRA})
     68     list(APPEND args "--extra" ${arg})
     69   endforeach()
     70   foreach(arg ${ARG_LIBS})
     71     list(APPEND args "$<TARGET_FILE:${arg}>")
     72   endforeach()
     73   add_custom_command(OUTPUT ${vers}
     74     COMMAND ${PYTHON_EXECUTABLE}
     75       ${SANITIZER_GEN_DYNAMIC_LIST} --version-list ${args}
     76       > ${vers}
     77     DEPENDS ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA} ${ARG_LIBS}
     78     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
     79     COMMENT "Generating version list for ${name}"
     80     VERBATIM)
     81 
     82   add_custom_target(${name}-version-list ALL
     83     DEPENDS ${vers})
     84 endmacro()
     85 
     86 # Add target to check code style for sanitizer runtimes.
     87 if(UNIX)
     88   add_custom_target(SanitizerLintCheck
     89     COMMAND LLVM_CHECKOUT=${LLVM_MAIN_SRC_DIR} SILENT=1 TMPDIR=
     90       PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
     91       COMPILER_RT=${COMPILER_RT_SOURCE_DIR}
     92       ${SANITIZER_LINT_SCRIPT}
     93     DEPENDS ${SANITIZER_LINT_SCRIPT}
     94     COMMENT "Running lint check for sanitizer sources..."
     95     VERBATIM)
     96 endif()
     97 
     98