构建
创建clang插件目录
mkdir llvm-project/clang/tools/clang插件目录
创建YourPlugin.cpp
创建CMakeLists.txt,编写内容
// 将 Clang 插件代码集成到 LLVM 的 Xcode 工程中,并作为一个模块进行编写调试。
add_llvm_library(YourPlugin MODULE YourPlugin.cpp PLUGIN_TOOL clang)
// add_clang_library(YourPlugin MODULE YourPlugin.cpp)
// add_clang_executable(find-class-decls FindClassDecls.cpp)
// target_link_libraries(find-class-decls clangTooling)
添加插件到xcode工程
llvm-project/clang/tools/CMakeLists.txt 非插件目录里的CMakeLists.txt
add_clang_subdirectory(YourPlugin)
重新生成xcode工程
cd build_xcode
cmake -DLLVM_ENABLE_PROJECTS=clang -G Xcode ../llvm
编译插件
插件、clang 均需要编译
使用clang插件
llvm-project/build/Debug/bin/clang \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk **/ \
-Xclang -load \
-Xclang llvm-project/build/Debug/lib/YourPlugin.dylib \
-Xclang -add-plugin \
-Xclang YourPlugin \
-c test.c