LLVM/CMake: in-source-tree and out-of-source tree CMake configs for the same project.


Does anyone have a positive experience of maintaining CMake configs for both in-source and out-of-source kinds of hosting in the same project?

P.S. http://stanislaw.github.io/2017/02/18/llvm-in-source-vs-out-of-source.html.



The problem with this article is that it makes it seem like you really should choose one or the other, and that is just not so.

At this point I believe all of the LLVM sub-projects support both in-tree and out-of-tree builds with LLVM. Using the LLVM CMake packages that are installed as part of most LLVM distributions you can write your CMake scripts as if they are for in-source builds, and supporting out-of-source is a minimal effort.

To see how that works in practice please take a look at Clang’s root CMakeLists.txt. Near the top there is a comment about standalone build support, and the required code is underneath. You’ll find similarly CMake code in all the LLVM sub-projects which we use to support building each project separately.