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. Dependencies across multiproject in CMake
QtWS25 Last Chance

Dependencies across multiproject in CMake

Scheduled Pinned Locked Moved Solved General and Desktop
cmakecmakelists.txt
6 Posts 3 Posters 708 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.
  • A Offline
    A Offline
    artwaw
    wrote on 28 Jul 2023, 16:25 last edited by
    #1

    Good afternoon,
    can someone clarify please:

    • I have a project composed (for now) of a library and desktop project
    • library uses network and sql, while desktop does not
      I can't compile target desktop because it complains about network classes, which are not a part of this project at all (library itself is).

    Root cmakelists:

    cmake_minimum_required(VERSION 3.5)
    
    project(
      boilerplate
      LANGUAGES CXX
      VERSION 0.1
      DESCRIPTION "boilerplate client")
    
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(Qt6 REQUIRED COMPONENTS Core Widgets Gui LinguistTools)
    #above is used in both lib and the program
    qt_standard_project_setup()
    add_subdirectory(Core)
    add_subdirectory(Desktop)
    

    Library cmakelists:

    find_package(Qt6 REQUIRED COMPONENTS Network Sql)
    
    set(TS_FILES Core_en_GB.ts)
    
    qt_add_library(Core SHARED
      core.h   core.cpp
      ${TS_FILES}
      logger.h logger.cpp
      ipmodel.h ipmodel.cpp
      core.qrc
      cookiejar.h cookiejar.cpp
    )
    target_link_libraries(Core PRIVATE Qt6::Core)
    target_link_libraries(Core PRIVATE Qt6::Network)
    target_link_libraries(Core PRIVATE Qt6::Sql)
    target_link_libraries(Core PRIVATE Qt6::Gui)
    target_include_directories(Core INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
    target_compile_definitions(Core PRIVATE BLACORE_LIBRARY)
    qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
    

    Desktop cmakelists:

    set(TS_FILES Desktop_en_GB.ts)
    set(PROJECT_SOURCES
            main.cpp
            blab.h blab.cpp blab.ui
            ${TS_FILES}
    )
    qt_add_executable(Desktop
            MANUAL_FINALIZATION
            ${PROJECT_SOURCES}
            desktop.rc desktop.qrc
    )
    qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
    target_link_libraries(Desktop PRIVATE Qt6::Core)
    target_link_libraries(Desktop PRIVATE Qt6::Widgets)
    target_link_libraries(Desktop PRIVATE Qt6::Gui)
    target_link_libraries(Desktop PRIVATE Core)
    set_target_properties(Desktop PROPERTIES
        ${BUNDLE_ID_OPTION}
        MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
        MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
        OUTPUT_NAME "Desktop boilerplate"
        MACOSX_BUNDLE TRUE
        WIN32_EXECUTABLE TRUE
    )
    include(GNUInstallDirs)
    install(TARGETS Desktop
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    qt_finalize_executable(Desktop)
    

    The exact error I get while compiling from the root level is:

    In file included from "[..]/lib/core.h:6"
    from "[..]/Desktop/blab.h:5"
    from "[..]/Desktop/main.cpp:1"
    [..]/lib/cookiejar.h:4:10": fatal error: QNetworkCookieJar: No such file or directory
    

    I can build the library itself just fine. I don't recall having such issues in the past.

    For more information please re-read.

    Kind Regards,
    Artur

    J 1 Reply Last reply 28 Jul 2023, 16:35
    0
    • J JoeCFD
      28 Jul 2023, 16:46

      @artwaw It looks like you may need include path of network module as well.

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 28 Jul 2023, 16:52 last edited by
      #5

      You have to link PUBLIC to the libraries which you're using in your headers (which should be used by others). Please see the CMake documentation.

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

      A 1 Reply Last reply 28 Jul 2023, 16:59
      2
      • A artwaw
        28 Jul 2023, 16:25

        Good afternoon,
        can someone clarify please:

        • I have a project composed (for now) of a library and desktop project
        • library uses network and sql, while desktop does not
          I can't compile target desktop because it complains about network classes, which are not a part of this project at all (library itself is).

        Root cmakelists:

        cmake_minimum_required(VERSION 3.5)
        
        project(
          boilerplate
          LANGUAGES CXX
          VERSION 0.1
          DESCRIPTION "boilerplate client")
        
        
        set(CMAKE_AUTOUIC ON)
        set(CMAKE_AUTOMOC ON)
        set(CMAKE_AUTORCC ON)
        
        set(CMAKE_CXX_STANDARD 17)
        set(CMAKE_CXX_STANDARD_REQUIRED ON)
        
        find_package(Qt6 REQUIRED COMPONENTS Core Widgets Gui LinguistTools)
        #above is used in both lib and the program
        qt_standard_project_setup()
        add_subdirectory(Core)
        add_subdirectory(Desktop)
        

        Library cmakelists:

        find_package(Qt6 REQUIRED COMPONENTS Network Sql)
        
        set(TS_FILES Core_en_GB.ts)
        
        qt_add_library(Core SHARED
          core.h   core.cpp
          ${TS_FILES}
          logger.h logger.cpp
          ipmodel.h ipmodel.cpp
          core.qrc
          cookiejar.h cookiejar.cpp
        )
        target_link_libraries(Core PRIVATE Qt6::Core)
        target_link_libraries(Core PRIVATE Qt6::Network)
        target_link_libraries(Core PRIVATE Qt6::Sql)
        target_link_libraries(Core PRIVATE Qt6::Gui)
        target_include_directories(Core INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
        target_compile_definitions(Core PRIVATE BLACORE_LIBRARY)
        qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
        

        Desktop cmakelists:

        set(TS_FILES Desktop_en_GB.ts)
        set(PROJECT_SOURCES
                main.cpp
                blab.h blab.cpp blab.ui
                ${TS_FILES}
        )
        qt_add_executable(Desktop
                MANUAL_FINALIZATION
                ${PROJECT_SOURCES}
                desktop.rc desktop.qrc
        )
        qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
        target_link_libraries(Desktop PRIVATE Qt6::Core)
        target_link_libraries(Desktop PRIVATE Qt6::Widgets)
        target_link_libraries(Desktop PRIVATE Qt6::Gui)
        target_link_libraries(Desktop PRIVATE Core)
        set_target_properties(Desktop PROPERTIES
            ${BUNDLE_ID_OPTION}
            MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
            MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
            OUTPUT_NAME "Desktop boilerplate"
            MACOSX_BUNDLE TRUE
            WIN32_EXECUTABLE TRUE
        )
        include(GNUInstallDirs)
        install(TARGETS Desktop
            BUNDLE DESTINATION .
            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
        )
        qt_finalize_executable(Desktop)
        

        The exact error I get while compiling from the root level is:

        In file included from "[..]/lib/core.h:6"
        from "[..]/Desktop/blab.h:5"
        from "[..]/Desktop/main.cpp:1"
        [..]/lib/cookiejar.h:4:10": fatal error: QNetworkCookieJar: No such file or directory
        

        I can build the library itself just fine. I don't recall having such issues in the past.

        J Offline
        J Offline
        JoeCFD
        wrote on 28 Jul 2023, 16:35 last edited by
        #2

        @artwaw did you add include path of your lib?

        A 1 Reply Last reply 28 Jul 2023, 16:39
        0
        • J JoeCFD
          28 Jul 2023, 16:35

          @artwaw did you add include path of your lib?

          A Offline
          A Offline
          artwaw
          wrote on 28 Jul 2023, 16:39 last edited by
          #3

          @JoeCFD In this project I followed what seems to be updated documentation from Qt, where they say the line in the lib's cmakelists target_include_directories(Core INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) is sufficient (certainly seems that way, core.h is found in Desktop target).

          source https://doc.qt.io/qt-6/cmake-get-started.html

          By calling target_include_directories, we make sure that the absolute path to the [library] directory is automatically added as an include path to all targets using our library.
          

          Should I scrap this and do the usual, pure cmake way?

          For more information please re-read.

          Kind Regards,
          Artur

          J 1 Reply Last reply 28 Jul 2023, 16:46
          0
          • A artwaw
            28 Jul 2023, 16:39

            @JoeCFD In this project I followed what seems to be updated documentation from Qt, where they say the line in the lib's cmakelists target_include_directories(Core INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) is sufficient (certainly seems that way, core.h is found in Desktop target).

            source https://doc.qt.io/qt-6/cmake-get-started.html

            By calling target_include_directories, we make sure that the absolute path to the [library] directory is automatically added as an include path to all targets using our library.
            

            Should I scrap this and do the usual, pure cmake way?

            J Offline
            J Offline
            JoeCFD
            wrote on 28 Jul 2023, 16:46 last edited by JoeCFD
            #4

            @artwaw It looks like you may need include path of network module as well.

            C 1 Reply Last reply 28 Jul 2023, 16:52
            0
            • J JoeCFD
              28 Jul 2023, 16:46

              @artwaw It looks like you may need include path of network module as well.

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 28 Jul 2023, 16:52 last edited by
              #5

              You have to link PUBLIC to the libraries which you're using in your headers (which should be used by others). Please see the CMake documentation.

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

              A 1 Reply Last reply 28 Jul 2023, 16:59
              2
              • C Christian Ehrlicher
                28 Jul 2023, 16:52

                You have to link PUBLIC to the libraries which you're using in your headers (which should be used by others). Please see the CMake documentation.

                A Offline
                A Offline
                artwaw
                wrote on 28 Jul 2023, 16:59 last edited by
                #6

                @Christian-Ehrlicher My bad. Thank you, it worked! I need to up my cmake game...

                For more information please re-read.

                Kind Regards,
                Artur

                1 Reply Last reply
                0
                • A artwaw has marked this topic as solved on 28 Jul 2023, 16:59

                1/6

                28 Jul 2023, 16:25

                • Login

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