Setting the compiler with CMake is a bit delicate. Although the method you use setting CMAKE_CXX_COMPILER in CMakeLists.txt works, this is the least recommended way in CMake Help .
CLion supports CMake's FAQ method 2: using -D in a cmake call. Setting variables in CMakeLists.txt is not affected.
On a Mac, go to Preferences
On Linux / Windows, go to File | Settings File | Settings
then Build, Execution, Deployment | CMake | CMake options Build, Execution, Deployment | CMake | CMake options Build, Execution, Deployment | CMake | CMake options and enter the text:
-D CMAKE_C_COMPILER=/path/to/c_compiler -D CMAKE_CXX_COMPILER=/path/to/c++_compiler
See the CLion FAQ for more details.
Also note that when changing compilers, you will have to invalidate the CLion cache and restart, see my answer to How to clear the CMake cache in Clion? .
EDIT
After I wrote this answer, CLion added support for several build directories, as noted in @rubenvb's comments. This is another way to explore.
source share