In any case, CMake requires GCC version 4+?

I use some of the features provided by GCC v4 +, and I would like CMake to detect the GCC v4 compiler, and if it does not find it, return the GCC v4 error message.

Does anyone have modules / ideas on how to do something like this?

Thanks.

+6
gcc cmake
source share
4 answers

Use the try_compile () command and try to compile the following program

#if __GNUC__ != 4 #error #endif int main() { return 0; } 
+8
source share

A completely different (not necessarily the best) way to check gcc version would look something like this:

 if(CMAKE_COMPILER_IS_GNUCXX) exec_program( ${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE _compiler_output) string(REGEX REPLACE ".* ([0-9]\\.[0-9]\\.[0-9]) .*" "\\1" gcc_compiler_version ${_compiler_output}) message(STATUS "C++ compiler version: ${gcc_compiler_version} [${CMAKE_CXX_COMPILER}]") if(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]") message(FATAL_ERROR "foobar") ... if(gcc_compiler_version VERSION_GREATER "4.5.99") ... ... 
+7
source share

Soon there may be a solution in cmake itself, cf. http://cmake.3232098.n2.nabble.com/GCC-compiler-version-td7185771.html

Future cmake releases may include two variables: CMAKE_C_COMPILER_VERSION and CMAKE_CXX_COMPILER_VERSION .

Halas, I have not seen them in 2.8.8 changelog.

I am using the @cmaker solution now.

+4
source share

There is also a toolchain file that is mentioned in the vtk wiki . This allows you to specify custom toolchains. It is commonly used for cross-compiling, but I used it before to use other tools.

0
source share

All Articles