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'.
-
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.