Skip to content

Latest commit

 

History

History
61 lines (48 loc) · 2.85 KB

cmake.md

File metadata and controls

61 lines (48 loc) · 2.85 KB

CMake

Here we describe our journey towards building with CMake in Docker.

How to compile Clang and then use it as a compiler

This is inherently problematic in CMake because it expects only one C++ compiler in the whole project. See [CMake] One build, multiple compilers and packages. There is one Stack Overflow question (Compile a compiler as an external project and use it?) of a person with similar problem. The answer there actually lists possible solutions pretty well. We decided to manually invoke CMake for Clang and then for our project itself at configure time. This is also known as a superbuild configuration. Then, we add clang.exe as a custom target that runs Ninja for Clang before building our project.

Other related sites:

How to compile with clang, not clang-cl

This is a known issue: Add support for Clang targeting MSVC ABI but with GNU-like command line. See also Building with CMake, Ninja and Clang on Windows. Or maybe cmake-toolchains(7) could be useful. Anyway, in general, here are the ways to specify custom compiler in CMake: How do I use a different compiler?. Also see this SO answer which references that article.

How to use lld-link instead of clang to link .obj files

Tips and tricks

Dependencies

DEPENDS of add_custom_target just builds files listed if there is any add_custom_command that can build them. To add target dependencies, you have to use add_dependencies.

DEPENDS of add_custom_command, on the other hand, is far more advanced. It can specify outputs of other custom commands, other targets and also arbitrary files. If you specify an arbitrary file (i.e., file that is not an output of a custom command), the custom command is re-run every time the file is changed.