It would be nice to switch between different compiler systems based on current requirements. I.e. CLang is known to produce better error messages especially with C++ templates, GCC might be the reference compiler and Icecream supports faster development by reducing compile times.
Since all 3 system produce compatible binary outputs it would be nice to switch without the need to rebuild everything, i.e. dependencies etc. Ideally switch is possible to just run a single build.
Challenge: CMake doesn't support switching compiler for an already configured build system. Normally you would have to delete your build directory and reconfigure or maintain different build directories.
Solution:
- Use CCache as a compiler wrapper.
- Configure your CMake based build using CCache as the compiler
- Before actual build set environment variables to tell CCache which compiler it should really use
The scripts in this gist provide tools to setup a system as described above.
To use the system:
- Setup Icecream, CCache, CMake, GCC and CLang according to the instructions given for your specific Linux distribution (This has been tested on Ubuntu 14.04)
- Put all the scripts in a location accessible from your path. A good place would be
$(HOME)/bin
for example.
- Configure the buildsystem using CMake as usually but put
ccache_env
in front of yourcmake
command to modify paths to force CMake to find CCache first.
Example:
$myhome/mydev/project/build> ccache_env cmake ..
- This is the default.
- Just use make to run your build using CCache and GCC
- To use icecc as your compiler, wrap your call to make through the script below to setup the necessary environment variables for CCache
- Note: Icecream has to be setup and working on your system already according to the requirements set by your Linux distribution.
Example:
$myhome/mydev/project/build> icecc_make
- I like to use another BASH alias to setup more detailed options for make:
alias icemake='nice -n 10 icecc_make -j -l6 '
and just callicemake
instead of make
- Using CLang follows the same main principle but requires an extra wrapper script to properly wrap options for clang.
- To use clang as your compiler, wrap your call to make through the script below to setup the necessary environment variables for CCache and use the clang-wrapper script
- Note: CLang has to be setup and working on your system already according to the requirements set by your Linux distribution.
Example:
$myhome/mydev/project/build> clang_make