However in my case i wanted to use gcc for normal compilation and intel compiler for my cmake project so method 1 was not suitable.
Cmake set compiler.
Specifying this is easy in cmake.
This method is not guaranteed to work for all generators.
How to set c or c compiler for cmake first posted on.
Cmake evaluates the environment variables cc for the c compiler cxx for the c compiler and fc for the fortran compiler.
The compiler used is not something you want hard coded into a cmakelists txt file.
That is not the way cmake works.
2013 12 24 02 14 34 00 00 sometimes you might need to use a different version of a default compiler like gcc or a different compiler like intel compiler to build your code.
On 4 30 2015 12 52 pm nikolaus rath wrote.
For c and c set the cc and cxx environment variables.
Intel compiler clang or pgi or a different version then cmake uses by default one can either set environment variables or modify the cmakelists txt file.
As an alternative especially when you re new to cmake use the gui version under windows run cmake gui without parameters instead of cmake.
Thanks for sharing that.
If there s no compiler set it will ask you to pick one otherwise you have to clear the cache to make it reappear.
What i found worked reliably for me is to set cc and cxx and as needed cudacxx environment variables before running cmake.
Add these lines to your cmakelists txt.
Indeed method 1 and 2 listed in the faq are more elegant.
To select a specific compiler you have several solutions as exaplained in cmake wiki.
Once opened set your paths and click on configure.
Remember that the compiler is saved in the cache so i d start with a new build directory whenever you change.