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
7 Posts 2 Posters 75 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 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
    • B Offline
      B Offline
      bogong
      wrote 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
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote 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 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 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 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 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

                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