Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Building clang (win32)

Alexander Siol edited this page Jul 2, 2014 · 10 revisions

In this short tutorial, we're going to show you how to build llvm and clang in order to compile Tria. Note: clang is not required to use the Nuria Framework, only to build Tria from source!

Requirements

  • MinGW-based build environment for C/C++. We recommend using the packaged MinGW installed alongside with the official Qt binaries.
  • CMake 2.8 or higher. Get your binaries here.
  • Python. llvm needs this for building and tests. Fetch an installer from here and make sure you let the installer add it to your system path.

If you're using your current Qt version for the first time with cmake, you'll need to copy the Qt cmake modules so that cmake can find the compiler and Qt itself. Just copy *.cmake from your Qt directory (C:\Qt\5.3 by default, mind the version!) to [your CMake install]\share\cmake-X.Y\Modules (substitute X.Y with your CMake version).

Qt (qmake.exe), MinGW (g++.exe), CMake (cmake.exe) and Python (python.exe) all need to be in your PATH.

Getting the Source

You'll need the source code archives for:

  • llvm 3.4.x
  • clang 3.4.x

Both can be grabbed over at llvm.org.

Unpack the llvm source to llvm-src (anywhere, that name is just how we'll refer to it from now on). Clang (internally called cfe by llvm devs) needs to go to llvm-src\tools\clang - move and rename the cfe-3.4.x.src directory in the archive accordingly.

Configuring

For the next step, you'll be needing a build directory, in which Makefiles will be generated and code compiled. This can be anywhere, but we strongly recommend keeping it outside of the source tree. Consider using llvm-build in the same top directory as llvm-src is. We'll assume it is that way.

Get a shell open at llvm-build. First, you'll need to generate Makefiles using cmake. cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE="release" -DCMAKE_INSTALL_PREFIX="path\to\llvm-install" path\to\llvm-src What this does is tell cmake to generate Makefiles for use with an MinGW environment (-G "MinGW Makefiles"), build as release (that is, without debug information) and to plan for an install to path\to\llvm-install. This is important, since we can't just use a built but not installed clang for building Tria, as a lot of libraries and generated headers are scattered around all over build and source directories where they are not found. If you're following the advised directory structure, install to llvm-3.4.x in the same top-level directory as llvm-src and llvm-build are.

You can give additional options here, a full reference can be found in the llvm CMake reference. We recommend limiting which targets to build to x86, just to keep compile time short. The option used for that is -DLLVM_TARGETS_TO_BUILD="X86".

Full example (using the recommended directory structure): cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE="release" -DCMAKE_INSTALL_PREFIX="..\llvm-3.4.x" -DLLVM_TARGETS_TO_BUILD="X86" ..\llvm-src

Compiling

Compile it just like any other software, only remember that make is called mingw32-make in MinGW environments. mingw32-make If everything compiled successfully, you'll want to install it afterwards. mingw32-make install And that's it! You'll need to have [your llvm install]\bin in your path in order to build Tria.

Tips

  • You can build with multiple threads, just append -jX (substitute X for thread count, i.e. cpu cores * 2) to the mingw32-make command. Note that this may not work correctly (as it can potentially mess up internal dependencies), if you encounter an error just start mingw32-make again without using multithreading. This will continue compiling with one thread, not restart from scratch.
  • Do compile for release mode. While it might be useful to have debug codes around, compiling will usually fail as 32-bit compilers will run out of memory. If you know how to set up a native 64-bit MinGW environment, please contribute!
Clone this wiki locally