Default C++ compiler in Ubuntu 16.04

By default, your c++ compiler is a symlink to yet another symlink that is pointing to g++. To change this default, you'll need to use the update-alternatives command. To see what alternatives are currently installed for c++, use the --query c++ flags, e.g.:

sudo update-alternatives --query c++  

To install clang as an alternative on Ubuntu 16.04, run apt-get like so:

sudo apt-get install clang  

To choose clang as default, use the following command:

sudo update-alternatives --config c++  

After selecting your alternative, things like cmake will know what to do. This can be overridden by setting environment variables:

export CXX=/usr/bin/compiler

Or setting flags when creating the cmake cache:

cmake -DCMAKE_CXX_COMPILER="/usr/bin/compiler" ..

Check out the CMake documentation.