aboutsummaryrefslogtreecommitdiff
path: root/test/CMakeLists.txt
blob: a11b83a854cb0d1bfed4b633a90b823974a43234 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Test runner infrastructure for Clang. This configures the Clang test trees
# for use by Lit, and delegates to LLVM's lit test handlers.
#
# If this is a stand-alone Clang build, we fake up our own Lit support here
# rather than relying on LLVM's.

set(CLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
set(CLANG_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/..")

configure_lit_site_cfg(
  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
  )

configure_lit_site_cfg(
  ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
  ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
  )

if( PATH_TO_LLVM_BUILD )
  set(CLANG_TEST_EXTRA_ARGS "--path=${CLANG_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}")
endif()

option(CLANG_TEST_USE_VG "Run Clang tests under Valgrind" OFF)
if(CLANG_TEST_USE_VG)
  set(CLANG_TEST_EXTRA_ARGS ${CLANG_TEST_EXTRA_ARGS} "--vg")
endif ()

set(CLANG_TEST_DEPS
  clang clang-headers
  c-index-test diagtool arcmt-test c-arcmt-test
  clang-check clang-format
  )
set(CLANG_TEST_PARAMS
  clang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
  )

if(CLANG_INCLUDE_TESTS)  
  list(APPEND CLANG_TEST_DEPS ClangUnitTests)
  list(APPEND CLANG_TEST_PARAMS
    clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
    )
endif()

if( NOT CLANG_BUILT_STANDALONE )
  list(APPEND CLANG_TEST_DEPS
    llc opt FileCheck count not llvm-symbolizer
    )

  add_lit_testsuite(check-clang "Running the Clang regression tests"
    ${CMAKE_CURRENT_BINARY_DIR}
    PARAMS ${CLANG_TEST_PARAMS}
    DEPENDS ${CLANG_TEST_DEPS}
    ARGS ${CLANG_TEST_EXTRA_ARGS}
    )
  set_target_properties(check-clang PROPERTIES FOLDER "Clang tests")

else()

  include(FindPythonInterp)
  if(PYTHONINTERP_FOUND)
    if( LLVM_MAIN_SRC_DIR )
      set(LIT "${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py")
    else()
      set(LIT "${PATH_TO_LLVM_BUILD}/bin/${CMAKE_CFG_INTDIR}/llvm-lit")
      # Installed LLVM does not contain ${CMAKE_CFG_INTDIR} in paths.
      if( NOT EXISTS ${LIT} )
        set(LIT "${PATH_TO_LLVM_BUILD}/bin/llvm-lit")
      endif()
    endif()

    set(LIT_ARGS "${CLANG_TEST_EXTRA_ARGS} ${LLVM_LIT_ARGS}")
    separate_arguments(LIT_ARGS)
    
    list(APPEND CLANG_TEST_PARAMS build_mode=${CMAKE_CFG_INTDIR})

    foreach(param ${CLANG_TEST_PARAMS})
      list(APPEND LIT_ARGS --param ${param})
    endforeach()

    add_custom_target(check-clang
      COMMAND ${PYTHON_EXECUTABLE}
              ${LIT}
              ${LIT_ARGS}
              ${CMAKE_CURRENT_BINARY_DIR}
              ${CLANG_TEST_EXTRA_ARGS}
      COMMENT "Running Clang regression tests"
      DEPENDS ${CLANG_TEST_DEPS}
      )
    set_target_properties(check-clang PROPERTIES FOLDER "Clang tests")
  endif()

endif()

# Add a legacy target spelling: clang-test
add_custom_target(clang-test)
add_dependencies(clang-test check-clang)
set_target_properties(clang-test PROPERTIES FOLDER "Clang tests")