Conan: [cmake][clang] compiler version check fails when `compiler.version` is different as `major.minor`

Created on 30 Jul 2018  路  4Comments  路  Source: conan-io/conan

Conan Version 1.5.2
Compiler: Clang-based

The compiler version check in the generated conanbuildinfo.cmake file (check_compiler_version function) extracts the major and minor version components from CMAKE_CXX_COMPILER_VERSION and compares them against CONAN_COMPILER_VERSION. This works fine when the compiler.version also consists of exactly major.minor. However, as soon as, for example, a more specific version like major.minor.patch is specified the check incorrectly fails even though the versions do actually match exactly.

In the specific case where I encountered this error a custom llvm/clang compiler with the version 6.99.1 has been used. CMake correctly recognises the version and provides 6.99.1 in CMAKE_CXX_COMPILER_VERSION. However, when compiler.version = 6.99.1 is specified in the associated profile (and white-listed in the settings.yml), configuring the project fails with the following error:
~
Incorrect 'clang' version 'compiler.version=6.99.1' is not the one detected
by CMake: 'Clang=6.99
~

Of course, as workaround, I can specify compiler.version=6.99 to match conan's expectations that compiler.version adheres to major.minor. However, it is clearly a bug to report a version mismatch when the versions actually match perfectly.

bug

All 4 comments

Thanks for reporting!

Could you check replacing this function in the conanbuildinfo.cmake?

function(check_compiler_version)
    conan_split_version(${CMAKE_CXX_COMPILER_VERSION} VERSION_MAJOR VERSION_MINOR)
    if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
        # https://cmake.org/cmake/help/v3.2/variable/MSVC_VERSION.html
        if( (CONAN_COMPILER_VERSION STREQUAL "14" AND NOT VERSION_MAJOR STREQUAL "19") OR
            (CONAN_COMPILER_VERSION STREQUAL "12" AND NOT VERSION_MAJOR STREQUAL "18") OR
            (CONAN_COMPILER_VERSION STREQUAL "11" AND NOT VERSION_MAJOR STREQUAL "17") OR
            (CONAN_COMPILER_VERSION STREQUAL "10" AND NOT VERSION_MAJOR STREQUAL "16") OR
            (CONAN_COMPILER_VERSION STREQUAL "9" AND NOT VERSION_MAJOR STREQUAL "15") OR
            (CONAN_COMPILER_VERSION STREQUAL "8" AND NOT VERSION_MAJOR STREQUAL "14") OR
            (CONAN_COMPILER_VERSION STREQUAL "7" AND NOT VERSION_MAJOR STREQUAL "13") OR
            (CONAN_COMPILER_VERSION STREQUAL "6" AND NOT VERSION_MAJOR STREQUAL "12") )
            conan_error_compiler_version()
        endif()
    elseif(CONAN_COMPILER STREQUAL "gcc")
        set(_CHECK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
        if(NOT ${CONAN_COMPILER_VERSION} VERSION_LESS 5.0)
            message(STATUS "Conan: Compiler GCC>=5, checking major version ${CONAN_COMPILER_VERSION}")
            conan_split_version(${CONAN_COMPILER_VERSION} CONAN_COMPILER_MAJOR CONAN_COMPILER_MINOR)
            if("${CONAN_COMPILER_MINOR}" STREQUAL "")
                set(_CHECK_VERSION ${VERSION_MAJOR})
            endif()
        endif()
        message(STATUS "Conan: Checking correct version: ${_CHECK_VERSION}")
        if(NOT ${_CHECK_VERSION} VERSION_EQUAL CONAN_COMPILER_VERSION)
            conan_error_compiler_version()
        endif()
    elseif(CONAN_COMPILER MATCHES "clang" OR CONAN_COMPILER STREQUAL "sun-cc")
        conan_split_version(${CONAN_COMPILER_VERSION} CONAN_COMPILER_MAJOR CONAN_COMPILER_MINOR)
        if(NOT ${VERSION_MAJOR}.${VERSION_MINOR} VERSION_EQUAL ${CONAN_COMPILER_MAJOR}.${CONAN_COMPILER_MINOR})
           conan_error_compiler_version()
        endif()
    else()
        message(STATUS "WARN: Unknown compiler '${CONAN_COMPILER}', skipping the version check...")
    endif()
endfunction()

Thank you @lasote for the quick fix, using your new function works like expected!

Best,
Mario

Great, many thanks for trying it. I'll submit the patch for the 1.7.

Was this page helpful?
0 / 5 - 0 ratings