Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using CMake build system

Using CMake build system

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tomy
    wrote on 24 May 2020, 20:13 last edited by tomy
    #1

    Hi all,

    Have you used CMake instead of qmake in your Qt Widgets projects, please?
    For me, it's the first time and want to make use of Docs (https://doc.qt.io/qt-5/cmake-get-started.html) for that, but it's ambiguous as usual (mostly).
    I did these:
    Created a Qt project called CMTest inheriting QLabel as the base class and without a .ui file and selecting CMake as the build system.
    It now looks like this:

    Capture.PNG

    Then Docs say:

    For find_package to be successful, CMake must find the Qt installation in one of the following ways:
    Set your CMAKE_PREFIX_PATH environment variable to the Qt 5 installation prefix. This is the recommended way.

    But I can't find CMAKE_PREFIX_PATH environment variable in the Projects > Build Environment list (Details)!

    J 1 Reply Last reply 25 May 2020, 05:29
    0
    • T tomy
      24 May 2020, 20:13

      Hi all,

      Have you used CMake instead of qmake in your Qt Widgets projects, please?
      For me, it's the first time and want to make use of Docs (https://doc.qt.io/qt-5/cmake-get-started.html) for that, but it's ambiguous as usual (mostly).
      I did these:
      Created a Qt project called CMTest inheriting QLabel as the base class and without a .ui file and selecting CMake as the build system.
      It now looks like this:

      Capture.PNG

      Then Docs say:

      For find_package to be successful, CMake must find the Qt installation in one of the following ways:
      Set your CMAKE_PREFIX_PATH environment variable to the Qt 5 installation prefix. This is the recommended way.

      But I can't find CMAKE_PREFIX_PATH environment variable in the Projects > Build Environment list (Details)!

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 25 May 2020, 05:29 last edited by
      #2

      @tomy said in Using CMake build system:

      But I can't find CMAKE_PREFIX_PATH environment variable in the Projects > Build Environment list (Details)!

      You can always add variables there...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply 25 May 2020, 07:28
      1
      • J jsulm
        25 May 2020, 05:29

        @tomy said in Using CMake build system:

        But I can't find CMAKE_PREFIX_PATH environment variable in the Projects > Build Environment list (Details)!

        You can always add variables there...

        T Offline
        T Offline
        tomy
        wrote on 25 May 2020, 07:28 last edited by tomy
        #3

        @jsulm

        I did that this way, if it's correct:

        Capture.PNG

        And this is my CMake text file contents:

        cmake_minimum_required(VERSION 3.5)
        
        project(CMTest LANGUAGES CXX)
        
        set(CMAKE_INCLUDE_CURRENT_DIR ON)
        
        set(CMAKE_AUTOUIC ON)
        set(CMAKE_AUTOMOC ON)
        set(CMAKE_AUTORCC ON)
        
        set(CMAKE_CXX_STANDARD 11)
        set(CMAKE_CXX_STANDARD_REQUIRED ON)
        
        # QtCreator supports the following variables for Android, which are identical to qmake Android variables.
        # Check http://doc.qt.io/qt-5/deployment-android.html for more information.
        # They need to be set before the find_package(Qt5 ...) call.
        
        #if(ANDROID)
        #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
        #    if (ANDROID_ABI STREQUAL "armeabi-v7a")
        #        set(ANDROID_EXTRA_LIBS
        #            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
        #            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
        #    endif()
        #endif()
        
        find_package(Qt5 COMPONENTS Widgets REQUIRED)
        
        if(ANDROID)
          add_library(CMTest SHARED
            main.cpp
            cmtest.cpp
            cmtest.h
          )
        else()
          add_executable(CMTest
            main.cpp
            cmtest.cpp
            cmtest.h
          )
        endif()
        
        target_link_libraries(CMTest PRIVATE Qt5::Widgets)
        

        When I run CMake, these error emerge:

        Capture.PNG

        I'm confused and don't know what to do next! :(

        J 1 Reply Last reply 25 May 2020, 07:46
        0
        • T tomy
          25 May 2020, 07:28

          @jsulm

          I did that this way, if it's correct:

          Capture.PNG

          And this is my CMake text file contents:

          cmake_minimum_required(VERSION 3.5)
          
          project(CMTest LANGUAGES CXX)
          
          set(CMAKE_INCLUDE_CURRENT_DIR ON)
          
          set(CMAKE_AUTOUIC ON)
          set(CMAKE_AUTOMOC ON)
          set(CMAKE_AUTORCC ON)
          
          set(CMAKE_CXX_STANDARD 11)
          set(CMAKE_CXX_STANDARD_REQUIRED ON)
          
          # QtCreator supports the following variables for Android, which are identical to qmake Android variables.
          # Check http://doc.qt.io/qt-5/deployment-android.html for more information.
          # They need to be set before the find_package(Qt5 ...) call.
          
          #if(ANDROID)
          #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
          #    if (ANDROID_ABI STREQUAL "armeabi-v7a")
          #        set(ANDROID_EXTRA_LIBS
          #            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
          #            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
          #    endif()
          #endif()
          
          find_package(Qt5 COMPONENTS Widgets REQUIRED)
          
          if(ANDROID)
            add_library(CMTest SHARED
              main.cpp
              cmtest.cpp
              cmtest.h
            )
          else()
            add_executable(CMTest
              main.cpp
              cmtest.cpp
              cmtest.h
            )
          endif()
          
          target_link_libraries(CMTest PRIVATE Qt5::Widgets)
          

          When I run CMake, these error emerge:

          Capture.PNG

          I'm confused and don't know what to do next! :(

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 25 May 2020, 07:46 last edited by jsulm
          #4

          @tomy You set wrong path. Take a look at https://stackoverflow.com/questions/22215900/add-the-installation-prefix-of-qt5widgets-to-cmake-prefix-path
          Also, as you can see Ninja was not found. If you do not have it then set Make as build tool.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply 25 May 2020, 14:32
          0
          • J jsulm
            25 May 2020, 07:46

            @tomy You set wrong path. Take a look at https://stackoverflow.com/questions/22215900/add-the-installation-prefix-of-qt5widgets-to-cmake-prefix-path
            Also, as you can see Ninja was not found. If you do not have it then set Make as build tool.

            T Offline
            T Offline
            tomy
            wrote on 25 May 2020, 14:32 last edited by tomy
            #5

            @jsulm

            I've Ninja at: "C:\Qt\Tools\Ninja"
            So added the following two lines

            set(CMAKE_PREFIX_PATH "C:\\Qt\\5.14.2\\mingw73_64\\bin\\")
            set(CMAKE_MAKE_PROGRAM "C:\\Qt\\Tools\\Ninja\\")
            

            after:

            cmake_minimum_required(VERSION 3.5)
            project(CMTest LANGUAGES CXX)
            

            in CMakeLists.txt file

            As well as, changed the CMAKE_PREFIX_PATH on Build Environment to C:\Qt\5.14.2\mingw73_64\bin.

            Still the same errors! Why are the stuff that complicated?! :(

            J 1 Reply Last reply 26 May 2020, 05:20
            0
            • T tomy
              25 May 2020, 14:32

              @jsulm

              I've Ninja at: "C:\Qt\Tools\Ninja"
              So added the following two lines

              set(CMAKE_PREFIX_PATH "C:\\Qt\\5.14.2\\mingw73_64\\bin\\")
              set(CMAKE_MAKE_PROGRAM "C:\\Qt\\Tools\\Ninja\\")
              

              after:

              cmake_minimum_required(VERSION 3.5)
              project(CMTest LANGUAGES CXX)
              

              in CMakeLists.txt file

              As well as, changed the CMAKE_PREFIX_PATH on Build Environment to C:\Qt\5.14.2\mingw73_64\bin.

              Still the same errors! Why are the stuff that complicated?! :(

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 26 May 2020, 05:20 last edited by
              #6

              @tomy said in Using CMake build system:

              CMAKE_MAKE_PROGRAM

              This needs to point to the executable, not a directory! So, whole path to ninja.exe.

              "set(CMAKE_PREFIX_PATH "C:\Qt\5.14.2\mingw73_64\bin\")" - this needs to be

              set(CMAKE_PREFIX_PATH "C:\\Qt\\5.14.2\\mingw73_64")
              

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              T 1 Reply Last reply 26 May 2020, 07:09
              0
              • J jsulm
                26 May 2020, 05:20

                @tomy said in Using CMake build system:

                CMAKE_MAKE_PROGRAM

                This needs to point to the executable, not a directory! So, whole path to ninja.exe.

                "set(CMAKE_PREFIX_PATH "C:\Qt\5.14.2\mingw73_64\bin\")" - this needs to be

                set(CMAKE_PREFIX_PATH "C:\\Qt\\5.14.2\\mingw73_64")
                
                T Offline
                T Offline
                tomy
                wrote on 26 May 2020, 07:09 last edited by tomy
                #7

                @jsulm

                Did these both:

                set(CMAKE_PREFIX_PATH "C:\\Qt\\5.14.2\\mingw73_64")
                set(CMAKE_MAKE_PROGRAM "C:\\Qt\\Tools\\Ninja\\ninja.exe")
                

                And:
                Capture.PNG

                Still both prior errors exist!

                This is my CMakeLists.txt file contents:

                cmake_minimum_required(VERSION 3.5)
                
                project(CMTest LANGUAGES CXX)
                
                set(CMAKE_PREFIX_PATH "C:\\Qt\\5.14.2\\mingw73_64")
                set(CMAKE_MAKE_PROGRAM "C:\\Qt\\Tools\\Ninja\\ninja.exe")
                
                
                set(CMAKE_INCLUDE_CURRENT_DIR ON)
                
                set(CMAKE_AUTOUIC ON)
                set(CMAKE_AUTOMOC ON)
                set(CMAKE_AUTORCC ON)
                
                set(CMAKE_CXX_STANDARD 11)
                set(CMAKE_CXX_STANDARD_REQUIRED ON)
                
                # QtCreator supports the following variables for Android, which are identical to qmake Android variables.
                # Check http://doc.qt.io/qt-5/deployment-android.html for more information.
                # They need to be set before the find_package(Qt5 ...) call.
                
                #if(ANDROID)
                #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
                #    if (ANDROID_ABI STREQUAL "armeabi-v7a")
                #        set(ANDROID_EXTRA_LIBS
                #            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
                #            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
                #    endif()
                #endif()
                
                find_package(Qt5 COMPONENTS Widgets REQUIRED)
                
                if(ANDROID)
                  add_library(CMTest SHARED
                    main.cpp
                    cmtest.cpp
                    cmtest.h
                  )
                else()
                  add_executable(CMTest
                    main.cpp
                    cmtest.cpp
                    cmtest.h
                  )
                endif()
                
                target_link_libraries(CMTest PRIVATE Qt5::Widgets)
                
                1 Reply Last reply
                0

                7/7

                26 May 2020, 07:09

                • Login

                • Login or register to search.
                7 out of 7
                • First post
                  7/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved