Pierluigi
Pierluigi

Reputation: 2294

How to setup a CMAKE imported target for plugin components?

I have a precompiled libary that also employes dynamically loaded plugins.

I am defining the imported target of L as:

add_library(L SHARED IMPORTED)
set_target_properties(L PROPERTIES
  IMPORTED_LOCATION_RELEASE library.dll
  IMPLIB_LOCATION_RELEASE library.lib
)

set_target_properties(L PROPERTIES 
  INTERFACE_LINK_LIBRARIES P
)

How do I define the imported target for P and its properties?

If I define it as:

add_library(P MODULE IMPORTED)
set_target_properties(P PROPERTIES 
  IMPORTED_LOCATION_RELEASE plugin.dll
)

Then the generated projects using L will erroneously consider plugin.dll as the lib to be linked. I would like instead to keep the dependency (so that I can transitively install plugin.dll) but avoid L to link target P

Upvotes: 1

Views: 320

Answers (1)

Pierluigi
Pierluigi

Reputation: 2294

I have ended up solving this by not linking L to P using INTERFACE_LINK_LIBRARIES.

I am configuring L by adding an additional variable containing its plugins:

LIST(APPEND L_PLUGINS P)

The targets using L can get access to its plugins by simply using the variable ${L_PLUGIN} (e.g. in order to install its files)

NB: This is the same approach used by Qt plugin components

Upvotes: 1

Related Questions