1
votes

I have some C++ code I build with CMake (3.x), which I need to link using g++ 4.x rather than 5.x due to a Boost library issue.

My system has /usr/bin/g++ linking to /usr/bin/g++-5.2 , and also /usr/bin/g++-4.9 . Obviously I could have my CMakeLists.txt manually choose /usr/bin/g++-4.9 as my compiler, but that means it'll break on another system... how can I get CMake to find "a version of g++ >=4 but < 5"? Or "The latest version of g++ that's still < 5"?

1

1 Answers

2
votes

You cannot do this with the built-in mechanisms. CMake searches for /usr/bin/c++ and if that works, it does not look further. You can check the version number of the found compiler and emit an error in case it does not hold your constraints. Advice your users (or use yourself) the CMake variables CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to indicate which compiler you want to use.