File API and imported targets

Hi everyone,

I would like to automatically list the dependencies of all of my project’s targets, including external dependencies.

Is there a way to get the file API to list IMPORTED targets?

Thank you,

Pablo

The cmake-file-api(7)'s codemodel v2 output does not include imported targets. It’s meant to correspond to the generated build system, and imported targets do not have build rules. However, link command line fragments are listed for each target and do include all libraries including external ones.

For human review of the dependency graph take a look at the cmake --graphviz=... option. CMake 3.17 will include improvements already in master from MR 3766.

@brad.king As I know, “link command line fragments are listed” only for shared libraries. If a static library has some imported targets as dependencies, this method doesn’t work.
Also, even always a dynamic library is build, it’s link information in the codemodel file is not enough, such as whether a fragment is static library or shared library is not sure, because the extension name is not reliable and at some extreme situation maybe a arbitrary name.
How about to add another field or something whatever to mark it an imported target, instead just throwing them away?
Maybe you know another approach which is reliable and precise?
Thank you,Brad.

@Yz_Chen the codemodel-v2 object is not meant for exposing full link dependencies like your question in CMake Issue 12435. It might provide enough information for some such use cases, but only by coincidence.

What are you actually trying to do?

@brad.king I have a big project to produce a static library. In the CMakeLists.txt files, many static libraries, which maybe third-party/internal static libraries, are the dependencies of the final static library. And these static libraries have interdependences, so a dependency graph exists. These dependencies may depend on certain feature options, so they are not always required.

The consumer need a static library file which contains all the static dependencies that are needed for the final link. So I need a method to find its static dependencies, and package them to a whole file for publish. How to get its dependencies by an accurate and elegant approach?

(I know that cmake-package maybe useful, but my consumer does’t want to use that for whatever some reason.)

I need a method to find its static dependencies, and package them to a whole file…my consumer does’t want to use [cmake-package]

Thanks. That’s pretty far outside the scope of “File API and imported targets”. Please start a new topic to describe that in more detail, and then link it from here.

Sad to hear about that. Though it seems a problem in this situation, maybe I need some more investigation before diving the specified problem.
cmake-package maybe the most suitable approach, at least from your view?