2

I am trying to build a sub C project that refers to multiple headers recursively from another project, which also contains unused headers. Instead of including all the unwanted header files in target_include_directories. I want to include only the required headers.

Note: The C project's CMake Build is not 100% through. I am facing errors in few headers.

I want those intermediate build files i.e. list of header files consumed by the C sources.

Is there is anyway to obtain the list?

Related Question with GCC list of all header files included by a C file

  • 1
    Hardly CMake could directly help you in obtaining the list of used header files. If you build your project with `make`, then you could run compilation process with `V=1` option (e.g. `make V=1`). That way whenever compiler is being invoked for compile source files, exact command line will be printed. If that command line already contains `-M` option, then you could find the headers in the corresponding file. If `-M` is absent in the command line, then you could **manually** run that command line with `-M` option added. – Tsyvarev Nov 29 '21 at 13:08
  • @Tsyvarev Yes its possible -M with gcc. `gcc -M`. But I am expecting a way with CMake. – honeybee1881 Nov 29 '21 at 14:07
  • I really don't understand what you are asking for. Could you try clarifying the question? –  Nov 29 '21 at 15:22
  • 2
    @buildSystemPerson The question is when you build a C project with CMake. How did you find out the included headers while compilation? – honeybee1881 Nov 30 '21 at 04:44

0 Answers0