1add_custom_target(LLDBUnitTests)
2set_target_properties(LLDBUnitTests PROPERTIES FOLDER "lldb tests")
3add_dependencies(lldb-test-deps LLDBUnitTests)
4
5include_directories(${LLDB_SOURCE_ROOT})
6include_directories(${LLDB_PROJECT_ROOT}/unittests)
7
8if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
9  add_compile_options("-Wno-suggest-override")
10endif()
11
12set(LLDB_GTEST_COMMON_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/gtest_common.h)
13if (MSVC)
14  list(APPEND LLVM_COMPILE_FLAGS /FI ${LLDB_GTEST_COMMON_INCLUDE})
15else ()
16  list(APPEND LLVM_COMPILE_FLAGS -include ${LLDB_GTEST_COMMON_INCLUDE})
17endif ()
18
19if (LLDB_BUILT_STANDALONE)
20  # Build the gtest library needed for unittests, if we have LLVM sources
21  # handy.
22  if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest AND NOT TARGET gtest)
23    add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/unittest utils/unittest)
24  endif()
25  # LLVMTestingSupport library is needed for Process/gdb-remote.
26  if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Testing/Support
27      AND NOT TARGET LLVMTestingSupport)
28    add_subdirectory(${LLVM_MAIN_SRC_DIR}/lib/Testing/Support
29      lib/Testing/Support)
30  endif()
31endif()
32
33function(add_lldb_unittest test_name)
34  cmake_parse_arguments(ARG
35    ""
36    ""
37    "LINK_LIBS;LINK_COMPONENTS"
38    ${ARGN})
39
40  if (NOT ${test_name} MATCHES "Tests$")
41    message(FATAL_ERROR "Unit test name must end with 'Tests' for lit to find it.")
42  endif()
43
44  list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS})
45
46  add_unittest(LLDBUnitTests
47    ${test_name}
48    ${ARG_UNPARSED_ARGUMENTS}
49    )
50
51  add_custom_command(
52    TARGET ${test_name}
53    POST_BUILD
54    COMMAND "${CMAKE_COMMAND}" -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Inputs)
55
56  target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS})
57endfunction()
58
59function(add_unittest_inputs test_name inputs)
60  foreach (INPUT ${inputs})
61    add_custom_command(
62      TARGET ${test_name}
63      POST_BUILD
64      COMMAND "${CMAKE_COMMAND}" -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Inputs/${INPUT} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Inputs
65      COMMENT "Copying ${INPUT} to binary directory.")
66  endforeach()
67endfunction()
68
69add_subdirectory(TestingSupport)
70if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
71  # FIXME: APITests.exe is not a valid googletest binary.
72  add_subdirectory(API)
73endif()
74add_subdirectory(Breakpoint)
75add_subdirectory(Core)
76add_subdirectory(DataFormatter)
77add_subdirectory(Disassembler)
78add_subdirectory(Editline)
79add_subdirectory(Expression)
80add_subdirectory(Host)
81add_subdirectory(Interpreter)
82add_subdirectory(Instruction)
83add_subdirectory(Language)
84add_subdirectory(ObjectFile)
85add_subdirectory(Platform)
86add_subdirectory(Process)
87add_subdirectory(ScriptInterpreter)
88add_subdirectory(Signals)
89add_subdirectory(Symbol)
90add_subdirectory(SymbolFile)
91add_subdirectory(Target)
92add_subdirectory(tools)
93add_subdirectory(UnwindAssembly)
94add_subdirectory(Utility)
95add_subdirectory(Thread)
96
97if(LLDB_CAN_USE_DEBUGSERVER AND LLDB_TOOL_DEBUGSERVER_BUILD AND NOT LLDB_USE_SYSTEM_DEBUGSERVER)
98  add_subdirectory(debugserver)
99endif()
100