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