forked from OSchip/llvm-project
153 lines
4.7 KiB
CMake
153 lines
4.7 KiB
CMake
set(LLVM_LINK_COMPONENTS
|
|
Option
|
|
FrontendOpenMP
|
|
Support
|
|
)
|
|
|
|
add_subdirectory(Core)
|
|
add_subdirectory(Inclusions)
|
|
add_subdirectory(Refactoring)
|
|
add_subdirectory(ASTDiff)
|
|
add_subdirectory(DumpTool)
|
|
add_subdirectory(Syntax)
|
|
add_subdirectory(DependencyScanning)
|
|
add_subdirectory(Transformer)
|
|
|
|
find_package(Python3 COMPONENTS Interpreter)
|
|
|
|
# Replace the last lib component of the current binary directory with include
|
|
string(FIND ${CMAKE_CURRENT_BINARY_DIR} "/lib/" PATH_LIB_START REVERSE)
|
|
if(PATH_LIB_START EQUAL -1)
|
|
message(FATAL_ERROR "Couldn't find lib component in binary directory")
|
|
endif()
|
|
math(EXPR PATH_LIB_END "${PATH_LIB_START}+5")
|
|
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD)
|
|
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} ${PATH_LIB_END} -1 PATH_TAIL)
|
|
string(CONCAT BINARY_INCLUDE_DIR ${PATH_HEAD} "/include/clang/" ${PATH_TAIL})
|
|
|
|
if (NOT Python3_EXECUTABLE
|
|
OR WIN32
|
|
OR APPLE
|
|
OR GENERATOR_IS_MULTI_CONFIG
|
|
OR NOT LLVM_NATIVE_ARCH IN_LIST LLVM_TARGETS_TO_BUILD
|
|
OR NOT X86 IN_LIST LLVM_TARGETS_TO_BUILD
|
|
)
|
|
file(GENERATE OUTPUT ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
|
|
CONTENT "
|
|
namespace clang {
|
|
namespace tooling {
|
|
|
|
NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) {
|
|
return {};
|
|
}
|
|
NodeLocationAccessors
|
|
NodeIntrospection::GetLocations(clang::DynTypedNode const &) {
|
|
return {};
|
|
}
|
|
} // namespace tooling
|
|
} // namespace clang
|
|
"
|
|
)
|
|
set(CLANG_TOOLING_BUILD_AST_INTROSPECTION "OFF" CACHE BOOL "")
|
|
else()
|
|
# The generation of ASTNodeAPI.json takes a long time in a
|
|
# Debug build due to parsing AST.h. Disable the processing
|
|
# but setting CLANG_TOOLING_BUILD_AST_INTROSPECTION as an
|
|
# internal hidden setting to override.
|
|
# When the processing is disabled, a trivial/empty JSON
|
|
# file is generated by clang-ast-dump and generate_cxx_src_locs.py
|
|
# generates the same API, but with a trivial implementation.
|
|
option(CLANG_TOOLING_BUILD_AST_INTROSPECTION "Enable AST introspection" TRUE)
|
|
|
|
set(skip_expensive_processing $<OR:$<CONFIG:Debug>,$<NOT:$<BOOL:${CLANG_TOOLING_BUILD_AST_INTROSPECTION}>>>)
|
|
|
|
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTTU.cpp
|
|
CONTENT "
|
|
#include <clang/AST/AST.h>
|
|
")
|
|
|
|
set(implicitDirs)
|
|
foreach(implicitDir ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
|
|
list(APPEND implicitDirs -I ${implicitDir})
|
|
endforeach()
|
|
|
|
add_custom_command(
|
|
COMMENT Generate ASTNodeAPI.json
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
|
|
DEPENDS clang-ast-dump clang-resource-headers ${CMAKE_CURRENT_BINARY_DIR}/ASTTU.cpp
|
|
COMMAND
|
|
$<TARGET_FILE:clang-ast-dump>
|
|
# Skip this in debug mode because parsing AST.h is too slow
|
|
--skip-processing=${skip_expensive_processing}
|
|
--astheader=${CMAKE_CURRENT_BINARY_DIR}/ASTTU.cpp
|
|
-I ${CMAKE_BINARY_DIR}/lib/clang/${CLANG_VERSION}/include
|
|
-I ${CMAKE_SOURCE_DIR}/../clang/include
|
|
-I ${CMAKE_BINARY_DIR}/tools/clang/include
|
|
-I ${CMAKE_BINARY_DIR}/include
|
|
-I ${CMAKE_SOURCE_DIR}/include
|
|
${implicitDirs}
|
|
--json-output-path ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
|
|
)
|
|
|
|
add_custom_target(run-ast-api-dump-tool
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
|
|
)
|
|
|
|
add_custom_command(
|
|
COMMENT Generate NodeIntrospection.inc
|
|
OUTPUT ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
|
|
${CMAKE_CURRENT_SOURCE_DIR}/DumpTool/generate_cxx_src_locs.py
|
|
COMMAND
|
|
${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/DumpTool/generate_cxx_src_locs.py
|
|
--json-input-path ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
|
|
--output-file NodeIntrospection.inc
|
|
--empty-implementation ${skip_expensive_processing}
|
|
COMMAND
|
|
${CMAKE_COMMAND} -E copy_if_different
|
|
${CMAKE_CURRENT_BINARY_DIR}/NodeIntrospection.inc
|
|
${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
|
|
)
|
|
|
|
add_custom_target(run-ast-api-generate-tool
|
|
DEPENDS
|
|
${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
|
|
)
|
|
endif()
|
|
|
|
add_clang_library(clangTooling
|
|
AllTUsExecution.cpp
|
|
ArgumentsAdjusters.cpp
|
|
CommonOptionsParser.cpp
|
|
CompilationDatabase.cpp
|
|
Execution.cpp
|
|
ExpandResponseFilesCompilationDatabase.cpp
|
|
FileMatchTrie.cpp
|
|
FixIt.cpp
|
|
GuessTargetAndModeCompilationDatabase.cpp
|
|
InterpolatingCompilationDatabase.cpp
|
|
JSONCompilationDatabase.cpp
|
|
Refactoring.cpp
|
|
RefactoringCallbacks.cpp
|
|
StandaloneExecution.cpp
|
|
NodeIntrospection.cpp
|
|
${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
|
|
Tooling.cpp
|
|
|
|
DEPENDS
|
|
ClangDriverOptions
|
|
omp_gen
|
|
|
|
LINK_LIBS
|
|
clangAST
|
|
clangASTMatchers
|
|
clangBasic
|
|
clangDriver
|
|
clangFormat
|
|
clangFrontend
|
|
clangLex
|
|
clangRewrite
|
|
clangSerialization
|
|
clangToolingCore
|
|
)
|