Hello *,
I have a project where I am building one application and a bunch of (mostly shared) libraries; the application is set up with project(myapp C CXX)
and the libraries are set up with add_library(mod_plugin1 MODULE myplugin1.cpp)
or add_library(mod_plugin2 STATIC myplugin2.cpp)
. All of the libaries reside in subdirectories with their own CMakeLists.txt which are then included by add_subdirectory
.
There are several libraries and I do/will not know which of them are present as users may choose freely which ones to compile.
So far, this is all fine and works.
Today, it became clear that one specific, statically linked library (let’s call it “mod_utils”) is needed by some of the other libraries as well. So I added to the depending libraries (f.e. mod_plugin1):
target_link_libraries(mod_plugin1
mod_utils
)
This works, but I don’t have access to the libraries header files during compilation of mod_plugin1.
I didn’t find a good solution to that; currently there is a global variable set in the root CMakeLists.txt that holds the include path for mod_utils and add that variable to target_include_directories
:
target_include_system_directories(mod_plugin1
# ...
${mod_utils_inc_path}
)
This variable can’t be set in mod_utils’ CMakeListst.txt though, since I can not control the order or execution in CMake.
Since this solution does require a change of the main CMakeLists.txt: is there a better way to keep this modular? I looked into mod_plugin1_SOURCE_DIR
but that’s only available for projects, not for libraries.
Thanks
Sebastian