Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a minimum compiler version requisite?

Tags:

cmake

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?

like image 704
Zhen Avatar asked Feb 18 '13 09:02

Zhen


People also ask

Is G ++ and GCC the same?

DIFFERENCE BETWEEN g++ & gccg++ is used to compile C++ program. gcc is used to compile C program.

What is G ++ compiler?

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.

How do I know if I have C++ compiler Mac?

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.


1 Answers

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.

like image 200
Angew is no longer proud of SO Avatar answered Nov 04 '22 21:11

Angew is no longer proud of SO