Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

Compiler option dependency for LLVM pass with CMake

I have a project that needs to be built with an LLVM pass. Here is the project structure:

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

instrumentation/CMakeLists.txt has a target to build the LLVM pass called MyPass.

I've added the following the CMakeLists.txt:

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

Now I just need to add MyPass as a dependency for all the targets in my project. I was wondering if there was a way to force MyPass to build first so that when compiling other files, the LLVM pass would be present. Maybe there a way to add a target compile_options dependencies?

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

My solution to this is to create another project to wrap the compiler executable and automatically build with the LLVM pass. Then rebuild the original project with the wrapped compiler.

AFL does this exact thing when building with a clang compiler.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...