xref: /openbsd-src/gnu/llvm/clang/lib/Tooling/CMakeLists.txt (revision 12c855180aad702bbcca06e0398d774beeafb155)
1set(LLVM_LINK_COMPONENTS
2  Option
3  FrontendOpenMP
4  Support
5  TargetParser
6  )
7
8add_subdirectory(Core)
9add_subdirectory(Inclusions)
10add_subdirectory(Refactoring)
11add_subdirectory(ASTDiff)
12add_subdirectory(DumpTool)
13add_subdirectory(Syntax)
14add_subdirectory(DependencyScanning)
15add_subdirectory(Transformer)
16
17# Replace the last lib component of the current binary directory with include
18string(FIND ${CMAKE_CURRENT_BINARY_DIR} "/lib/" PATH_LIB_START REVERSE)
19if(PATH_LIB_START EQUAL -1)
20  message(FATAL_ERROR "Couldn't find lib component in binary directory")
21endif()
22math(EXPR PATH_LIB_END "${PATH_LIB_START}+5")
23string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD)
24string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} ${PATH_LIB_END} -1 PATH_TAIL)
25string(CONCAT BINARY_INCLUDE_DIR ${PATH_HEAD} "/include/clang/" ${PATH_TAIL})
26
27if (NOT Python3_EXECUTABLE
28    OR APPLE
29    OR CMAKE_CROSSCOMPILING
30    OR GENERATOR_IS_MULTI_CONFIG
31    OR NOT LLVM_NATIVE_ARCH IN_LIST LLVM_TARGETS_TO_BUILD
32    )
33    configure_file(
34      EmptyNodeIntrospection.inc.in
35      ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
36      COPYONLY
37    )
38    set(CLANG_TOOLING_BUILD_AST_INTROSPECTION "OFF" CACHE BOOL "")
39else()
40  # The generation of ASTNodeAPI.json takes a long time in a
41  # Debug build due to parsing AST.h. Disable the processing
42  # but setting CLANG_TOOLING_BUILD_AST_INTROSPECTION as an
43  # internal hidden setting to override.
44  # When the processing is disabled, a trivial/empty JSON
45  # file is generated by clang-ast-dump and generate_cxx_src_locs.py
46  # generates the same API, but with a trivial implementation.
47  option(CLANG_TOOLING_BUILD_AST_INTROSPECTION "Enable AST introspection" TRUE)
48
49  set(skip_expensive_processing $<OR:$<CONFIG:Debug>,$<NOT:$<BOOL:${CLANG_TOOLING_BUILD_AST_INTROSPECTION}>>>)
50
51  set(implicitDirs)
52  foreach(implicitDir ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
53    list(APPEND implicitDirs -I ${implicitDir})
54  endforeach()
55
56  add_custom_command(
57      COMMENT Generate ASTNodeAPI.json
58      OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
59      DEPENDS clang-ast-dump clang-resource-headers
60      COMMAND
61      $<TARGET_FILE:clang-ast-dump>
62        # Skip this in debug mode because parsing AST.h is too slow
63        --skip-processing=${skip_expensive_processing}
64        -I ${LLVM_BINARY_DIR}/lib/clang/${CLANG_VERSION_MAJOR}/include
65        -I ${CLANG_SOURCE_DIR}/include
66        -I ${LLVM_BINARY_DIR}/tools/clang/include
67        -I ${LLVM_BINARY_DIR}/include
68        -I ${LLVM_SOURCE_DIR}/include
69        ${implicitDirs}
70        --json-output-path ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
71  )
72
73  add_custom_target(run-ast-api-dump-tool
74      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
75  )
76
77  add_custom_command(
78      COMMENT Generate NodeIntrospection.inc
79      OUTPUT ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
80      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
81        ${CMAKE_CURRENT_SOURCE_DIR}/DumpTool/generate_cxx_src_locs.py
82        ${CMAKE_CURRENT_SOURCE_DIR}/EmptyNodeIntrospection.inc.in
83      COMMAND
84      ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/DumpTool/generate_cxx_src_locs.py
85        --json-input-path ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
86        --output-file NodeIntrospection.inc
87        --use-empty-implementation ${skip_expensive_processing}
88        --empty-implementation
89          "${CMAKE_CURRENT_SOURCE_DIR}/EmptyNodeIntrospection.inc.in"
90      COMMAND
91      ${CMAKE_COMMAND} -E copy_if_different
92        ${CMAKE_CURRENT_BINARY_DIR}/NodeIntrospection.inc
93        ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
94  )
95
96  add_custom_target(run-ast-api-generate-tool
97      DEPENDS
98      ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
99  )
100endif()
101
102add_clang_library(clangTooling
103  AllTUsExecution.cpp
104  ArgumentsAdjusters.cpp
105  CommonOptionsParser.cpp
106  CompilationDatabase.cpp
107  Execution.cpp
108  ExpandResponseFilesCompilationDatabase.cpp
109  FileMatchTrie.cpp
110  FixIt.cpp
111  GuessTargetAndModeCompilationDatabase.cpp
112  InterpolatingCompilationDatabase.cpp
113  JSONCompilationDatabase.cpp
114  Refactoring.cpp
115  RefactoringCallbacks.cpp
116  StandaloneExecution.cpp
117  NodeIntrospection.cpp
118  ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
119  Tooling.cpp
120
121  DEPENDS
122  ClangDriverOptions
123  omp_gen
124
125  LINK_LIBS
126  clangAST
127  clangASTMatchers
128  clangBasic
129  clangDriver
130  clangFormat
131  clangFrontend
132  clangLex
133  clangRewrite
134  clangSerialization
135  clangToolingCore
136  )
137