I want to have CMake build using a gcc compiler I installed on my MacOSx
I built the gcc-5.4.0 distribution and installed it at /usr/local/gcc-5.4.0 all the compilers are under /usr/local/gcc-5.4.0/bin
I am using the CMake version 3.6.1
I want to have CMake build using a gcc compiler I installed on my MacOSx
I built the gcc-5.4.0 distribution and installed it at /usr/local/gcc-5.4.0 all the compilers are under /usr/local/gcc-5.4.0/bin
I am using the CMake version 3.6.1
Everything is detailed in the CMake FAQ
How do I use a different compiler? Method 1: use environment variables
For C and C++, set the CC and CXX environment variables. This method is not guaranteed to work for all generators. (Specifically, if you are trying to set Xcode's GCC_VERSION, this method confuses Xcode.)
For example:
CC=gcc-4.2 CXX=/usr/bin/g++-4.2 cmake -G "Your Generator" path/to/your/source
Method 2: use cmake -D
Set the appropriate CMAKE_FOO_COMPILER variable(s) to a valid compiler name or full path on the command-line using cmake -D.
For example:
cmake -G "Your Generator" -D CMAKE_C_COMPILER=gcc-4.2 -D CMAKE_CXX_COMPILER=g++-4.2 path/to/your/source
Method 3 (avoid): use set()
Set the appropriate CMAKE_FOO_COMPILER variable(s) to a valid compiler name or full path in a list file using set(). This must be done before any language is set (ie before any project() or enable_language() command).
For example:
set(CMAKE_C_COMPILER "gcc-4.2") set(CMAKE_CXX_COMPILER "/usr/bin/g++-4.2")
project("YourProjectName")