title: LTO with LLVM and CMake
body: <p>I am trying to apply Link Time Optimization with LLVM on a CMake Project, that creates a shared library. My question is pretty much the same as this one:</p>
  
  <p><a href="https://stackoverflow.com/questions/7031126/switching-between-gcc-and-clang-llvm-using-cmake">Switching between GCC and Clang/LLVM using CMake</a>. </p>
  
  <p>However, the answers do not seem to be applicable anymore, since <code>llvm-ld</code> is not present in the new versions. On the command line, I run the following commands to get LTO (Assuming there are only 2 <code>.cpp</code> files):</p>
  
  <p>Compile to byte code:</p>
  
  <pre><code>clang++ -c FirstClass.cpp -O3 -flto -o FirstClass.bc
  clang++ -c SecondClass.cpp -O3 -flto -o SecondClass.bc
  </code></pre>
  
  <p>Link byte code:</p>
  
  <pre><code>llvm-link FirstClass.bc SecondClass.bc -o unoptimized.bc
  </code></pre>
  
  <p>Optimize byte code:</p>
  
  <pre><code>opt -O3 unoptimized.bc -o optimized.bc
  </code></pre>
  
  <p>Convert byte code to shared object:</p>
  
  <pre><code>clang++ -shared optimized.bc -o libTest.so
  </code></pre>
  
  <p>Could somebody please tell me how to have CMake run the additional steps?    </p>