-
Notifications
You must be signed in to change notification settings - Fork 0
Integration Guide
Hugo edited this page Feb 26, 2026
·
1 revision
CoreTrace Compiler can be embedded as a library from CMake.
include(FetchContent)
FetchContent_Declare(cc
GIT_REPOSITORY https://github.com/CoreTrace/coretrace-compiler.git
GIT_TAG main
)
FetchContent_MakeAvailable(cc)
target_link_libraries(my_app PRIVATE cc::compilerlib_static)
# or: cc::compilerlib_sharedcmake -S . -B build \
-DLLVM_DIR=$(brew --prefix llvm@20)/lib/cmake/llvm \
-DClang_DIR=$(brew --prefix llvm@20)/lib/cmake/clangcmake -S . -B build \
-DLLVM_DIR=/usr/lib/llvm-20/lib/cmake/llvm \
-DClang_DIR=/usr/lib/llvm-20/lib/cmake/clang \
-DCLANG_LINK_CLANG_DYLIB=ON \
-DLLVM_LINK_LLVM_DYLIB=ON#include "compilerlib/compiler.h"
#include <iostream>
#include <vector>
int main()
{
std::vector<std::string> args = {"hello.c", "-o", "hello"};
auto r = compilerlib::compile(args, compilerlib::OutputMode::ToFile, false);
if (!r.success)
{
std::cerr << r.diagnostics << '\n';
return 1;
}
return 0;
}std::vector<std::string> args = {
"hello.c",
"-o", "hello_inst",
"--ct-modules=trace,alloc,bounds",
"--ct-autofree"
};
auto r = compilerlib::compile(args, compilerlib::OutputMode::ToFile, true);std::vector<std::string> args = {"hello.c", "-emit-llvm"};
auto r = compilerlib::compile(args, compilerlib::OutputMode::ToMemory, false);
if (r.success)
{
std::cout << r.llvmIR;
}When testing an external consumer against your local checkout:
cmake -S extern-project -B extern-project/.build-python \
-DFETCHCONTENT_SOURCE_DIR_CC=/absolute/path/to/coretrace-compilerThis pattern is used by test/examples/test_extern_project.py.
| Target | Alias | Type |
|---|---|---|
compilerlib_static |
cc::compilerlib_static |
static |
compilerlib_shared |
cc::compilerlib_shared |
shared |
ct_instrument_runtime |
none | static runtime |
Start
Architecture
Instrumentation
Developer