2

In a cmake based project (C/C++), if there is a change done in a source file, I would like a means to dump list of affected targets (including transitive dependencies).

I am considering:

  1. Generate source to .o mapping => generate build files using -GNinja and parse the CMakeFiles/.dir/.o.d files
  2. Generate a parseable output of --graphviz option => no solution yet
  3. Figure out a way to handle dependencies added to custom targets using add_dependencies() => no solution yet

What is the best way to achieve this?

Gns
  • 364
  • 1
  • 4
  • 9
  • Maybe you can use a dry-run and extract the information from it? -n is the flag for Ninja and Make. – usr1234567 Apr 28 '18 at 21:01
  • Parsing make output would be a bit clunky. Its output varies depending on whether make has been run or not. Since cmake has the targets and dependcy information, I am hoping there is a cleaner cmake specific solution. – Gns Apr 30 '18 at 04:27
  • The query option of Ninja works well for my purpose, thanks. – Gns May 28 '18 at 23:26

1 Answers1

2

Supporting @usr1234567's comment, I'm using your first -G Ninja approach if I want to know the dependencies.

does have a lot of tool/debug options to support you:

> ninja -t query CMakeFiles\HelloWorld.dir\main.obj

CMakeFiles/HelloWorld.dir/main.obj:
  input: CXX_COMPILER__HelloWorld
    ../main.cpp
  outputs:
    HelloWorld.exe

Or the mentioned "dry run" with:

> ninja -d explain -n

A specific approach would be more complicated. For a starting point refer to "make dist" equivalent in CMake.

Florian
  • 39,996
  • 9
  • 133
  • 149