Including external libraries in a cmake project is usually performed using find_package()
.
But in a large multi-application / multi-library project, it is typical for some 3rd-party and/or system libraries to be used by multiple applications and libraries.
Where should find_package()
for these common libraries be called?
- In the
CMakeLists.txt
file for each executable/library that needs them? - Or, once in a top-level
CMakeLists.txt
file?
The first options seems to be a more modular approach, but the associated find_package()
scripts are executed for each library/executable that uses them. This can slow down the configuration step.
The second option is more efficient, but looks a bit too much like a global variable to me.
target_link_libraries(my_exe PUBLIC Boost::system)
– Spermicfind_package
for the same package usually takes a little time, because it does not search again but reuses cached results from the first invocation. So in case of per-directory invocation offind_package
perfomance needn't neccessary to be a problem. (But, as usual with performance, one should measure it before draw the conclusions.) – Cetus