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. Add include directories from sub_directory to main application. How?
Forum Updated to NodeBB v4.3 + New Features

Add include directories from sub_directory to main application. How?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 320 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!

    My project have some libraries that defined with 'qt_add_library'. This libraries have some includes. How to automatically add library 'target_include_directories' to main application from this libraries CMakeLists.txt?

    Application (qt_add_executable)
    |-- Library 1 (qt_add_library)
    |-- Library 2 (qt_add_library)
    |-- Library ...

    Or is there option to declare global variable within required include directories?

    The global goal to make possible adding libraries just by using 'add_subdirectory'.

    1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @bogong said in Add include directories from sub_directory to main application. How?:

      What is 'correct'?

      See https://cmake.org/cmake/help/latest/command/target_include_directories.html on how to use target_include_directories() and properly set the include dirs for your libraries. Nothing more to do.

      B Offline
      B Offline
      bogong
      wrote last edited by
      #8

      @Christian-Ehrlicher Got finished some experiments. We both right.

      There are global issue for me - location of the libraries. All things that you writing is about 'common CMake way'. You writing about situation when all sources of all libraries located inside of the project. In my situation (by some reasons) libraries located outside of project tree. This is the main problem for me. On the CMake forum this trouble discussed by me and one of the moderators https://discourse.cmake.org/t/populate-include-directories-from-sub-directory-to-all-of-parts-of-the-project-how/14449/4

      Made it all clear for myself. Thx for assistance.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bogong
        wrote on last edited by bogong
        #2

        Totally got forgotten about CMake 'CACHE INTERNAL' parameter when setting variable:

        set(${LIB_PREFIX}_DIR_INCLUDES /dir1 /dir2 /dir3 CACHE INTERNAL "")
        

        And in the main application just add it to target includes:

        add_subdirectory(/Lib1 ${DIR_BUILD_LIBRARIES}/Library_1)
        add_subdirectory(/lib2 ${DIR_BUILD_LIBRARIES}/Library_2)
        
        ...
        
        target_include_directories(target
        	PRIVATE
        		${LIB1_PREFIX_DIR_INCLUDES}
        		${LIB2_PREFIX_DIR_INCLUDES}
        )
        
        1 Reply Last reply
        0
        • B bogong has marked this topic as solved on
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #3

          Use the correct target_include_directories() call for your library instead your hack.

          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
          0
          • Christian EhrlicherC Christian Ehrlicher

            Use the correct target_include_directories() call for your library instead your hack.

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

            @Christian-Ehrlicher What is correct call? Examples?

            Something like this:

            target_include_directories(target
            	PRIVATE
            		$<TARGET_PROPERTY:Library_1,INTERFACE_INCLUDE_DIRECTORIES>
            		$<TARGET_PROPERTY:Library_2,INTERFACE_INCLUDE_DIRECTORIES>
            )
            
            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #5

              Define the correct include dirs for you libraries with target_include_directories and simply link them to your executable. Then cmake is doing the rest for you automatically.

              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
              0
              • Christian EhrlicherC Christian Ehrlicher

                Define the correct include dirs for you libraries with target_include_directories and simply link them to your executable. Then cmake is doing the rest for you automatically.

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

                @Christian-Ehrlicher What is 'correct'?

                Christian EhrlicherC 1 Reply Last reply
                0
                • B bogong

                  @Christian-Ehrlicher What is 'correct'?

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @bogong said in Add include directories from sub_directory to main application. How?:

                  What is 'correct'?

                  See https://cmake.org/cmake/help/latest/command/target_include_directories.html on how to use target_include_directories() and properly set the include dirs for your libraries. Nothing more to do.

                  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 Add include directories from sub_directory to main application. How?:

                    What is 'correct'?

                    See https://cmake.org/cmake/help/latest/command/target_include_directories.html on how to use target_include_directories() and properly set the include dirs for your libraries. Nothing more to do.

                    B Offline
                    B Offline
                    bogong
                    wrote last edited by
                    #8

                    @Christian-Ehrlicher Got finished some experiments. We both right.

                    There are global issue for me - location of the libraries. All things that you writing is about 'common CMake way'. You writing about situation when all sources of all libraries located inside of the project. In my situation (by some reasons) libraries located outside of project tree. This is the main problem for me. On the CMake forum this trouble discussed by me and one of the moderators https://discourse.cmake.org/t/populate-include-directories-from-sub-directory-to-all-of-parts-of-the-project-how/14449/4

                    Made it all clear for myself. Thx for assistance.

                    1 Reply Last reply
                    0
                    • B bogong has marked this topic as solved
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote last edited by
                      #9

                      You never told us this. So you have to follow https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html

                      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

                        You never told us this. So you have to follow https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html

                        B Offline
                        B Offline
                        bogong
                        wrote last edited by
                        #10

                        @Christian-Ehrlicher There were my bad. Always been developing when libraries inside of project tree and never been facing any troubles. Never been thinking that 'library-in-tree' is there common way or even requirement for CMake. For now started optimising developing process and environment because of huge amount duplicated-triplicated sources and got troubles when moved sources outside of the project tree. For now made everything clear for myself.

                        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