boost_test.cpp:2:10: fatal error: boost/math/special_functions/round.hpp: No such file or directory
2 | #include <boost/math/special_functions/round.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
For some reason FetchContent_MakeAvailable did construct an almost working set of include directories, but for some reason did not add the math directories.
What did I misunderstood from FetchContent documentation ?
Seeing the code it seems you are correctly calling boost and the modules you want. In the target_link_libraries I think you miss to add Boost::math, you are linking just to filesystem and program_options.
That’s because in CMake targets carry their dependencies when linking. Boost::math is a target, so it carries the information about needed defines, location of the libraries, and needed include directories. Those pieces of information will be added to your target when using target_link_libraries
Thanks for the quick answer. Here is the documentation I am reading:
Each <item> may be:
A library target name: The generated link line will have the full path to the linkable library file associated with the target. The buildsystem will have a dependency to re-link <target> if the library file changes.
I’d love to give u a link, but I cannot find it either. It is one of the things that I have organically learned by using CMake and reading answers on SO, and MailingList.
If it’s written in the documentation in clear text, someone more familiar with the docu would have to point to it. Sorry.
None of this is really specific to FetchContent. Your queries would be the same if you simply downloaded Boost sources yourself or added Boost as a git submodule, then brought those sources into your build with add_subdirectory(). The same applies to any other project you might choose to absorb into your build.
So to directly answer your last question, the expected behavior is: if log4cpp is a target that is being defined by the sources you’re downloading and absorbing into your build, then it should work fine as long as that target correctly adds its usage requirements. It would usually do that using things like target_include_directories(), target_compile_definitions(), etc. If the build doesn’t work, I would be looking into the log4cpp project to see why. Not all projects expect to be absorbed into a larger parent build this way, so you can’t always use FetchContent, git submodules, etc. to bring every project into your own.
Excuse the brevity, I’m answering queries between other obligations.
I know it’s a old thread, but I want to share this knowledge anyway with the world.
The fastest way now to download boost is to download the artifact in compressed format, instead of cloning the git repository with FetchContent, see below:
@ClausKlein While Boost itself might not define install(...) rules for you, that doesn’t stop you adding your own install(...) commands for Boost targets in your own project. Starting with CMake 3.13, you can put install(TARGETS ...) commands in a different directory scope to the one that defines those targets.
CMake Error at CMakeLists.txt:100 (install):
install TARGETS given target "filesystem" which does not exist.
-- Configuring incomplete, errors occurred!