简体   繁体   English

检查cmake中的gcc minor

[英]Check gcc minor in cmake

Is it possible to check the minor version number of GCC in cmake? 是否可以在cmake中检查GCC的次要版本号?

I want to do something like this: 我想做这样的事情:

If (GCC_MAJOR >= 4 && GCC_MINOR >= 3)

Use if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.2) as mentioned by onqtam. 使用if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.2)提到的if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.2) This obsolete answer was back from the 2.6 CMake days. 这个过时的答案是从2.6 CMake天回来的。

You could run gcc -dumpversion and parse the output. 你可以运行 gcc -dumpversion并解析输出。 Here is one way to do that: 这是一种方法:

 
 
 
  
  if (CMAKE_COMPILER_IS_GNUCC) execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION}) list(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR) list(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR) message(STATUS ${GCC_MAJOR}) message(STATUS ${GCC_MINOR}) endif()
 
  

That would print "4" and "3" for gcc version 4.3.1. 这将为gcc版本4.3.1打印“4”和“3”。 However you can use CMake's version checking syntax to make life a bit easier and skip the regex stuff: 但是,您可以使用CMake的版本检查语法来简化生活并跳过正则表达式:

 
 
 
  
  execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) if (GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3) message(STATUS "Version >= 4.3") endif()
 
  

从CMake 2.8.10开始, CMAKE_C_COMPILER_VERSIONCMAKE_CXX_COMPILER_VERSION变量完全用于此目的,因此您可以这样做:

if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.2)

Combining the 2 other answers, you can check the specific gcc version as follows: 结合其他2个答案,您可以检查具体的gcc版本,如下所示:

if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.1)
    ...
endif()

However, there is an argument, -dumpfullversion that provides the full version string. 但是,有一个参数, -dumpfullversion提供完整版本字符串。

gcc -dumpfullversion

should get what you want. 应该得到你想要的。 Still backward compatibility is broken in gcc 7. 仍然向后兼容性在gcc 7中被打破。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM