Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkFunctionCreatePlugin.cmake
Go to the documentation of this file.
1 
2 #! \brief Creates a MITK CTK plugin.
3 #!
4 #! This function should be called from the plugins CMakeLists.txt file.
5 #! The target name is available after the macro call as ${PLUGIN_TARGET}
6 #! to add additional libraries in your CMakeLists.txt. Include paths and link
7 #! libraries are set depending on the value of the Required-Plugins header
8 #! in your manifest_headers.cmake file.
9 #!
10 #! This function internally calls ctkMacroBuildPlugin() and adds support
11 #! for Qt Help files and installers.
12 #!
13 #! Options:
14 #! \param TEST_PLUGIN Mark this plug-in as a testing plug-in.
15 #! \param NO_INSTALL Don't install this plug-in.
16 #!
17 #! Parameters:
18 #!
19 #! \param EXPORT_DIRECTIVE (required) The export directive to use in the generated
20 #! <plugin_target>_Exports.h file.
21 #!
22 #! Multi-value parameters (all optional):
23 #!
24 #! \param EXPORTED_INCLUDE_SUFFIXES A list of sub-directories which should
25 #! be added to the current source directory. The resulting directories
26 #! will be available in the set of include directories of depending plug-ins.
27 #! \param MODULE_DEPENDS (optional) A list of Modules this plug-in depends on.
28 #! \param PACKAGE_DEPENDS (optional) A list of external packages this plug-in depends on.
29 #! \param DOXYGEN_TAGFILES (optional) Which external tag files should be available for the plugin documentation
30 #! \param MOC_OPTIONS (optional) Additional options to pass to the Qt MOC compiler
31 function(mitk_create_plugin)
32 
33  # options
34  set(arg_options
35  TEST_PLUGIN # Mark this plug-in as a testing plug-in
36  NO_INSTALL # Don't install this plug-in
37  NO_QHP_TRANSFORM
38  )
39 
40  # single value arguments
41  set(arg_single
42  EXPORT_DIRECTIVE # (required) TODO: could be generated via CMake as it is done for MITK modules already
43  )
44 
45  # multiple value arguments
46  set(arg_multiple
47  EXPORTED_INCLUDE_SUFFIXES # (optional) additional public include directories
48  MODULE_DEPENDS # (optional)
49  PACKAGE_DEPENDS
50  DOXYGEN_TAGFILES
51  MOC_OPTIONS
52  SUBPROJECTS
53  )
54 
55  cmake_parse_arguments(_PLUGIN "${arg_options}" "${arg_single}" "${arg_multiple}" ${ARGN})
56 
57  if(_PLUGIN_TEST_PLUGIN)
58  set(_PLUGIN_NO_INSTALL 1)
59  set(is_test_plugin "TEST_PLUGIN")
60  else()
61  set(is_test_plugin)
62  endif()
63 
64  set(_PLUGIN_MOC_OPTIONS "-DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED ${_PLUGIN_MOC_OPTIONS}")
65 
66  set(PLUGIN_TARGET ${PROJECT_NAME})
67 
68  mitk_check_module_dependencies(MODULES ${_PLUGIN_MODULE_DEPENDS}
69  PACKAGES ${_PLUGIN_PACKAGE_DEPENDS}
70  MISSING_DEPENDENCIES_VAR _missing_deps
71  MODULE_DEPENDENCIES_VAR _module_deps
72  PACKAGE_DEPENDENCIES_VAR _package_deps)
73 
74  if(_missing_deps)
75  if(NOT MITK_BUILD_ALL_PLUGINS)
76  message(SEND_ERROR "${PROJECT_NAME} is missing requirements and won't be built. Missing: ${_missing_deps}")
77  else()
78  message(STATUS "${PROJECT_NAME} is missing requirements and won't be built. Missing: ${_missing_deps}")
79  endif()
80  return()
81  endif()
82 
83  # -------------- All dependencies are resolved ------------------
84 
85  message(STATUS "Creating CTK plugin ${PROJECT_NAME}")
86 
87  include(files.cmake)
88 
89  set(_PLUGIN_CPP_FILES ${CPP_FILES})
90  set(_PLUGIN_MOC_H_FILES ${MOC_H_FILES})
91  set(_PLUGIN_UI_FILES ${UI_FILES})
92  set(_PLUGIN_CACHED_RESOURCE_FILES ${CACHED_RESOURCE_FILES})
93  set(_PLUGIN_TRANSLATION_FILES ${TRANSLATION_FILES})
94  set(_PLUGIN_QRC_FILES ${QRC_FILES})
95  set(_PLUGIN_H_FILES ${H_FILES})
96  set(_PLUGIN_TXX_FILES ${TXX_FILES})
97  set(_PLUGIN_DOX_FILES ${DOX_FILES})
98  set(_PLUGIN_CMAKE_FILES ${CMAKE_FILES} files.cmake)
99  set(_PLUGIN_FILE_DEPENDENCIES ${FILE_DEPENDENCIES})
100 
101  if(CTK_PLUGINS_OUTPUT_DIR)
102  set(_output_dir "${CTK_PLUGINS_OUTPUT_DIR}")
103  else()
104  set(_output_dir "")
105  endif()
106 
107  # Compute the plugin dependencies
108  ctkFunctionGetTargetLibraries(_PLUGIN_target_libraries "")
109 
110  #------------------------------------------------------------#
111  #------------------ Qt Help support -------------------------#
112 
113  set(PLUGIN_GENERATED_QCH_FILES )
114  if(BLUEBERRY_USE_QT_HELP AND
115  EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/documentation/UserManual")
116  set(PLUGIN_DOXYGEN_INPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/documentation/UserManual")
117  set(PLUGIN_DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/documentation/UserManual")
118 
119  # Create a list of Doxygen tag files from the plug-in dependencies
120  set(PLUGIN_DOXYGEN_TAGFILES)
121  foreach(_dep_target ${_PLUGIN_target_libraries})
122  string(REPLACE _ . _dep ${_dep_target})
123 
124  get_target_property(_is_imported ${_dep_target} IMPORTED)
125  if(_is_imported)
126  get_target_property(_import_loc_debug ${_dep_target} IMPORTED_LOCATION_DEBUG)
127  get_target_property(_import_loc_release ${_dep_target} IMPORTED_LOCATION_RELEASE)
128  # There is not necessarily a debug and release build
129  if(_import_loc_release)
130  set(_import_loc ${_import_loc_release})
131  else()
132  set(_import_loc ${_import_loc_debug})
133  endif()
134  get_filename_component(_target_filename "${_import_loc}" NAME)
135  # on windows there might be a Debug or Release subdirectory
136  string(REGEX REPLACE "/bin/plugins/(Debug/|Release/)?${_target_filename}" "/Plugins/${_dep}/documentation/UserManual" plugin_tag_dir "${_import_loc}" )
137  else()
138  set(plugin_tag_dir "${CMAKE_BINARY_DIR}/Plugins/${_dep}/documentation/UserManual")
139  endif()
140 
141  set(_tag_file "${plugin_tag_dir}/${_dep_target}.tag")
142  if(EXISTS ${_tag_file})
143  set(PLUGIN_DOXYGEN_TAGFILES "${PLUGIN_DOXYGEN_TAGFILES} \"${_tag_file}=qthelp://${_dep}/bundle/\"")
144  endif()
145  endforeach()
146  if(_PLUGIN_DOXYGEN_TAGFILES)
147  set(PLUGIN_DOXYGEN_TAGFILES "${PLUGIN_DOXYGEN_TAGFILES} ${_PLUGIN_DOXYGEN_TAGFILES}")
148  endif()
149  #message("PLUGIN_DOXYGEN_TAGFILES: ${PLUGIN_DOXYGEN_TAGFILES}")
150 
151  if(_PLUGIN_NO_QHP_TRANSFORM)
152  set(_use_qhp_xsl 0)
153  else()
154  set(_use_qhp_xsl 1)
155  endif()
156  _FUNCTION_CREATE_CTK_QT_COMPRESSED_HELP(PLUGIN_GENERATED_QCH_FILES ${_use_qhp_xsl})
157  list(APPEND _PLUGIN_CACHED_RESOURCE_FILES ${PLUGIN_GENERATED_QCH_FILES})
158  endif()
159 
160  #------------------------------------------------------------#
161  #------------------ Create Plug-in --------------------------#
162 
163  mitkFunctionOrganizeSources(
164  SOURCE ${_PLUGIN_CPP_FILES}
165  HEADER ${_PLUGIN_H_FILES}
166  TXX ${_PLUGIN_TXX_FILES}
167  DOC ${_PLUGIN_DOX_FILES}
168  UI ${_PLUGIN_UI_FILES}
169  QRC ${_PLUGIN_QRC_FILES} ${_PLUGIN_CACHED_RESOURCE_FILES}
170  META ${_PLUGIN_META_FILES}
171  MOC ${MY_MOC_CPP}
172  GEN_UI ${MY_UI_CPP}
173  GEN_QRC ${MY_QRC_SRCS}
174  )
175 
176  ctkMacroBuildPlugin(
177  NAME ${PLUGIN_TARGET}
178  EXPORT_DIRECTIVE ${_PLUGIN_EXPORT_DIRECTIVE}
179  SRCS ${_PLUGIN_CPP_FILES} ${_PLUGIN_H_FILES} ${CORRESPONDING__H_FILES} ${GLOBBED__H_FILES}
180  MOC_SRCS ${_PLUGIN_MOC_H_FILES}
181  MOC_OPTIONS ${_PLUGIN_MOC_OPTIONS}
182  UI_FORMS ${_PLUGIN_UI_FILES}
183  EXPORTED_INCLUDE_SUFFIXES ${_PLUGIN_EXPORTED_INCLUDE_SUFFIXES}
184  RESOURCES ${_PLUGIN_QRC_FILES}
185  TARGET_LIBRARIES ${_PLUGIN_target_libraries}
186  CACHED_RESOURCEFILES ${_PLUGIN_CACHED_RESOURCE_FILES}
187  TRANSLATIONS ${_PLUGIN_TRANSLATION_FILES}
188  OUTPUT_DIR ${_output_dir}
189  NO_INSTALL # we install the plug-in ourselves
190  ${is_test_plugin}
191  )
192 
193  mitk_use_modules(TARGET ${PLUGIN_TARGET}
194  MODULES ${_PLUGIN_MODULE_DEPENDS}
195  PACKAGES ${_PLUGIN_PACKAGE_DEPENDS}
196  )
197 
198  set_property(TARGET ${PLUGIN_TARGET} APPEND PROPERTY COMPILE_DEFINITIONS US_MODULE_NAME=${PLUGIN_TARGET})
199  set_property(TARGET ${PLUGIN_TARGET} PROPERTY US_MODULE_NAME ${PLUGIN_TARGET})
200 
201  if(MITK_DEFAULT_SUBPROJECTS AND NOT MY_SUBPROJECTS)
202  set(MY_SUBPROJECTS ${MITK_DEFAULT_SUBPROJECTS})
203  endif()
204 
205  if(MY_SUBPROJECTS)
206  set_property(TARGET ${PLUGIN_TARGET} PROPERTY LABELS ${MY_SUBPROJECTS})
207  foreach(subproject ${MY_SUBPROJECTS})
208  add_dependencies(${subproject} ${PLUGIN_TARGET})
209  endforeach()
210  endif()
211 
212  if(_PLUGIN_TEST_PLUGIN)
213  find_package(CppUnit REQUIRED)
214  target_include_directories(${PLUGIN_TARGET} PRIVATE ${CppUnit_INCLUDE_DIRS})
215  target_link_libraries(${PLUGIN_TARGET} PRIVATE ${CppUnit_LIBRARIES})
216  endif()
217 
218  if(mbilog_FOUND)
219  target_link_libraries(${PLUGIN_TARGET} PRIVATE mbilog)
220  endif()
221 
222  set(_PLUGIN_META_FILES "${CMAKE_CURRENT_SOURCE_DIR}/manifest_headers.cmake")
223  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/plugin.xml")
224  list(APPEND _PLUGIN_META_FILES "${CMAKE_CURRENT_SOURCE_DIR}/plugin.xml")
225  endif()
226 
227  set(PLUGIN_TARGET ${PLUGIN_TARGET} PARENT_SCOPE)
228 
229  #------------------------------------------------------------#
230  #------------------ Installer support -----------------------#
231  if(NOT _PLUGIN_NO_INSTALL)
232  set(install_directories "")
233  if(NOT MACOSX_BUNDLE_NAMES)
234  set(install_directories bin/plugins)
235  else(NOT MACOSX_BUNDLE_NAMES)
236  foreach(bundle_name ${MACOSX_BUNDLE_NAMES})
237  list(APPEND install_directories ${bundle_name}.app/Contents/MacOS/plugins)
238  endforeach(bundle_name)
239  endif(NOT MACOSX_BUNDLE_NAMES)
240 
241  foreach(install_subdir ${install_directories})
242 
243  mitkFunctionInstallCTKPlugin(TARGETS ${PLUGIN_TARGET}
244  DESTINATION ${install_subdir})
245 
246  endforeach()
247 
248  set(_autoload_targets )
249  foreach(_dependency ${_module_deps})
250  get_target_property(_dep_autoloads ${_dependency} MITK_AUTOLOAD_TARGETS)
251  if (_dep_autoloads)
252  list(APPEND _autoload_targets ${_dep_autoloads})
253  endif()
254  endforeach()
255 
256  # The MITK_AUTOLOAD_TARGETS property is used in the mitkFunctionInstallAutoLoadModules
257  # macro which expects a list of plug-in targets.
258  if (_autoload_targets)
259  list(REMOVE_DUPLICATES _autoload_targets)
260  set_target_properties(${PLUGIN_TARGET} PROPERTIES MITK_AUTOLOAD_TARGETS "${_autoload_targets}")
261  endif()
262  endif()
263 
264 endfunction()
265 
266 
267 function(_FUNCTION_CREATE_CTK_QT_COMPRESSED_HELP qch_file use_xsl)
268 
269  set(_manifest_path "${CMAKE_CURRENT_SOURCE_DIR}/manifest_headers.cmake")
270  if(NOT EXISTS ${_manifest_path})
271  message(FATAL_ERROR "${_manifest_path} not found")
272  endif()
273 
274  include(${_manifest_path})
275  string(REPLACE "_" "." Plugin-SymbolicName "${PLUGIN_TARGET}")
276 
277  configure_file(${MITK_SOURCE_DIR}/Documentation/doxygen_plugin_manual.conf.in
278  ${PLUGIN_DOXYGEN_OUTPUT_DIR}/doxygen.conf
279  )
280 
281  set(_qhp_xsl_file "${MITK_SOURCE_DIR}/Documentation/qhp_toc.xsl")
282  set(_generated_qhp_file "${PLUGIN_DOXYGEN_OUTPUT_DIR}/html/index.qhp")
283  set(_transformed_qhp_file "${PLUGIN_DOXYGEN_OUTPUT_DIR}/html/${PLUGIN_TARGET}.qhp")
284  set(${qch_file} "${CMAKE_CURRENT_BINARY_DIR}/resources/${PLUGIN_TARGET}.qch")
285 
286  set(_xsl_command )
287  if(use_xsl)
288  set(_xsl_command COMMAND ${QT_XMLPATTERNS_EXECUTABLE} ${_qhp_xsl_file} ${_generated_qhp_file} -output ${_transformed_qhp_file})
289  endif()
290 
291  file(GLOB _file_dependencies "${PLUGIN_DOXYGEN_INPUT_DIR}/*")
292 
293  add_custom_command(OUTPUT ${${qch_file}}
294  # Generate a Qt help project (index.qhp) with doxygen
295  COMMAND ${DOXYGEN_EXECUTABLE} ${PLUGIN_DOXYGEN_OUTPUT_DIR}/doxygen.conf
296  # Use a XSL transformation to get rid of the top-level entry
297  ${_xsl_command}
298  # Generate the final Qt compressed help file (.qch)
299  COMMAND ${QT_HELPGENERATOR_EXECUTABLE} ${_transformed_qhp_file} -o ${${qch_file}}
300  DEPENDS ${PLUGIN_DOXYGEN_OUTPUT_DIR}/doxygen.conf ${_file_dependencies}
301  )
302 
303  #set_source_files_properties(${qch_file} PROPERTIES GENERATED 1)
304 
305  set(${qch_file} ${${qch_file}} PARENT_SCOPE)
306 
307 endfunction()
308 
309 function(MACRO_CREATE_MITK_CTK_PLUGIN)
310  message(SEND_ERROR "The function MACRO_CREATE_MITK_CTK_PLUGIN was renamed to mitk_create_plugin in MITK 2015.05.")
311 endfunction()
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
Definition: jsoncpp.cpp:244
mitk_create_plugin()
Creates a MITK CTK plugin.