使用 CMake 的 LLVM 传递的编译器选项依赖性

Compiler option dependency for LLVM pass with CMake

我有一个项目需要使用 LLVM pass 构建。这是项目结构:

proj/
   instrumentation/
       CMakeLists.txt
       Instrumentation.cpp
   [My project files]
   CMakeLists.txt

instrumentation/CMakeLists.txt 有一个构建名为 MyPass.

的 LLVM pass 的目标

我在 CMakeLists.txt 添加了以下内容:

add_subdirectory(instrumentation)
add_compile_options(
            "SHELL:-Xclang -load"
            "SHELL:-Xclang $<TARGET_FILE:MyPass>")

现在我只需要添加 MyPass 作为项目中所有目标的依赖项。我想知道是否有一种方法可以强制 MyPass 首先构建,以便在编译其他文件时,LLVM pass 会出现。也许有办法添加目标 compile_options 依赖项?

Note: I'd rather not add the dependency manually to every target because there many targets in the project.

我的解决方案是创建另一个项目来包装编译器可执行文件并使用 LLVM pass 自动构建。然后用包装好的编译器重建原来的项目。

AFL 在使用 clang 编译器构建时执行此操作。