Building clang on Windows with CMake/Ninja

On the clang getting started page there is:

"It is also possible to use CMake instead of the makefiles. With CMake it is possible to generate project files for several IDEs: Xcode, Eclipse CDT4, CodeBlocks, Qt-Creator (use the CodeBlocks generator), KDevelop3."

How does one build clang on Windows using MingW with CMake/Ninja ?

Edward Diener <eldlistmailingz@tropicsoft.com>
writes:

On the clang getting started page there is:

"It is also possible to use CMake instead of the makefiles. With CMake
it is possible to generate project files for several IDEs: Xcode,
Eclipse CDT4, CodeBlocks, Qt-Creator (use the CodeBlocks generator),
KDevelop3."

How does one build clang on Windows using MingW with CMake/Ninja ?

Install recent versions of MinGW, CMake and Ninja. Make sure everything
is reachable through PATH environment variable.

Let's suppose that LLVM sources are installed in C:\LLVM and Clang in
C:\LLVM\tools\clang

Execute this commands on a Windows command prompt and you are done:

mkdir \buildLLVM

cd \buildLLVM

cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=c:/llvm_installed ../llvm

ninja

ninja install

Be sure that ../llvm is indeed the path to the LLVM sources from the
build directory.

You can change CMAKE_BUILD_TYPE to Debug, depending on your usage. Last
time I tried (long time ago) it was not strictly required to install
Clang to use it.

More information about CMake & LLVM usage on
http://www.llvm.org/docs/CMake.html

Thanks for the info. How does Ninja know to be using MingW as opposed to other development environments I have ?

Edward Diener <eldlistmailingz@tropicsoft.com>
writes:

Thanks for the info. How does Ninja know to be using MingW as opposed
to other development environments I have ?

CMake has a list of toolsets to search for. IIRC for the Ninja generator
MinGW takes precedence, just make sure that its `bin' directory is
listed in PATH, but if after doing that CMake picks VS first, delete and
recreate the build directory and set this environment variables before
invoking CMake:

set CC=gcc
set CXX=g++

Running the cmake command you specified worked but with this warning:

"-- Warning: LLVM will be built thread-unsafe because atomic builtins are missing"

Does this affect the build of clang in any way ?

Edward Diener <eldlistmailingz@tropicsoft.com>
writes:

Running the cmake command you specified worked but with this warning:

"-- Warning: LLVM will be built thread-unsafe because atomic builtins
are missing"

Does this affect the build of clang in any way ?

IIRC this means that it is unsafe to use LLVM on multiple threads (for
those specific LLVM features which support parallel execution.)

AFAIK it doesn't affect Clang, although there is more knowledgeable
people than me here that can correct or confirm that assertion.

I think that MinGW-w64 supports atomic builtins.