I am deploying a small application to several different systems (mac, linux, linux64) where it needs to be compiled. I would like to tell cmake to the latest gcc available in a particular system. For example, Mac 10.6 has gcc 4.0 and gcc 4.2 (default). But some users have also gcc 4.4 installed through MacPorts (it is not the default). I would like cmake to use gcc44 in this case. In other linux systems, the latest gcc is 4.4 or 4.5 What is the more robust way to achieve this?
Thanks,
H
CMake honors the environment variables CC and CXX upon detecting the C and C++ compiler to use. E.g., if those variables point to clang, it will use clang by default:
$ export CC=/usr/bin/clang
$ export CXX=/usr/bin/clang++
$ cmake ..
-- The C compiler identification is Clang
-- The CXX compiler identification is Clang
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- works
...
You could either define these as system wide environment variables pointing to the preferred compilers or write a small shell wrapper script which tests the availability of several compilers and sets the variables accordingly before invoking cmake.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With