[CMake] How to figure out the "type" of an imported library

Attila Krasznahorkay attila.krasznahorkay at gmail.com
Thu Oct 29 11:53:32 EDT 2015


Dear All,

In my code I'm trying to do something slightly tricky. I include packages that provide imported libraries (amongst other things). Then, because of how my project is structured, I don't make use of the imported libraries directly, but first make "copies" of them, and then make use of these copies in my build.

(The reason is that I allow the project to override libraries that are available from the base packages as well. In which case components using this overridden library need to use this instance instead of the imported one. But if no such override is in place, I need to give the library a name that the components in the project expect to find it with.)

If there would be a way in CMake to "clone" an imported library with a new name, that would be perfect for my use case. Since as far as I know there's no such thing, I use code like:

      ...
      add_library( ${libName} SHARED IMPORTED GLOBAL )
      # Check which builds it is available for:
      get_property( _builds TARGET ${prefix}_${libName}
         PROPERTY IMPORTED_CONFIGURATIONS )
      set_property( TARGET ${libName} PROPERTY
         IMPORTED_CONFIGURATIONS ${_builds} )
      ...

Now, I recently started producing MODULE and INTERFACE libraries as well. So the first line in this code is no longer correct for all the imported libraries. Plus, for INTERFACE libraries the get_property call on IMPORTED_CONFIGURATIONS just fails with an error message.

So now I wonder: Is there a target property on INTERFACE libraries that I could use to identify them? Like how there is the target property IMPORTED on the imported libraries.

Cheers,
            Attila


More information about the CMake mailing list