I’ve been assigned to completely run a project using CMake.
Basically, the project has over 20 modules, and for each module i created a CMake file
such as:
# Module: CFS
file(
GLOB_RECURSE
files
*.c
*.cpp
)
include_directories("${PROJECT_SOURCE_DIR}/include/PEM/cfs")
include_directories("${PROJECT_SOURCE_DIR}/include/PEM/kernel2")
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
add_library(cfs ${files})
kernel2 is another module and has its own CMakeFile.
Now the problem is that a third module: m3 requires headers from cfs (which also require headers from kernel2)
So i basically go with:
# Module: m3
file( ... )
include_directories("${PROJECT_SOURCE_DIR}/include/PEM/cfs")
add_library(m3 ${files})
target_link_library(m3 cfs)
Unfortunately this is not enough, kernel2 included files won’t be found when i compile unless I add:
include_directories("${PROJECT_SOURCE_DIR}/include/PEM/kernel2")
Am I doing it wrong? Perhaps I should also add include files using add_library directive?
If you have
#includedirectives in cfs’s headers, then you should useIt’s not the problem of CMake, but how C/C++ compiler works.
For example, you have following header in cfs:
Now if you wish to instantiate
SomeCfsClassin your m3 module, the compiler should know it’s size. But knowing it’s size is not possible without knowningSomeKernelClassdefinition from kernel2/someclass.h.This situation can be resolved by storing not the object, but pointer to it inside
SomeCfsClass:But of course, there are cases, when it’s simply impossible to avoid including.
As an alternative, i can suggest to use relative paths in
#includedirectives, but this solution is somewhat hackish.