Test for supported Qt version with CMake





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







3















I'm using CMake to build a Qt project, and it uses some of the newer Qt features and requires at least version 5.3 to build properly. I'd like to be nice to the people trying to build the project and fail at CMake configure time with a logical error telling them their CMake version isn't recent enough, rather than with some esoteric build error.



I know that I'll be getting at least version 5.0 by simply using the module find_package syntax (i.e. find_package(Qt5Widgets REQURIED)), but it's not so obvious how to make sure I'm using the right minor version.
What's the easiest way to do this?










share|improve this question































    3















    I'm using CMake to build a Qt project, and it uses some of the newer Qt features and requires at least version 5.3 to build properly. I'd like to be nice to the people trying to build the project and fail at CMake configure time with a logical error telling them their CMake version isn't recent enough, rather than with some esoteric build error.



    I know that I'll be getting at least version 5.0 by simply using the module find_package syntax (i.e. find_package(Qt5Widgets REQURIED)), but it's not so obvious how to make sure I'm using the right minor version.
    What's the easiest way to do this?










    share|improve this question



























      3












      3








      3








      I'm using CMake to build a Qt project, and it uses some of the newer Qt features and requires at least version 5.3 to build properly. I'd like to be nice to the people trying to build the project and fail at CMake configure time with a logical error telling them their CMake version isn't recent enough, rather than with some esoteric build error.



      I know that I'll be getting at least version 5.0 by simply using the module find_package syntax (i.e. find_package(Qt5Widgets REQURIED)), but it's not so obvious how to make sure I'm using the right minor version.
      What's the easiest way to do this?










      share|improve this question
















      I'm using CMake to build a Qt project, and it uses some of the newer Qt features and requires at least version 5.3 to build properly. I'd like to be nice to the people trying to build the project and fail at CMake configure time with a logical error telling them their CMake version isn't recent enough, rather than with some esoteric build error.



      I know that I'll be getting at least version 5.0 by simply using the module find_package syntax (i.e. find_package(Qt5Widgets REQURIED)), but it's not so obvious how to make sure I'm using the right minor version.
      What's the easiest way to do this?







      qt cmake






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 18 '17 at 11:49









      Melebius

      3,11032235




      3,11032235










      asked Mar 25 '16 at 22:23









      Nicolas HolthausNicolas Holthaus

      3,93522464




      3,93522464
























          3 Answers
          3






          active

          oldest

          votes


















          1














          These days it is possible to pass a version to find_package, like this:



          find_package(Qt5Core 5.10 REQUIRED)


          The find_package call will fail if no compatible version of Qt5Core can be found:



          CMake Warning at CMakeLists.txt:15 (find_package):
          Could not find a configuration file for package "Qt5Core" that is
          compatible with requested version "5.10".

          The following configuration files were considered but not accepted:

          C:/some/where/lib/cmake/Qt5Core/Qt5CoreConfig.cmake, version: 5.9.4


          This is in-depth documented at https://cmake.org/cmake/help/latest/command/find_package.html#version-selection






          share|improve this answer































            6














            I know this is a somewhat old post, but you can check the version using Qt5Widgets_VERSION. Here's some example CMake code:



            find_package(Qt5Widgets REQUIRED)

            if (Qt5Widgets_FOUND)
            if (Qt5Widgets_VERSION VERSION_LESS 5.7.0)
            message(FATAL_ERROR "Minimum supported Qt5 version is 5.70!")
            endif()
            else()
            message(SEND_ERROR "The Qt5Widgets library could not be found!")
            endif(Qt5Widgets_FOUND)





            share|improve this answer































              0














              There's no direct way to do this with the Qt-provided cmake packages, but it's easy enough to query the Qt version using qmake. Assuming you have something similar to the following already in the cmake files to locate the Qt install



              set(QTDIR $ENV{QTDIR} CACHE STRING "Qt install path")
              list(APPEND CMAKE_PREFIX_PATH ${QTDIR})


              you can check the version and fail the configure step if it's too low like so



              set(QT_MINIMUM_VERSION 5.3.0)

              # Test for supported Qt version
              find_program(QMAKE_EXECUTABLE NAMES qmake HINTS ${QTDIR} ENV QTDIR PATH_SUFFIXES bin)
              execute_process(COMMAND ${QMAKE_EXECUTABLE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)
              if(QT_VERSION LESS QT_MINIMUM_VERSION)
              MESSAGE(FATAL_ERROR "Minimum supported Qt version: ${QT_MINIMUM_VERSION}.
              Installed version: ${QT_VERSION}")
              endif()





              share|improve this answer
























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36229013%2ftest-for-supported-qt-version-with-cmake%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1














                These days it is possible to pass a version to find_package, like this:



                find_package(Qt5Core 5.10 REQUIRED)


                The find_package call will fail if no compatible version of Qt5Core can be found:



                CMake Warning at CMakeLists.txt:15 (find_package):
                Could not find a configuration file for package "Qt5Core" that is
                compatible with requested version "5.10".

                The following configuration files were considered but not accepted:

                C:/some/where/lib/cmake/Qt5Core/Qt5CoreConfig.cmake, version: 5.9.4


                This is in-depth documented at https://cmake.org/cmake/help/latest/command/find_package.html#version-selection






                share|improve this answer




























                  1














                  These days it is possible to pass a version to find_package, like this:



                  find_package(Qt5Core 5.10 REQUIRED)


                  The find_package call will fail if no compatible version of Qt5Core can be found:



                  CMake Warning at CMakeLists.txt:15 (find_package):
                  Could not find a configuration file for package "Qt5Core" that is
                  compatible with requested version "5.10".

                  The following configuration files were considered but not accepted:

                  C:/some/where/lib/cmake/Qt5Core/Qt5CoreConfig.cmake, version: 5.9.4


                  This is in-depth documented at https://cmake.org/cmake/help/latest/command/find_package.html#version-selection






                  share|improve this answer


























                    1












                    1








                    1







                    These days it is possible to pass a version to find_package, like this:



                    find_package(Qt5Core 5.10 REQUIRED)


                    The find_package call will fail if no compatible version of Qt5Core can be found:



                    CMake Warning at CMakeLists.txt:15 (find_package):
                    Could not find a configuration file for package "Qt5Core" that is
                    compatible with requested version "5.10".

                    The following configuration files were considered but not accepted:

                    C:/some/where/lib/cmake/Qt5Core/Qt5CoreConfig.cmake, version: 5.9.4


                    This is in-depth documented at https://cmake.org/cmake/help/latest/command/find_package.html#version-selection






                    share|improve this answer













                    These days it is possible to pass a version to find_package, like this:



                    find_package(Qt5Core 5.10 REQUIRED)


                    The find_package call will fail if no compatible version of Qt5Core can be found:



                    CMake Warning at CMakeLists.txt:15 (find_package):
                    Could not find a configuration file for package "Qt5Core" that is
                    compatible with requested version "5.10".

                    The following configuration files were considered but not accepted:

                    C:/some/where/lib/cmake/Qt5Core/Qt5CoreConfig.cmake, version: 5.9.4


                    This is in-depth documented at https://cmake.org/cmake/help/latest/command/find_package.html#version-selection







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 16 '18 at 13:38









                    hole-otter-rosyhole-otter-rosy

                    914




                    914

























                        6














                        I know this is a somewhat old post, but you can check the version using Qt5Widgets_VERSION. Here's some example CMake code:



                        find_package(Qt5Widgets REQUIRED)

                        if (Qt5Widgets_FOUND)
                        if (Qt5Widgets_VERSION VERSION_LESS 5.7.0)
                        message(FATAL_ERROR "Minimum supported Qt5 version is 5.70!")
                        endif()
                        else()
                        message(SEND_ERROR "The Qt5Widgets library could not be found!")
                        endif(Qt5Widgets_FOUND)





                        share|improve this answer




























                          6














                          I know this is a somewhat old post, but you can check the version using Qt5Widgets_VERSION. Here's some example CMake code:



                          find_package(Qt5Widgets REQUIRED)

                          if (Qt5Widgets_FOUND)
                          if (Qt5Widgets_VERSION VERSION_LESS 5.7.0)
                          message(FATAL_ERROR "Minimum supported Qt5 version is 5.70!")
                          endif()
                          else()
                          message(SEND_ERROR "The Qt5Widgets library could not be found!")
                          endif(Qt5Widgets_FOUND)





                          share|improve this answer


























                            6












                            6








                            6







                            I know this is a somewhat old post, but you can check the version using Qt5Widgets_VERSION. Here's some example CMake code:



                            find_package(Qt5Widgets REQUIRED)

                            if (Qt5Widgets_FOUND)
                            if (Qt5Widgets_VERSION VERSION_LESS 5.7.0)
                            message(FATAL_ERROR "Minimum supported Qt5 version is 5.70!")
                            endif()
                            else()
                            message(SEND_ERROR "The Qt5Widgets library could not be found!")
                            endif(Qt5Widgets_FOUND)





                            share|improve this answer













                            I know this is a somewhat old post, but you can check the version using Qt5Widgets_VERSION. Here's some example CMake code:



                            find_package(Qt5Widgets REQUIRED)

                            if (Qt5Widgets_FOUND)
                            if (Qt5Widgets_VERSION VERSION_LESS 5.7.0)
                            message(FATAL_ERROR "Minimum supported Qt5 version is 5.70!")
                            endif()
                            else()
                            message(SEND_ERROR "The Qt5Widgets library could not be found!")
                            endif(Qt5Widgets_FOUND)






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 13 '16 at 18:32









                            Phobos D'thorgaPhobos D'thorga

                            156214




                            156214























                                0














                                There's no direct way to do this with the Qt-provided cmake packages, but it's easy enough to query the Qt version using qmake. Assuming you have something similar to the following already in the cmake files to locate the Qt install



                                set(QTDIR $ENV{QTDIR} CACHE STRING "Qt install path")
                                list(APPEND CMAKE_PREFIX_PATH ${QTDIR})


                                you can check the version and fail the configure step if it's too low like so



                                set(QT_MINIMUM_VERSION 5.3.0)

                                # Test for supported Qt version
                                find_program(QMAKE_EXECUTABLE NAMES qmake HINTS ${QTDIR} ENV QTDIR PATH_SUFFIXES bin)
                                execute_process(COMMAND ${QMAKE_EXECUTABLE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)
                                if(QT_VERSION LESS QT_MINIMUM_VERSION)
                                MESSAGE(FATAL_ERROR "Minimum supported Qt version: ${QT_MINIMUM_VERSION}.
                                Installed version: ${QT_VERSION}")
                                endif()





                                share|improve this answer




























                                  0














                                  There's no direct way to do this with the Qt-provided cmake packages, but it's easy enough to query the Qt version using qmake. Assuming you have something similar to the following already in the cmake files to locate the Qt install



                                  set(QTDIR $ENV{QTDIR} CACHE STRING "Qt install path")
                                  list(APPEND CMAKE_PREFIX_PATH ${QTDIR})


                                  you can check the version and fail the configure step if it's too low like so



                                  set(QT_MINIMUM_VERSION 5.3.0)

                                  # Test for supported Qt version
                                  find_program(QMAKE_EXECUTABLE NAMES qmake HINTS ${QTDIR} ENV QTDIR PATH_SUFFIXES bin)
                                  execute_process(COMMAND ${QMAKE_EXECUTABLE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)
                                  if(QT_VERSION LESS QT_MINIMUM_VERSION)
                                  MESSAGE(FATAL_ERROR "Minimum supported Qt version: ${QT_MINIMUM_VERSION}.
                                  Installed version: ${QT_VERSION}")
                                  endif()





                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    There's no direct way to do this with the Qt-provided cmake packages, but it's easy enough to query the Qt version using qmake. Assuming you have something similar to the following already in the cmake files to locate the Qt install



                                    set(QTDIR $ENV{QTDIR} CACHE STRING "Qt install path")
                                    list(APPEND CMAKE_PREFIX_PATH ${QTDIR})


                                    you can check the version and fail the configure step if it's too low like so



                                    set(QT_MINIMUM_VERSION 5.3.0)

                                    # Test for supported Qt version
                                    find_program(QMAKE_EXECUTABLE NAMES qmake HINTS ${QTDIR} ENV QTDIR PATH_SUFFIXES bin)
                                    execute_process(COMMAND ${QMAKE_EXECUTABLE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)
                                    if(QT_VERSION LESS QT_MINIMUM_VERSION)
                                    MESSAGE(FATAL_ERROR "Minimum supported Qt version: ${QT_MINIMUM_VERSION}.
                                    Installed version: ${QT_VERSION}")
                                    endif()





                                    share|improve this answer













                                    There's no direct way to do this with the Qt-provided cmake packages, but it's easy enough to query the Qt version using qmake. Assuming you have something similar to the following already in the cmake files to locate the Qt install



                                    set(QTDIR $ENV{QTDIR} CACHE STRING "Qt install path")
                                    list(APPEND CMAKE_PREFIX_PATH ${QTDIR})


                                    you can check the version and fail the configure step if it's too low like so



                                    set(QT_MINIMUM_VERSION 5.3.0)

                                    # Test for supported Qt version
                                    find_program(QMAKE_EXECUTABLE NAMES qmake HINTS ${QTDIR} ENV QTDIR PATH_SUFFIXES bin)
                                    execute_process(COMMAND ${QMAKE_EXECUTABLE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)
                                    if(QT_VERSION LESS QT_MINIMUM_VERSION)
                                    MESSAGE(FATAL_ERROR "Minimum supported Qt version: ${QT_MINIMUM_VERSION}.
                                    Installed version: ${QT_VERSION}")
                                    endif()






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Mar 25 '16 at 22:23









                                    Nicolas HolthausNicolas Holthaus

                                    3,93522464




                                    3,93522464






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36229013%2ftest-for-supported-qt-version-with-cmake%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        List item for chat from Array inside array React Native

                                        Thiostrepton

                                        Caerphilly