Hi CMakers,<div><br></div><div>I am trying to use CMake with llvm-gcc compiler (<a href="http://llvm.org/cmds/llvmgcc.html" target="_blank">http://llvm.org/cmds/llvmgcc.html</a>) and want to split the compilation into three steps:</div>

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


<div><br></div><div>The reason for this is that I need both the object files and the bitcode files be generated.</div><div>However I can&#39;t figure out how to accomplish this.</div><div><br></div><div>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:</div>


<div><br></div><div><div>string(REPLACE &quot;&lt;OBJECT&gt;&quot; &quot;&lt;OBJECT&gt;.bc&quot;</div><div>    generate_bc ${CMAKE_CXX_COMPILE_OBJECT})</div></div><div><br></div><div><div>set(CMAKE_CXX_COMPILE_OBJECT</div>


<div>    &quot;${CMAKE_CXX_COMPILE_OBJECT} &amp;&amp; ${generate_bc} -emit-llvm&quot;)</div></div><div><br></div><div>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).</div>


<div>Is there a better solution to this problem?</div><div><br></div><div>Best regards,</div><div>Victor</div>