Chao Peng
Chao Peng

Reputation: 13

How to apply llvm passes using CMake

We have implemented a LLVM pass and compiled it to a library (called libMyPass.so).

We want to apply this pass to a project (all its source code files) which uses cmake to build it. Is there a way to do so in cmake?

Generally, we used clang to emit llvm bit code from a source file, opt to apply this pass to the bit code, llc to translate the new bit code to assembly language and clang again to compile assembly language to executable. Can I encapsulate this process using cmake?

Upvotes: 1

Views: 1022

Answers (1)

compor
compor

Reputation: 2329

You can have a look or even use this repo that implements the various steps as cmake commands.

The gist of it is that creates various commands (using the cmake's add_custom_command) basically do exactly what you're looking for using the various LLVM subtools in conjunction with the various cmake target properties, in order to create the IR generation commands from source and to native binary code (i.e. .o).

For example, using llvmir_attach_bc_target() attaches to a top-level cmake target and creates a (unoptimized) .bc file for each source file in the SOURCES property of it.

It contains various examples in the same repo that should be enough to get you started.

Upvotes: 1

Related Questions