[CMake] splitting compilation into steps

Victor Zverovich victor.zverovich at googlemail.com
Sun Mar 28 08:26:00 EDT 2010


Hi CMakers,

I am trying to use CMake with llvm-gcc compiler (
http://llvm.org/cmds/llvmgcc.html) and want to split the compilation into
three steps:

1. Compile the C/C++ source code into LLVM bitcode using llvm-gcc with the
command llvm-gcc <c-flags> -emit-llvm -o <bitcode> -c <source>
2. Compile bitcode into assembly language using llc with the command llc -o
<assembly> <bitcode>
3. Translate assembly language into object code using GNU assembler with the
command as -o <object> <assembly>

The reason for this is that I need both the object files and the bitcode
files be generated.
However I can't figure out how to accomplish this.

So far the only way to invoke llvm-gcc with the correct flags I have found
is to redefine CMAKE_CXX_COMPILE_OBJECT as follows:

string(REPLACE "<OBJECT>" "<OBJECT>.bc"
    generate_bc ${CMAKE_CXX_COMPILE_OBJECT})

set(CMAKE_CXX_COMPILE_OBJECT
    "${CMAKE_CXX_COMPILE_OBJECT} && ${generate_bc} -emit-llvm")

However it invokes the compiler two times: one to generate the object file
(steps 1 - 3 combined) and one to generate the bitcode (step 1).
Is there a better solution to this problem?

Best regards,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100328/3d49a5fe/attachment.htm>


More information about the CMake mailing list