I want to create a project in C++11 and I use CMake as my build system.
How can I add a minimum compiler version requisite in the CMake config files?
DIFFERENCE BETWEEN g++ & gccg++ is used to compile C++ program. gcc is used to compile C program.
GNU C++ Compiler ( g++ ) is a compiler in Linux which is used to compile C++ programs. It compiles both files with extension . c and . cpp as C++ files. The following is the compiler command to compile C++ program.
Choose your platform and install. You can test by opening Terminal (Mac) / cmd.exe (Windows) and entering g++ . If you get a warning that no files were provided, then you're all set! Otherwise, if you get an error about the command not being found, then the C++ compiler is not installed properly.
AFAIK, there is no built-in support for something like this, but you could certainly write it yourself:
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "your.required.gcc.version") message(FATAL_ERROR "Insufficient gcc version") endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "your.required.msvc.version") message(FATAL_ERROR "Insufficient msvc version") endif() elseif(...) # etc. endif()
However, I suggest you actually consider a feature-detection approach instead. That is, use try_compile()
to verify that the compiler supports the features you need, and FATAL_ERROR
if it doesn't. It's more idiomatic in CMake, and has the added benefit you don't have to discover the appropriate minimal version for all compilers out there.
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