Chained compilation

I’m looking for a way to create a new language, let’s call it LLVM :), and the compilation from C++ to object file would go through:
C++ -> LLVM -> C -> object file
where LLVM -> C compilation is defined via

So given that C++ outputs LLVM, I’d like CMake to “understand” to apply the compilation chain above, implicitly. Ideas on how to accomplish this, if possible at all?

I think you’d have to basically skip the C++ -> object file logic that CMake knows about and add your own CXXLLVM language for that step. The outputs might need some coaxing to be understood as source files as well, but I think ISPC likely has codepaths for that these days. Not sure how easy it would be to repurpose them.

Cc: @brad.king @robert.maynard

I was more thinking of specifying a toolchain file, which basically overrides CMAKE_CXX_OUTPUT_EXTENSION with the input extension of the LLVM language (".llvm"). So all C++ files would go through the compilation chain. The CXX flags would have “-S -emit-llvm” so that the C++ object file, with ending .llvm, would contain LLVM IR code.
This is how I envisioned CMake being able to deduce the compilation order :slight_smile:

ISPC code model is C++ -> N object files + headers. As long as CMake compiles all ISPC files before any other language ( per target ) we are good since that makes sure headers exist before consumers.

If I am understanding this correctly you want to pass the output of the C++ compiler to the C compiler. This will be tricky for CMake as in general languages are considered to be fully independent, so a project might only enable C++ and therefore you won’t have C .

This type of transformation is done by other current languages via the compiler driver it self. Since the end result of C++ -> object hasn’t changed, this allows for drop-in replacement as the C++ compiler for numerous build-systems.