Assume you wrote a library. Or you inherited one and want to install it or make an installable package.
What include directories (or files) do you actually need to export for a given c++ library project?
In general there are headers that are meant to be included. Others are only used internally. But the first set of headers usually includes other headers, often from dependencies of the library. Which in turn may include other headers.
To find out which headers are visible (and thus required) for the depender (the user of the library) you can do the following.
grep -o '"/.*"' preprocessed.cpp|sort -u
. You can adapt the regexp to filter out only those in your project by including the path to the project, e.g. grep -o '"/home/youruser/yourprojectfolder.*"' preprocessed.cpp|sort -u
If you are using cmake as a build system, it assembles the command line for your compiler for you, so often one doesn’t know how to compile “by hand”.
I usually get the compiler command from compile_commands.json, change -c to -E and execute it. To get that file set the variable CMAKE_EXPORT_COMPILE_COMMANDS to ON either in CMakeLists.txt:
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
or via the command line:
cmake (...) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
You can probably (I didn’t test it) also just set the -E option via add_compiler_options(yourtarget PRIVATE -E)
.