I'm working on a project using the C++ language (but - this is not a C++-specific question, really). On my system, there are several C++ compilers installed, several versions of the same compiler, and perhaps even some versions built myself under my own home directory. I use different compilers (of C++) for different purposes (although I'm exaggerating here a little to make the question more general).
Now, my project depends, for some reason, on the compiler being gcc rather than clang, and with version between 4.7 and 4.9 with a preference for a newer version.
I want to get CMake to find the relevant compilers I have, and to use the best one available, if there's a valid one. But - I want this to happen not just on my system; that is pretty easy to force. I want it to do this on any (reasonable) system, and not depend on the developer who grabs my code doing any customization of CMakeLists.txt or setting the compiler explicitly with CXX=/some/thing
etc.
More concretely:
- How do I affect the kinds of locations CMake looks for compilers in?
- How do I affect the order in which these locations are searched?
- How can I express preference of certain compiler providers and versions?
- How can I express constraints on the compiler provider and version?
Notes:
- Answers which work for CMake 3.x only are relevant, but I'm also interested in CMake 2.8.x .
- You can tell me to RTFM, but please be specific about what FM and where in the FM (and whether it will actually help me).
- I'm working on Linux in case it matters.