How to find the Qt5 CMake module on Windows

后端 未结 6 606
独厮守ぢ
独厮守ぢ 2020-12-10 23:03

I\'m trying to make a very basic Qt5 application using CMake on Windows. I used the documentation of Qt5 to use CMake, and my main.cpp file just contains a

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 23:30

    The @tresf's solution perfectly covers the whole idea. It's only one thing to add: Microsoft's versioning seems to be turning into geometric progression. The series is too short yet to confirm, so as of 2019' the following formula may be used:

    # do some math trickery to guess folder
    # - qt uses (e.g.) "msvc2012"
    # - cmake uses (e.g.) "1800"
    # - see also https://cmake.org/cmake/help/v3.0/variable/MSVC_VERSION.html
    # - see also https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd
    if ((MSVC_VERSION GREATER_EQUAL "1920") AND (IS_DIRECTORY "${QT_VERSION}/msvc2019"))
        set(QT_MSVC "2019")
    elseif ((MSVC_VERSION GREATER_EQUAL "1910") AND (IS_DIRECTORY "${QT_VERSION}/msvc2017"))
        set(QT_MSVC "2017")
    elseif (MSVC_VERSION GREATER_EQUAL "1900")
        set(QT_MSVC "2015")
    else ()
        MATH(EXPR QT_MSVC "2000 + (${MSVC_VERSION} - 500) / 100")
    endif ()
    

提交回复
热议问题