1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
# kf5designerplugin_generate_plugin(<sources_var> <widgetsfile>)
#
# Generates the necessary source code files for a Qt Designer widget plugin
# from the given ini-style description file, and adds them to <sources_var>.
# Note that plugins cannot be combined: you cannot add the generated code files
# from more than one widgets file into the same plugin.
#
# Usage:
#
# set(foo_SRCS otherfile.cpp)
# qt_add_resources(foo_SRCS widgeticons.qrc)
# kf5designerplugin_generate_plugin(foo_SRCS foo.widgets)
# add_library(foowidgets MODULE ${foo_SRCS})
#
#
# kf5designerplugin_add_plugin(<target> [OPTIONAL]
# <sourcefile> [<sourcefile> [...]])
#
# This behaves like add_library() (with the MODULE argument), except that if
# one of the source files has the extension ".widgets", kgendesignerplugin will
# be used to generate Qt Designer plugin source files from it. Additionally,
# any source files with the extension ".qrc" will be dealt with appropriately
# as well.
#
# The OPTIONAL argument specifies that if Qt Designer was not found, the macro
# should just not create the target instead of causing an error. You should
# then use "if(TARGET <target>)" to wrap anything that makes use of the target.
#
# The usage example for kf5designerplugin_generate_plugin can be replaced with
#
# kf5designerplugin_add_plugin(foowidgets
# foo.widgets otherfile.cpp widgeticons.qrc)
#
# but you still need to link against the appropriate libraries (the ones that
# provide the widgets described in the plugin) and install the plugin to the
# "designer" subdirectory of a directory Qt will look in for plugins (see
# QPluginLoader).
#
# Note that only one .widgets file can be provided to each call to
# kf5designerplugin_add_plugin.
# Copyright (c) 2006-2009 Alexander Neundorf, <neundorf@kde.org>
# Copyright (c) 2006, 2007, Laurent Montel, <montel@kde.org>
# Copyright (c) 2007 Matthias Kretz <kretz@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
function(kf5designerplugin_generate_plugin outvar widgetfile)
get_filename_component(input ${widgetfile} ABSOLUTE)
get_filename_component(basename ${input} NAME_WE)
set(source ${CMAKE_CURRENT_BINARY_DIR}/${basename}widgets.cpp)
# create source file from the .widgets file
add_custom_command(OUTPUT ${source}
COMMAND KF5::kgendesignerplugin
ARGS -o ${source} ${input}
MAIN_DEPENDENCY ${input})
# create moc file
set(moc ${CMAKE_CURRENT_BINARY_DIR}/${basename}widgets.moc)
qt_generate_moc(${source} ${moc} ${ARGN})
set(${outvar} ${${outvar}} "${source}" "${moc}" PARENT_SCOPE)
endfunction()
# This needs to be a macro because of the nested find_package call
# (which will set some variables).
macro(kf5designerplugin_add_plugin target)
set(_requiredarg REQUIRED)
set(_files)
foreach(f ${ARGN})
if(f MATCHES "\\.widgets$")
kf5designerplugin_generate_plugin(_files "${f}" TARGET "${target}")
elseif(f MATCHES "\\.qrc$")
qt_add_resources(_files "${f}")
elseif(f MATCHES "OPTIONAL")
set(_requiredarg)
else()
list(APPEND _files "${f}")
endif()
endforeach()
if(NOT TARGET Qt${QT_MAJOR_VERSION}::Designer)
find_package(Qt${QT_MAJOR_VERSION}Designer ${REQUIRED_QT_VERSION} ${_requiredarg} NO_MODULE)
set_package_properties(Qt${QT_MAJOR_VERSION}Designer PROPERTIES
PURPOSE "Required to build Qt Designer plugins"
)
endif()
if(NOT Qt5Designer_VERSION_STRING VERSION_LESS 5.5.0 AND NOT Qt5UiPlugin_FOUND AND NOT CMAKE_VERSION VERSION_LESS 3.0.0)
find_package(Qt${QT_MAJOR_VERSION}UiPlugin ${REQUIRED_QT_VERSION} ${_requiredarg} NO_MODULE)
set_package_properties(Qt${QT_MAJOR_VERSION}UiPlugin PROPERTIES
PURPOSE "Required to build Qt Designer plugins"
)
endif()
if (TARGET Qt${QT_MAJOR_VERSION}::UiPlugin)
# for some reason, Qt5UiPlugin does not set its _INCLUDE_DIRS variable. Fill it manually
get_target_property(Qt${QT_MAJOR_VERSION}UiPlugin_INCLUDE_DIRS Qt${QT_MAJOR_VERSION}::UiPlugin INTERFACE_INCLUDE_DIRECTORIES)
endif()
if(TARGET Qt${QT_MAJOR_VERSION}::Designer)
add_library(${target} MODULE ${_files})
target_include_directories(${target}
PRIVATE ${Qt5UiPlugin_INCLUDE_DIRS}
PRIVATE ${Qt5Designer_INCLUDE_DIRS}
)
endif()
endmacro()
|