How to compile & install libc++ on Linux

Problem:

You want to compile and install libc++ (sometimes also named libcxx), but CMake complains with this error message

CMake Error at cmake/Modules/MacroEnsureOutOfSourceBuild.cmake:7 (message):
libcxx requires an out of source build. Please create a separate</em>

build directory and run 'cmake /path/to/libcxx [options]' there.
Call Stack (most recent call first):
 CMakeLists.txt:24 (MACRO_ENSURE_OUT_OF_SOURCE_BUILD)
CMake Error at cmake/Modules/MacroEnsureOutOfSourceBuild.cmake:8 (message):
 In-source builds are not allowed.

CMake would overwrite the makefiles distributed with Compiler-RT.
 Please create a directory and run cmake from there, passing the path
 to this source directory as the last argument.
 This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
 Please delete them.
Call Stack (most recent call first):
 CMakeLists.txt:24 (MACRO_ENSURE_OUT_OF_SOURCE_BUILD)

Solution:

Once you know what “out-of-source-build” means, it’s actually pretty easy: You must not execute cmake from the libcxx directory itself, you need to execute it from any parent directory – the build will take place there.

Just run this script in your favourite shell:

mkdir libc++
svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
cmake libcxx
make

This creates the directory libc++ inside your current directory and downloads and compiles the latest libc++ SVN trunk inside it. Run sudo make install inside the libc++ directory (not inside libcxx!) to install it globally.