Warning, /frameworks/kdesignerplugin/KF5DesignerPluginMacros.cmake is written in an unsupported language. File is not indexed.

0001 # kf5designerplugin_generate_plugin(<sources_var> <widgetsfile>)
0002 #
0003 # Generates the necessary source code files for a Qt Designer widget plugin
0004 # from the given ini-style description file, and adds them to <sources_var>.
0005 # Note that plugins cannot be combined: you cannot add the generated code files
0006 # from more than one widgets file into the same plugin.
0007 #
0008 # Usage:
0009 #
0010 #   set(foo_SRCS otherfile.cpp)
0011 #   qt_add_resources(foo_SRCS widgeticons.qrc)
0012 #   kf5designerplugin_generate_plugin(foo_SRCS foo.widgets)
0013 #   add_library(foowidgets MODULE ${foo_SRCS})
0014 #
0015 #
0016 # kf5designerplugin_add_plugin(<target> [OPTIONAL]
0017 #                              <sourcefile> [<sourcefile> [...]])
0018 #
0019 # This behaves like add_library() (with the MODULE argument), except that if
0020 # one of the source files has the extension ".widgets", kgendesignerplugin will
0021 # be used to generate Qt Designer plugin source files from it. Additionally,
0022 # any source files with the extension ".qrc" will be dealt with appropriately
0023 # as well.
0024 #
0025 # The OPTIONAL argument specifies that if Qt Designer was not found, the macro
0026 # should just not create the target instead of causing an error. You should
0027 # then use "if(TARGET <target>)" to wrap anything that makes use of the target.
0028 #
0029 # The usage example for kf5designerplugin_generate_plugin can be replaced with
0030 #
0031 #   kf5designerplugin_add_plugin(foowidgets
0032 #       foo.widgets otherfile.cpp widgeticons.qrc)
0033 #
0034 # but you still need to link against the appropriate libraries (the ones that
0035 # provide the widgets described in the plugin) and install the plugin to the
0036 # "designer" subdirectory of a directory Qt will look in for plugins (see
0037 # QPluginLoader).
0038 #
0039 # Note that only one .widgets file can be provided to each call to
0040 # kf5designerplugin_add_plugin.
0041 
0042 # Copyright (c) 2006-2009 Alexander Neundorf, <neundorf@kde.org>
0043 # Copyright (c) 2006, 2007, Laurent Montel, <montel@kde.org>
0044 # Copyright (c) 2007 Matthias Kretz <kretz@kde.org>
0045 #
0046 # Redistribution and use is allowed according to the terms of the BSD license.
0047 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
0048 
0049 function(kf5designerplugin_generate_plugin outvar widgetfile)
0050     get_filename_component(input ${widgetfile} ABSOLUTE)
0051     get_filename_component(basename ${input} NAME_WE)
0052     set(source ${CMAKE_CURRENT_BINARY_DIR}/${basename}widgets.cpp)
0053 
0054     # create source file from the .widgets file
0055     add_custom_command(OUTPUT ${source}
0056         COMMAND KF5::kgendesignerplugin
0057         ARGS -o ${source} ${input}
0058         MAIN_DEPENDENCY ${input})
0059 
0060     # create moc file
0061     set(moc ${CMAKE_CURRENT_BINARY_DIR}/${basename}widgets.moc)
0062     qt_generate_moc(${source} ${moc} ${ARGN})
0063 
0064     set(${outvar} ${${outvar}} "${source}" "${moc}" PARENT_SCOPE)
0065 endfunction()
0066 
0067 # This needs to be a macro because of the nested find_package call
0068 # (which will set some variables).
0069 macro(kf5designerplugin_add_plugin target)
0070     set(_requiredarg REQUIRED)
0071     set(_files)
0072     foreach(f ${ARGN})
0073         if(f MATCHES "\\.widgets$")
0074             kf5designerplugin_generate_plugin(_files "${f}" TARGET "${target}")
0075         elseif(f MATCHES "\\.qrc$")
0076             qt_add_resources(_files "${f}")
0077         elseif(f MATCHES "OPTIONAL")
0078             set(_requiredarg)
0079         else()
0080             list(APPEND _files "${f}")
0081         endif()
0082     endforeach()
0083 
0084     if(NOT TARGET Qt${QT_MAJOR_VERSION}::Designer)
0085         find_package(Qt${QT_MAJOR_VERSION}Designer ${REQUIRED_QT_VERSION} ${_requiredarg} NO_MODULE)
0086         set_package_properties(Qt${QT_MAJOR_VERSION}Designer PROPERTIES
0087             PURPOSE "Required to build Qt Designer plugins"
0088         )
0089     endif()
0090     if(NOT Qt5Designer_VERSION_STRING VERSION_LESS 5.5.0 AND NOT Qt5UiPlugin_FOUND AND NOT CMAKE_VERSION VERSION_LESS 3.0.0)
0091         find_package(Qt${QT_MAJOR_VERSION}UiPlugin ${REQUIRED_QT_VERSION} ${_requiredarg} NO_MODULE)
0092         set_package_properties(Qt${QT_MAJOR_VERSION}UiPlugin PROPERTIES
0093             PURPOSE "Required to build Qt Designer plugins"
0094         )
0095     endif()
0096     if (TARGET Qt${QT_MAJOR_VERSION}::UiPlugin)
0097         # for some reason, Qt5UiPlugin does not set its _INCLUDE_DIRS variable. Fill it manually
0098         get_target_property(Qt${QT_MAJOR_VERSION}UiPlugin_INCLUDE_DIRS Qt${QT_MAJOR_VERSION}::UiPlugin INTERFACE_INCLUDE_DIRECTORIES)
0099     endif()
0100     if(TARGET Qt${QT_MAJOR_VERSION}::Designer)
0101         add_library(${target} MODULE ${_files})
0102         target_include_directories(${target}
0103              PRIVATE ${Qt5UiPlugin_INCLUDE_DIRS}
0104              PRIVATE ${Qt5Designer_INCLUDE_DIRS}
0105         )
0106     endif()
0107 endmacro()
0108