Displaying a target's list of linked libraries in cmake

后端 未结 4 2105
谎友^
谎友^ 2021-02-02 13:38

Is there a way to print a list the filenames for the libraries linked into a target via the target_link_libraries command

or even better, have all a target\'s dependenci

4条回答
  •  生来不讨喜
    2021-02-02 14:14

    I realise this doesn't fully answer the question with regards doing it within cmake, but I faced a similar problem and thought I should share my solution.

    First, in your source directory ("project"):

    $ mkdir build && cd build
    $ cmake ..
    

    Then, use graphviz to create a dot file, as in this answer:

    $ cmake --graphviz=graph.dot .
    

    Then, strip out the dependencies from the graph for your target (let's call it "foo"):

    $ sed -n 's/.*label="\(.*\)"\s.*/\1/p' graph.dot.foo > foo_dependencies.txt
    

    Now, remove the clutter:

    $ rm graph.dot*
    

提交回复
热议问题