File: CompareCompilerVersion.cmake

package info (click to toggle)
cmake 4.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 152,344 kB
  • sloc: ansic: 403,894; cpp: 303,807; sh: 4,097; python: 3,582; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 108; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (41 lines) | stat: -rw-r--r-- 2,533 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function(compare_compiler_version lang)
  cmake_policy(GET CMP0129 LCC_FALLBACK_MODE)
  if(${CMAKE_${lang}_COMPILER} STREQUAL "LCC" OR ${CMAKE_${lang}_COMPILER} STREQUAL "GNU")
    execute_process(COMMAND ${CMAKE_${lang}_COMPILER} --version OUTPUT_VARIABLE output)
    if("${output}" MATCHES [[lcc:([0-9]+.[0-9]+.([0-9]+)):]])
      set(native_version ${CMAKE_MATCH_1})
    else()
      message(FATAL_ERROR "Can not identify native LCC version for language ${lang}.")
    endif()
    if("${output}" MATCHES [[\(GCC\) ([0-9]+.[0-9]+.([0-9]+)) compatible]])
      set(simulated_version ${CMAKE_MATCH_1})
    else()
      message(FATAL_ERROR "Can not identify simulated GNU version for language ${lang}.")
    endif()
    message(STATUS "Compiler native version is ${native_version}, simulated version is ${simulated_version}.")
    if("${LCC_FALLBACK_MODE}" STREQUAL "NEW")
      if(NOT "${CMAKE_${lang}_COMPILER_ID}" STREQUAL "LCC")
        message(FATAL_ERROR "Policy is in NEW mode, but compiler identification is ${CMAKE_${lang}_COMPILER_ID} instead of LCC.")
      endif()
      if(NOT "${CMAKE_${lang}_COMPILER_VERSION}" STREQUAL "${native_version}")
        message(FATAL_ERROR "Policy is in NEW mode, but compiler version is ${CMAKE_${lang}_COMPILER_VERSION} instead of ${native_version}.")
      endif()
      if(NOT "${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "GNU")
        message(FATAL_ERROR "Policy is in NEW mode, but simulated compiler identification is ${CMAKE_${lang}_SIMULATE_ID} instead of GNU.")
      endif()
      if(NOT "${CMAKE_${lang}_SIMULATE_VERSION}" STREQUAL "${simulated_version}")
        message(FATAL_ERROR "Policy is in NEW mode, but simulated compiler version is ${CMAKE_${lang}_SIMULATE_VERSION} instead of ${simulated_version}.")
      endif()
    else()
      if(NOT "${CMAKE_${lang}_COMPILER_ID}" STREQUAL "GNU")
        message(FATAL_ERROR "Policy is in OLD mode, but compiler identification is ${CMAKE_${lang}_COMPILER_ID} instead of GNU.")
      endif()
      if(NOT "${CMAKE_${lang}_COMPILER_VERSION}" STREQUAL "${simulated_version}")
        message(FATAL_ERROR "Policy is in OLD mode, but compiler version is ${CMAKE_${lang}_COMPILER_VERSION} instead of ${simulated_version}.")
      endif()
      if(${CMAKE_${lang}_SIMULATE_VERSION} OR ${CMAKE_${lang}_SIMULATE_ID)
        message(FATAL_ERROR "Policy is in OLD mode, but simulated compiler ID/version is ${CMAKE_${lang}_COMPILER_ID}/${CMAKE_${lang}_COMPILER_VERSION} instead of undefined.")
      endif()
    endif()
  endif()
endfunction()