Add include directories from sub_directory to main application. How?
-
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'.
-
@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.
@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.
-
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} )
-
-
Use the correct target_include_directories() call for your library instead your hack.
-
Use the correct target_include_directories() call for your library instead your hack.
@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> )
-
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.
-
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.
@Christian-Ehrlicher What is 'correct'?
-
@Christian-Ehrlicher What is 'correct'?
@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.
-
@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.
@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.
-
-
You never told us this. So you have to follow https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html
-
You never told us this. So you have to follow https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html
@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.