-
Notifications
You must be signed in to change notification settings - Fork 216
Setting up Clang on Windows
There is quite a number of possibilities on how to use Clang on Windows. This page gives a brief overview on which options will lead to a working setup for Hana.
- Visual Studio 2015 with Clang/C2 [currently fails]
- Visual Studio 2015 with Clang/LLVM (Clang-Cl) [works]
- MinGW64 with native Clang/LLVM [works]
- Cygwin64 with native Clang [currently fails]
Below you find some detailed descriptions for these configurations.
Since Visual Studio 2015 Update 1, Microsoft added Clang as an official alternative frontend to its C2 backend code generator. However, this doesn't play well with CMake, yet, mainly since CMake doesn't recognize the alternative platform toolset v140_clang_3_7
correctly, and fails at defining some flags (exceptions and debugging format) and directories correctly. This was last tested with CMake 3.5RC2 and MSVC 2015 Update 2 CTP.
For now, you might want to resort to the next option:
The following are instructions to build Hana and run the tests with Visual Studio 2015 using the Clang-cl compiler. This apparently requires a functional Visual Studio 2015 installation.
Stable releases of pre-built Clang-cl binaries are available from http://llvm.org/releases/download.html; snapshot releases from http://llvm.org/builds/. These binaries provide a special version of Clang which emulates the MSVC compiler, both in its arguments upon invocation, but also in its sometimes special C++ parsing and code generation behaviour. This binary is found after a standard installation in C:\Program Files\LLVM\msbuild-bin\cl.exe
. Clang-cl also comes with a Visual Studio integration; just choose the platform toolset LLVM-vs2014
in your VS project properties. In case that isn't available after installing
Clang-cl, point your explorer to C:\Program Files\LLVM\tools\msbuild
and run install.bat
(possibly requires admin rights).
After downloading and unpacking Hana in a directory, here named hana
, continue on the Windows command line (cmd.exe
).
cd hana
mkdir build_Win32
cd build_Win32
cmake .. -TLLVM-vs2014 -G"Visual Studio 14 2015"
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" Boost.Hana.sln /p:Configuration=Debug /p:Platform=Win32 /v:m /m
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" RUN_TESTS.vcxproj /p:Configuration=Debug /p:Platform=Win32
The verbosity of the build is reduced by the argument /v:m
; the use all available cpus during the build is enabled with /m
. Both may be omitted or modified.
In the same manner as the 32bit build, the following results in a 64bit solution:
cd hana
mkdir build_Win64
cd build_Win64
cmake .. -TLLVM-vs2014 -G"Visual Studio 14 2015 Win64"
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" Boost.Hana.sln /p:Configuration=Release /p:Platform=x64 /v:m /m
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" RUN_TESTS.vcxproj /p:Configuration=Release /p:Platform=x64
Note the difference for the invocation of cmake and MSBuild in the platform tag, and, yes, LLVM-vs2014
is correct although being for VS 2015. If you intend to link against other Boost libraries to which Hana provides interfaces, such as MPL and Fusion, add -DBOOST_ROOT=/path/to/boost
as argument to the cmake invocation.
For a Hana build and test run, I highly recommend the use of the command line. Due to the close to 1000 test cases (and probably growing), MSVC (the IDE) is rather slow with all those background indexing processes. Unlike mentioned in quite a few other how-tos, it is not necessary to run the above commands from a command line invoked from within Visual Studio. The regular cmd.exe
is absolutely sufficient. All the necessary include and library paths are correctly defined either by cmake or the platform toolset.
There also seems to be a chance in generating a build for ARM (replace Win64 with ARM in the above example), since being available as cmake generator. But this has not been tested, yet.
The above commands may also be executed in an MSYS2/MinGW64 console, and will as well produce the MSVC compatible binaries. However, the slashes for the arguments of MSBuild
might require to be given twice to be recognized as parameters rather than names of solution files, e.g. //p:Platform=x64
.
Note that invoking cmake
in MSYS2/MinGW64 typically defaults to the 32bit Visual Studio generator, but does not automatically choose the Clang-cl/LLVM platform toolset.
To use a native MinGW64 toolchain, simply proceed with the instructions given for Linux, but specify the MSYS Makefiles
generator. Since cmake
defaults to GCC, you would also have to specify the compiler of your choice. Hence, start with
cd hana
mkdir build_MinGW64
cd build_MinGW64
cmake .. -DCMAKE_CXX_COMPILER=clang++ -G"MSYS Makefiles"
make check
Unfortunately, Cygwin is not yet providing a standard C++ library that allows a successful build of all Hana tests. This is due to Clang linking against the GCC C++ library, libstdc++
, which is currently at a version 4.9.3, whereas Hana requires at least a libstdc++
version of 5.1. Also, Clang's own libc++
is not yet provided either.
Be patient, or choose one of the other options given above.