[CMake] Using Clang + Ninja on Windows?

Mueller-Roemer, Johannes Sebastian Johannes.Sebastian.Mueller-Roemer at igd.fraunhofer.de
Fri Apr 22 02:59:15 EDT 2016


You are mistaken, Clang absolutely also works with MinGW. Or it did at least up to 3.7 (didn’t get around to trying 3.8 yet)

From: CMake [mailto:cmake-bounces at cmake.org] On Behalf Of Cristian Adam
Sent: Thursday, April 21, 2016 23:30
To: Johan Holmberg <johan556 at gmail.com>
Cc: cmake at cmake.org
Subject: Re: [CMake] Using Clang + Ninja on Windows?


On Wed, Apr 20, 2016 at 4:01 PM, Johan Holmberg <johan556 at gmail.com<mailto:johan556 at gmail.com>> wrote:
Hi!
How should I setup CMake to build a C/C++ application on Windows using clang/clang++ as compilers and Ninja as build tool?
I tried specifying "-GNinja" to cmake, and setting CC/CXX to clang/clang++. But this didn't work. I get errors like:

  clang.exe: error: no such file or directory: '/nologo'
indicating that CMake thinks it should pass Visual C++ style options to clang.
I'm thinking about fooling CMake that clang/clang++ are cross compilers (I know how to get cross compiling working in other cases). But since clang/clang++ are the native tools for Windows, I was hoping to be able to use Clang + Ninja on Windows almost like I use on Linux.
If I run Clang from the command line, I can build my application, so my Clang-installation works.

I'm using CMake 3.5.1 and Clang 3.8.0.
/Johan Holmberg

Hi,

On Windows Clang works only with Visual C++, since they don't provide libc++. MinGW is not supported.
Clang provides a Visual C++'s cl.exe replacement.

You need to have the official windows<http://llvm.org/releases/download.html#3.8.0> Clang and Visual C++ Express or Community installed.

Then it's just a matter of:
1.       Opening a Visual C++ 2013 64 bit command prompt window
2.       Putting clang's cl.exe in the path and setting clang's INCLUDE path first

set PATH=c:\Program Files\LLVM\msbuild-bin\;%PATH%
set INCLUDE=c:\Program Files\LLVM\lib\clang\3.8.0\include\;%INCLUDE%
3.       cmake -G "Ninja"
4.       Ninja
CMake / Ninja will think that they compile with Visual C++, but instead will use clang.

Note that you have to match Visual C++ and Clang's build, 32 or 64 bit. You can't mix them,
or you'll have weird errors<https://cmake.org/pipermail/cmake/2016-March/062978.html>.

Cheers,
Cristian.

P.S. This is actually a re-post, this time adding the mailing list.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160422/32eeaeef/attachment-0001.html>


More information about the CMake mailing list