aszswaz
aszswaz

Reputation: 637

How does cmake print the path of the header file of the library the project depends on?

I want cmake to output the path of the header file of the library that the project depends on, and give it to ctags to generate tags.

I have tried to generate tags of all header files of the system directly: ctags -R /usr/include, but the size of the generated tags file is 190MB, which is too large.

For example, if libcurl is used in the project, then let cmake output /usr/include/curl, and then ctags can ctags -R /usr/include/curl.

I looked at cmake --help, but didn't find what I was looking for. How can I achieve this?

Upvotes: 1

Views: 737

Answers (1)

KamilCuk
KamilCuk

Reputation: 140970

Generate compile_commands.json. Parse compile_commands.json, extract all "command": keys, extract all -I<this paths> include paths from compile commands, interpret them relative to build directory. sort -u the list.

$ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ...
$ jq -r '.[] | .command' "$builddir"/compile_commands.json |
     grep -o -- '-I[^ ]*' |
     sed 's/^-I//' |
     sort -u |
     ( cd "$builddir" && xargs -d '\n' readlink -f ) |
     sort -u

Upvotes: 3

Related Questions