1# This is a no-op for building files in this dir, but is inherited by subdirs. 2include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 3include_directories(${CMAKE_CURRENT_BINARY_DIR}) 4 5add_subdirectory(support) 6 7# Configure the Features.inc file. 8if (NOT DEFINED CLANGD_BUILD_XPC) 9 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 10 set(CLANGD_BUILD_XPC_DEFAULT ON) 11 else () 12 set(CLANGD_BUILD_XPC_DEFAULT OFF) 13 endif () 14 15 llvm_canonicalize_cmake_booleans(CLANGD_BUILD_XPC_DEFAULT) 16 17 set(CLANGD_BUILD_XPC ${CLANGD_BUILD_XPC_DEFAULT} CACHE BOOL "Build XPC Support For Clangd." FORCE) 18 unset(CLANGD_BUILD_XPC_DEFAULT) 19endif () 20 21# This involves generating and compiling large source files, which can run into toolchain limitations. 22option(CLANGD_DECISION_FOREST "Enable decision forest model for ranking code completion items" ON) 23option(CLANGD_MALLOC_TRIM "Call malloc_trim(3) periodically in Clangd. (only takes effect when using glibc)" ON) 24# -DCLANG_TIDY_CHECKS=Off avoids a dependency on clang-tidy, reducing rebuilds. 25option(CLANGD_TIDY_CHECKS "Link all clang-tidy checks into clangd" ON) 26 27llvm_canonicalize_cmake_booleans( 28 CLANGD_BUILD_XPC 29 CLANGD_ENABLE_REMOTE 30 ENABLE_GRPC_REFLECTION 31 CLANGD_MALLOC_TRIM 32 CLANGD_TIDY_CHECKS 33 LLVM_ENABLE_ZLIB 34 CLANGD_DECISION_FOREST 35) 36 37configure_file( 38 ${CMAKE_CURRENT_SOURCE_DIR}/Features.inc.in 39 ${CMAKE_CURRENT_BINARY_DIR}/Features.inc 40) 41 42set(LLVM_LINK_COMPONENTS 43 Support 44 AllTargetsInfos 45 FrontendOpenMP 46 Option 47 TargetParser 48 ) 49 50set(COMPLETIONMODEL_SOURCES) 51if(CLANGD_DECISION_FOREST) 52 include(${CMAKE_CURRENT_SOURCE_DIR}/quality/CompletionModel.cmake) 53 gen_decision_forest(${CMAKE_CURRENT_SOURCE_DIR}/quality/model CompletionModel clang::clangd::Example) 54 list(APPEND COMPLETIONMODEL_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/CompletionModel.cpp) 55endif() 56 57if(MSVC AND NOT CLANG_CL) 58 set_source_files_properties(CompileCommands.cpp PROPERTIES COMPILE_FLAGS -wd4130) # disables C4130: logical operation on address of string constant 59endif() 60 61include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}/../clang-tidy") 62include_directories(BEFORE "${CMAKE_CURRENT_SOURCE_DIR}/../include-cleaner/include") 63 64add_clang_library(clangDaemon STATIC 65 AST.cpp 66 ASTSignals.cpp 67 ClangdLSPServer.cpp 68 ClangdServer.cpp 69 CodeComplete.cpp 70 CodeCompletionStrings.cpp 71 CollectMacros.cpp 72 CompileCommands.cpp 73 Compiler.cpp 74 Config.cpp 75 ConfigCompile.cpp 76 ConfigProvider.cpp 77 ConfigYAML.cpp 78 DecisionForest.cpp 79 Diagnostics.cpp 80 DraftStore.cpp 81 DumpAST.cpp 82 ExpectedTypes.cpp 83 FeatureModule.cpp 84 Feature.cpp 85 FindSymbols.cpp 86 FindTarget.cpp 87 FileDistance.cpp 88 Format.cpp 89 FS.cpp 90 FuzzyMatch.cpp 91 GlobalCompilationDatabase.cpp 92 Headers.cpp 93 HeaderSourceSwitch.cpp 94 Hover.cpp 95 IncludeCleaner.cpp 96 IncludeFixer.cpp 97 InlayHints.cpp 98 JSONTransport.cpp 99 ModulesBuilder.cpp 100 PathMapping.cpp 101 Protocol.cpp 102 Quality.cpp 103 ParsedAST.cpp 104 Preamble.cpp 105 RIFF.cpp 106 ScanningProjectModules.cpp 107 Selection.cpp 108 SemanticHighlighting.cpp 109 SemanticSelection.cpp 110 SourceCode.cpp 111 SystemIncludeExtractor.cpp 112 TidyProvider.cpp 113 TUScheduler.cpp 114 URI.cpp 115 XRefs.cpp 116 ${COMPLETIONMODEL_SOURCES} 117 118 index/Background.cpp 119 index/BackgroundIndexLoader.cpp 120 index/BackgroundIndexStorage.cpp 121 index/BackgroundQueue.cpp 122 index/BackgroundRebuild.cpp 123 index/CanonicalIncludes.cpp 124 index/FileIndex.cpp 125 index/Index.cpp 126 index/IndexAction.cpp 127 index/MemIndex.cpp 128 index/Merge.cpp 129 index/ProjectAware.cpp 130 index/Ref.cpp 131 index/Relation.cpp 132 index/Serialization.cpp 133 index/StdLib.cpp 134 index/Symbol.cpp 135 index/SymbolCollector.cpp 136 index/SymbolID.cpp 137 index/SymbolLocation.cpp 138 index/SymbolOrigin.cpp 139 index/YAMLSerialization.cpp 140 141 index/dex/Dex.cpp 142 index/dex/Iterator.cpp 143 index/dex/PostingList.cpp 144 index/dex/Trigram.cpp 145 146 refactor/InsertionPoint.cpp 147 refactor/Rename.cpp 148 refactor/Tweak.cpp 149 150 DEPENDS 151 omp_gen 152 ClangDriverOptions 153 ) 154 155# Include generated CompletionModel headers. 156target_include_directories(clangDaemon PUBLIC 157 $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> 158) 159 160clang_target_link_libraries(clangDaemon 161 PRIVATE 162 clangAST 163 clangASTMatchers 164 clangBasic 165 clangDependencyScanning 166 clangDriver 167 clangFormat 168 clangFrontend 169 clangIndex 170 clangLex 171 clangSema 172 clangSerialization 173 clangTooling 174 clangToolingCore 175 clangToolingInclusions 176 clangToolingInclusionsStdlib 177 clangToolingSyntax 178 ) 179 180target_link_libraries(clangDaemon 181 PRIVATE 182 ${LLVM_PTHREAD_LIB} 183 184 clangIncludeCleaner 185 clangTidy 186 clangTidyUtils 187 188 clangdSupport 189 ) 190if(CLANGD_TIDY_CHECKS) 191 target_link_libraries(clangDaemon PRIVATE ${ALL_CLANG_TIDY_CHECKS}) 192endif() 193 194add_subdirectory(refactor/tweaks) 195if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 196 # FIXME: Make fuzzer not use linux-specific APIs, build it everywhere. 197 add_subdirectory(fuzzer) 198endif() 199add_subdirectory(tool) 200add_subdirectory(indexer) 201 202if (LLVM_INCLUDE_BENCHMARKS) 203 add_subdirectory(benchmarks) 204endif() 205if ( CLANGD_BUILD_XPC ) 206 add_subdirectory(xpc) 207endif () 208 209if (CLANGD_ENABLE_REMOTE) 210 include(AddGRPC) 211endif() 212 213if(CLANG_INCLUDE_TESTS) 214 add_subdirectory(test) 215 add_subdirectory(unittests) 216endif() 217 218# FIXME(kirillbobyrev): Document this in the LLVM docs once remote index is stable. 219option(CLANGD_ENABLE_REMOTE "Use gRPC library to enable remote index support for Clangd" OFF) 220set(GRPC_INSTALL_PATH "" CACHE PATH "Path to gRPC library manual installation.") 221 222add_subdirectory(index/remote) 223add_subdirectory(index/dex/dexp) 224