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. The CMake "include" vs "add_subdirectory" with Qt. Which is better?
Forum Updated to NodeBB v4.3 + New Features

The CMake "include" vs "add_subdirectory" with Qt. Which is better?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 4.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.
  • B Offline
    B Offline
    bogong
    wrote on last edited by bogong
    #1

    Hello all!
    For now redeveloping application and moving it from QMake to CMake. Got currious about which is better to use when Qt Application developing with CMake using "includes" or using "add_subdirectory"? Read a lot about this topic:

    • https://stackoverflow.com/questions/48509911/cmake-add-subdirectory-vs-include
    • https://cmake.org/pipermail/cmake/2007-November/017895.html
    • https://stackoverflow.com/questions/49984011/cmake-include-vs-add-subdirectory-relative-header-file-path
    • https://stackoverflow.com/questions/12761748/cmake-difference-between-include-directories-and-add-subdirectory
    • https://stackoverflow.com/questions/42744315/cmake-with-subdirectories

    But still not clear about it, especcially in case of using Qt. Got some troubles when attaching native languages in Qt project when using native in sub_directory project like sub-target (for example when using Swift with Qt for iOS) When Qt CMake created like all-in one and using only includes all is working perfectly with native languages. But include not always Ok with speed of building, using subtargets reducing this time and making whole project more maintainable.

    What is the pros and cons of both of this ways in CMake in case of using it with Qt? Suggestions?

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      include() and add_subdirectory() are imo two completely different things. Esp. since include is searching for a cmake file in it's path whereas add_subdirectory() explcitly add the subdirectory() and use the CMakeLists.txt in there.

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

      B 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        include() and add_subdirectory() are imo two completely different things. Esp. since include is searching for a cmake file in it's path whereas add_subdirectory() explcitly add the subdirectory() and use the CMakeLists.txt in there.

        B Offline
        B Offline
        bogong
        wrote on last edited by bogong
        #3

        @Christian-Ehrlicher Thx for reply. Know it. But both of it might be used in project architecture for Qt. Just asking which aproach is better in case of Qt with CMake. Is there any thoghts about it?

        Christian EhrlicherC 1 Reply Last reply
        0
        • B bogong

          @Christian-Ehrlicher Thx for reply. Know it. But both of it might be used in project architecture for Qt. Just asking which aproach is better in case of Qt with CMake. Is there any thoghts about it?

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by Christian Ehrlicher
          #4

          @bogong said in The CMake "include" vs "add_subdirectory" with Qt. Which is better?:

          Just asking which aproach is better in case of Qt with CMake.

          I already answered what's the difference so I don't understand the question... if you have a subdirectory to include, use add_subdirectory(), if you've a cmake module, use include(), doesn't matter if you compile Qt or not - Qt is just c++

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

          B 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            @bogong said in The CMake "include" vs "add_subdirectory" with Qt. Which is better?:

            Just asking which aproach is better in case of Qt with CMake.

            I already answered what's the difference so I don't understand the question... if you have a subdirectory to include, use add_subdirectory(), if you've a cmake module, use include(), doesn't matter if you compile Qt or not - Qt is just c++

            B Offline
            B Offline
            bogong
            wrote on last edited by
            #5

            @Christian-Ehrlicher Thx. Issue closed.

            1 Reply Last reply
            0

            • Login

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