[CMake] Handling library dependencies and minimizing duplicated include_directories

Daniel Lidström daniel.lidstrom at sbg.se
Sat Mar 20 08:16:31 EDT 2010


Hello,

I am just starting to get familiar with CMake. We are currently using Boost.Build,
so I am of course used to the behaviour of Boost.Build. One of the things I am now
trying to do with CMake is to set library usage requirements. For example, with
Boost.Build I can specify the include/ directory as a usage requirement of a library.
So when I then have this library as a dependency of another library I don't have to
specify the include directory. With CMake I am seeing myself writing include_directories
in a lot of places. Here's my attempt (parts copied from my CMakeLists):

project(UMC3D)

# here's a library of my own that I want to use
# in order to use this library from another library
# you must add the directory GFL/include to your include_directories
add_library(GFL SHARED
 ${DataIO_src}
)

# so here's a library which uses GFL
add_library(Device SHARED
 ${Device_src}
)
include_directories(
 ${UMC3D_SOURCE_DIR}/GFL
)
target_link_libraries(Device
 GFL
)

# and here's an executable that also uses GFL
add_executable(GFL.Test
 ${Test_src}
)
include_directories(
 ${UMC3D_SOURCE_DIR}/GFL
)
target_link_libraries(GFL.Test
 GFL
)


The way I see it is that this is not scalable. If I need to change GFL, for example
move the headers to another directory, I would then need to update both Device and GFL.Test.
This is not necessary with out-of-the-box Boost.Build where GFL can specify usage requirements.
Is there a similar solution with CMake? Hopefully I am being clear, please let me know otherwise.
Any help is much appreciated!

Thanks in advance.

Regards,

Daniel Lidström
Stockholm, Sweden 


More information about the CMake mailing list