[cmake-developers] A type for static plugins?

Stephen Kelly steveire at gmail.com
Fri Sep 20 13:40:21 EDT 2013


Brad King wrote:

> On 09/20/2013 12:03 PM, Stephen Kelly wrote:
>>  if (my_lib_type STREQUAL SHARED)
>>    add_library(some_plugin MODULE main.cpp)
>>  else()
>>    add_library(some_plugin STATIC
>>      SOURCES main.cpp
>>      PROPERTIES
>>        STATICPLUGIN 1
>>         # If we need this anyway, we might as well move it upscope
>>         # and remove the CMAKE_SHARED_MODULE_PREFIX setting, replacing
>>         # it with
>>         #  set_property(TARGET some_plugin PROPERTY PREFIX "")
>>        PREFIX ""
>>      )
>>  endif()
> 
> That has to duplicate the list of sources, and the properties make
> the add_library call start to look pretty verbose anyways.

Yes, that was my thought too.

> Currently we can just do:
> 
>  set(plugin_type ...) # MODULE or STATIC
>  add_library(some_plugin ${plugin_type} main.cpp)
>  set_target_properties(some_plugin PROPERTIES PLUGIN "1" PREFIX "")
> 
> Can't this be packaged up in a qt_add_plugin() API?

Perhaps. 

macro(qt_add_plugin name type)
  if (${type} STREQUAL STATIC OR ${type} STREQUAL MODULE)
    set(_type ${type})
    set(args ${ARGN})
  else()
    set(_type MODULE)
    set(args ${type} ${ARGN}) 
  endif()
  add_library(${name} ${_type} ${ARGN})
  if (_type STREQUAL STATIC)
    set_target_properties(${name} PROPERTIES
      PLUGIN "1" 
      # Not sure if this is a Qt/KDE convention:
      PREFIX ""
    )
  endif()
endmacro()

A remaining question is whether the 'PLUGIN' target property should be a 
CMake built-in target property or a QT_ prefixed one?

Thanks,

Steve.





More information about the cmake-developers mailing list