Skip to content

Instantly share code, notes, and snippets.

@willkill07
Last active June 30, 2017 18:06
Show Gist options
  • Save willkill07/6c9ee4db5ff4a702bb4c3ba0af9b908e to your computer and use it in GitHub Desktop.
Save willkill07/6c9ee4db5ff4a702bb4c3ba0af9b908e to your computer and use it in GitHub Desktop.
Clang Plugin CMakeLists.txt
find_package(Clang REQUIRED)
set(CLANG_LIBRARIES clangAST clangASTMatchers clangAnalysis clangBasic clangDriver clangEdit clangFrontend clangFrontendTool clangLex clangParse clangSema clangEdit clangRewrite clangRewriteFrontend clangStaticAnalyzerFrontend clangStaticAnalyzerCheckers clangStaticAnalyzerCore clangSerialization clangToolingCore clangTooling clangFormat)
macro(add_clang_plugin _name)
add_library(${_name} SHARED "")
set_target_properties(${_name}
PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED On
CXX_EXTENSIONS Off)
target_include_directories(${_name}
PRIVATE
${LLVM_INCLUDE_DIR})
target_link_libraries(${_name}
libclang)
endmacro(add_clang_plugin)
macro(add_clang_executable _name)
add_executable(${_name} "")
set_target_properties(${_name}
PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED On
CXX_EXTENSIONS Off)
target_include_directories(${_name}
PRIVATE
${LLVM_INCLUDE_DIR})
target_link_libraries(${_name}
${CLANG_LIBRARIES} ${LLVM_AVAILABLE_LIBS})
endmacro(add_clang_executable)
cmake_minimum_required(VERSION 3.6)
project(ClangPluginExamples CXX)
include(cmake/AddClangPlugin.cmake)
add_subdirectory(src_clang)
add_clang_plugin(plugin_print_funcnames)
target_sources(plugin_print_funcnames
PUBLIC
plugin_print_funcnames.cpp)
add_clang_executable(tooling_sample)
target_sources(tooling_sample
PUBLIC
tooling_sample.cpp)
target_link_libraries(tooling_sample
clangTooling)
add_clang_executable(rewritersample)
target_sources(rewritersample
PUBLIC
rewritersample.cpp)
add_clang_executable(clang_check)
target_sources(clang_check
PUBLIC
ClangCheck.cpp)
target_link_libraries(clang_check
clangTooling)
add_clang_executable(matchers_rewriter)
target_sources(matchers_rewriter
PUBLIC
matchers_rewriter.cpp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment