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. understanding cmake -part 1-
Forum Updated to NodeBB v4.3 + New Features

understanding cmake -part 1-

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 323 Views 2 Watching
  • 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.
  • M Offline
    M Offline
    MasterQ
    wrote on 7 Oct 2024, 12:22 last edited by
    #1

    Hi,

    I have a very small cmake project for learning Qt. Now I have put my source code (cpp, h, ui) into a subdirectory (prg) of the project.

    CMakeList.txt:

    cmake_minimum_required(VERSION 3.16)
    
    project(FoE VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 20)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    set(CMAKE_PREFIX_PATH "/home/joachim/Qt/6.7.2/gcc_64/lib/cmake/")
    
    find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Sql)
    find_package(QT NAMES Qt6 REQUIRED COMPONENTS Sql)
    
    add_subdirectory(prg)
    
    

    and

    prg/CMakeList.txt

    cmake_minimum_required(VERSION 3.16)
    
    set(PROJECT_SOURCES
            main.cpp
            MainWindow.h MainWindow.cpp
            MainWindow.ui
    )
    
    add_executable(FoE ${PROJECT_SOURCES})
    
    target_link_libraries(FoE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Sql)
    target_include_directories(FoE INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
    
    include(GNUInstallDirs)
    install(
            TARGETS FoE
            BUNDLE DESTINATION .
            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
    
    

    I also have a second cmake project from some month ago and this has to be different. The important part is:

    find_package(Qt6 REQUIRED COMPONENTS Widgets)
    find_package(Qt6 REQUIRED COMPONENTS Core)
    find_package(Qt6 REQUIRED COMPONENTS Sql)
    

    If I omit the lines with find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets),
    cmakes complains.

    CMake Error at CMakeLists.txt:xx (find_package):
      By not providing "FindQt.cmake" in CMAKE_MODULE_PATH this project has asked
      CMake to find a package configuration file provided by "Qt", but CMake did
      not find one.
    
    

    Why is the behaviour of the two projects different? They are on the same machine, same Qt installation, same IDE, ...

    Do I miss something?

    Joachim

    P 1 Reply Last reply 7 Oct 2024, 15:29
    0
    • M MasterQ referenced this topic on 7 Oct 2024, 12:27
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 7 Oct 2024, 15:38 last edited by
      #3

      Simply use find_package(Qt6 REQUIRED COMPONTENS Widgets Sql and target_link_libraries(FoE PRIVATE Qt6::Widgets Qt6::Sql) - don't think you will ever support anything other than Qt6 so it's not worth the trouble.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • M MasterQ
        7 Oct 2024, 12:22

        Hi,

        I have a very small cmake project for learning Qt. Now I have put my source code (cpp, h, ui) into a subdirectory (prg) of the project.

        CMakeList.txt:

        cmake_minimum_required(VERSION 3.16)
        
        project(FoE VERSION 0.1 LANGUAGES CXX)
        
        set(CMAKE_AUTOUIC ON)
        set(CMAKE_AUTOMOC ON)
        set(CMAKE_AUTORCC ON)
        
        set(CMAKE_CXX_STANDARD 20)
        set(CMAKE_CXX_STANDARD_REQUIRED ON)
        
        set(CMAKE_PREFIX_PATH "/home/joachim/Qt/6.7.2/gcc_64/lib/cmake/")
        
        find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets)
        find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
        find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Sql)
        find_package(QT NAMES Qt6 REQUIRED COMPONENTS Sql)
        
        add_subdirectory(prg)
        
        

        and

        prg/CMakeList.txt

        cmake_minimum_required(VERSION 3.16)
        
        set(PROJECT_SOURCES
                main.cpp
                MainWindow.h MainWindow.cpp
                MainWindow.ui
        )
        
        add_executable(FoE ${PROJECT_SOURCES})
        
        target_link_libraries(FoE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Sql)
        target_include_directories(FoE INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
        
        include(GNUInstallDirs)
        install(
                TARGETS FoE
                BUNDLE DESTINATION .
                LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
                RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
        
        

        I also have a second cmake project from some month ago and this has to be different. The important part is:

        find_package(Qt6 REQUIRED COMPONENTS Widgets)
        find_package(Qt6 REQUIRED COMPONENTS Core)
        find_package(Qt6 REQUIRED COMPONENTS Sql)
        

        If I omit the lines with find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets),
        cmakes complains.

        CMake Error at CMakeLists.txt:xx (find_package):
          By not providing "FindQt.cmake" in CMAKE_MODULE_PATH this project has asked
          CMake to find a package configuration file provided by "Qt", but CMake did
          not find one.
        
        

        Why is the behaviour of the two projects different? They are on the same machine, same Qt installation, same IDE, ...

        Do I miss something?

        Joachim

        P Offline
        P Offline
        Pl45m4
        wrote on 7 Oct 2024, 15:29 last edited by
        #2

        @MasterQ said in understanding cmake -part 1-:

        Why is the behaviour of the two projects different?

        If you remove the package dependency, it won't work anymore as expected... so what is different?!


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        M 1 Reply Last reply 7 Oct 2024, 16:00
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 7 Oct 2024, 15:38 last edited by
          #3

          Simply use find_package(Qt6 REQUIRED COMPONTENS Widgets Sql and target_link_libraries(FoE PRIVATE Qt6::Widgets Qt6::Sql) - don't think you will ever support anything other than Qt6 so it's not worth the trouble.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • P Pl45m4
            7 Oct 2024, 15:29

            @MasterQ said in understanding cmake -part 1-:

            Why is the behaviour of the two projects different?

            If you remove the package dependency, it won't work anymore as expected... so what is different?!

            M Offline
            M Offline
            MasterQ
            wrote on 7 Oct 2024, 16:00 last edited by
            #4

            @Christian-Ehrlicher said in understanding cmake -part 1-:

            Simply use find_package(Qt6 REQUIRED COMPONTENS Widgets Sql and target_link_libraries(FoE PRIVATE Qt6::Widgets Qt6::Sql) - don't think you will ever support anything other than Qt6 so it's not worth the trouble.

            Year, that's it.

            OK, still not knowing what the real root cause is behind. Nevermind, it is running now.

            Thnx

            1 Reply Last reply
            0
            • M MasterQ has marked this topic as solved on 7 Oct 2024, 16:00

            1/4

            7 Oct 2024, 12:22

            • Login

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