Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 #! \param WARNINGS_NO_ERRORS (optional) Do not handle compiler warnings as errors
32 function(mitk_create_plugin)
33 
34  # options
35  set(arg_options
36  TEST_PLUGIN # Mark this plug-in as a testing plug-in
37  NO_INSTALL # Don't install this plug-in
38  NO_QHP_TRANSFORM
39  WARNINGS_NO_ERRORS
40  )
41 
42  # single value arguments
43  set(arg_single
44  EXPORT_DIRECTIVE # (required) TODO: could be generated via CMake as it is done for MITK modules already
45  )
46 
47  # multiple value arguments
48  set(arg_multiple
49  EXPORTED_INCLUDE_SUFFIXES # (optional) additional public include directories
50  MODULE_DEPENDS # (optional)
51  PACKAGE_DEPENDS
52  DOXYGEN_TAGFILES
53  MOC_OPTIONS
54  SUBPROJECTS
55  )
56 
57  cmake_parse_arguments(_PLUGIN "${arg_options}" "${arg_single}" "${arg_multiple}" ${ARGN})
58 
59  if(_PLUGIN_TEST_PLUGIN)
60  set(_PLUGIN_NO_INSTALL 1)
61  set(is_test_plugin "TEST_PLUGIN")
62  else()
63  set(is_test_plugin)
64  endif()
65 
66  set(_PLUGIN_MOC_OPTIONS "-DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED ${_PLUGIN_MOC_OPTIONS}")
67 
68  set(PLUGIN_TARGET ${PROJECT_NAME})
69 
70  mitk_check_module_dependencies(MODULES ${_PLUGIN_MODULE_DEPENDS}
71  PACKAGES ${_PLUGIN_PACKAGE_DEPENDS}
72  MISSING_DEPENDENCIES_VAR _missing_deps
73  MODULE_DEPENDENCIES_VAR _module_deps
74  PACKAGE_DEPENDENCIES_VAR _package_deps)
75 
76  if(_missing_deps)
77  if(NOT MITK_BUILD_ALL_PLUGINS)
78  message(SEND_ERROR "${PROJECT_NAME} is missing requirements and won't be built. Missing: ${_missing_deps}")
79  else()
80  message(STATUS "${PROJECT_NAME} is missing requirements and won't be built. Missing: ${_missing_deps}")
81  endif()
82  return()
83  endif()
84 
85  # -------------- All dependencies are resolved ------------------
86 
87  message(STATUS "Creating CTK plugin ${PROJECT_NAME}")
88 
89  include(files.cmake)
90 
91  set(_PLUGIN_CPP_FILES ${CPP_FILES})
92  set(_PLUGIN_MOC_H_FILES ${MOC_H_FILES})
93  set(_PLUGIN_UI_FILES ${UI_FILES})
94  set(_PLUGIN_CACHED_RESOURCE_FILES ${CACHED_RESOURCE_FILES})
95  set(_PLUGIN_TRANSLATION_FILES ${TRANSLATION_FILES})
96  set(_PLUGIN_QRC_FILES ${QRC_FILES})
97  set(_PLUGIN_H_FILES ${H_FILES})
98  set(_PLUGIN_TXX_FILES ${TXX_FILES})
99  set(_PLUGIN_DOX_FILES ${DOX_FILES})
100  set(_PLUGIN_CMAKE_FILES ${CMAKE_FILES} files.cmake)
101  set(_PLUGIN_FILE_DEPENDENCIES ${FILE_DEPENDENCIES})
102 
103  if(CTK_PLUGINS_OUTPUT_DIR)
104  set(_output_dir "${CTK_PLUGINS_OUTPUT_DIR}")
105  else()
106  set(_output_dir "")
107  endif()
108 
109  # Compute the plugin dependencies
110  ctkFunctionGetTargetLibraries(_PLUGIN_target_libraries "")
111 
112  #------------------------------------------------------------#
113  #------------------ Qt Help support -------------------------#
114 
115  set(PLUGIN_GENERATED_QCH_FILES )
116  if(BLUEBERRY_USE_QT_HELP AND
117  EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/documentation/UserManual")
118  set(PLUGIN_DOXYGEN_INPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/documentation/UserManual")
119  set(PLUGIN_DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/documentation/UserManual")
120 
121  # Create a list of Doxygen tag files from the plug-in dependencies
122  set(PLUGIN_DOXYGEN_TAGFILES)
123  foreach(_dep_target ${_PLUGIN_target_libraries})
124  string(REPLACE _ . _dep ${_dep_target})
125 
126  get_target_property(_is_imported ${_dep_target} IMPORTED)
127  if(_is_imported)
128  get_target_property(_import_loc_debug ${_dep_target} IMPORTED_LOCATION_DEBUG)
129  get_target_property(_import_loc_release ${_dep_target} IMPORTED_LOCATION_RELEASE)
130  # There is not necessarily a debug and release build
131  if(_import_loc_release)
132  set(_import_loc ${_import_loc_release})
133  else()
134  set(_import_loc ${_import_loc_debug})
135  endif()
136  get_filename_component(_target_filename "${_import_loc}" NAME)
137  # on windows there might be a Debug or Release subdirectory
138  string(REGEX REPLACE "/bin/plugins/(Debug/|Release/)?${_target_filename}" "/Plugins/${_dep}/documentation/UserManual" plugin_tag_dir "${_import_loc}" )
139  else()
140  set(plugin_tag_dir "${CMAKE_BINARY_DIR}/Plugins/${_dep}/documentation/UserManual")
141  endif()
142 
143  set(_tag_file "${plugin_tag_dir}/${_dep_target}.tag")
144  if(EXISTS ${_tag_file})
145  set(PLUGIN_DOXYGEN_TAGFILES "${PLUGIN_DOXYGEN_TAGFILES} \"${_tag_file}=qthelp://${_dep}/bundle/\"")
146  endif()
147  endforeach()
148  if(_PLUGIN_DOXYGEN_TAGFILES)
149  set(PLUGIN_DOXYGEN_TAGFILES "${PLUGIN_DOXYGEN_TAGFILES} ${_PLUGIN_DOXYGEN_TAGFILES}")
150  endif()
151  #message("PLUGIN_DOXYGEN_TAGFILES: ${PLUGIN_DOXYGEN_TAGFILES}")
152 
153  if(_PLUGIN_NO_QHP_TRANSFORM)
154  set(_use_qhp_xsl 0)
155  else()
156  set(_use_qhp_xsl 1)
157  endif()
158  _FUNCTION_CREATE_CTK_QT_COMPRESSED_HELP(PLUGIN_GENERATED_QCH_FILES ${_use_qhp_xsl})
159  list(APPEND _PLUGIN_CACHED_RESOURCE_FILES ${PLUGIN_GENERATED_QCH_FILES})
160  endif()
161 
162  #------------------------------------------------------------#
163  #------------------ Create Plug-in --------------------------#
164 
165  mitkFunctionOrganizeSources(
166  SOURCE ${_PLUGIN_CPP_FILES}
167  HEADER ${_PLUGIN_H_FILES}
168  TXX ${_PLUGIN_TXX_FILES}
169  DOC ${_PLUGIN_DOX_FILES}
170  UI ${_PLUGIN_UI_FILES}
171  QRC ${_PLUGIN_QRC_FILES} ${_PLUGIN_CACHED_RESOURCE_FILES}
172  META ${_PLUGIN_META_FILES}
173  MOC ${MY_MOC_CPP}
174  GEN_UI ${MY_UI_CPP}
175  GEN_QRC ${MY_QRC_SRCS}
176  )
177 
178  ctkMacroBuildPlugin(
179  NAME ${PLUGIN_TARGET}
180  EXPORT_DIRECTIVE ${_PLUGIN_EXPORT_DIRECTIVE}
181  SRCS ${_PLUGIN_CPP_FILES} ${_PLUGIN_H_FILES} ${CORRESPONDING__H_FILES} ${GLOBBED__H_FILES}
182  MOC_SRCS ${_PLUGIN_MOC_H_FILES}
183  MOC_OPTIONS ${_PLUGIN_MOC_OPTIONS}
184  UI_FORMS ${_PLUGIN_UI_FILES}
185  EXPORTED_INCLUDE_SUFFIXES ${_PLUGIN_EXPORTED_INCLUDE_SUFFIXES}
186  RESOURCES ${_PLUGIN_QRC_FILES}
187  TARGET_LIBRARIES ${_PLUGIN_target_libraries}
188  CACHED_RESOURCEFILES ${_PLUGIN_CACHED_RESOURCE_FILES}
189  TRANSLATIONS ${_PLUGIN_TRANSLATION_FILES}
190  OUTPUT_DIR ${_output_dir}
191  NO_INSTALL # we install the plug-in ourselves
192  ${is_test_plugin}
193  )
194 
195  mitk_use_modules(TARGET ${PLUGIN_TARGET}
196  MODULES ${_PLUGIN_MODULE_DEPENDS}
197  PACKAGES ${_PLUGIN_PACKAGE_DEPENDS}
198  )
199 
200  set_property(TARGET ${PLUGIN_TARGET} APPEND PROPERTY COMPILE_DEFINITIONS US_MODULE_NAME=${PLUGIN_TARGET})
201  set_property(TARGET ${PLUGIN_TARGET} PROPERTY US_MODULE_NAME ${PLUGIN_TARGET})
202 
203  if(NOT CMAKE_CURRENT_SOURCE_DIR MATCHES "^${CMAKE_SOURCE_DIR}.*")
204  foreach(MITK_EXTENSION_DIR ${MITK_EXTENSION_DIRS})
205  if(CMAKE_CURRENT_SOURCE_DIR MATCHES "^${MITK_EXTENSION_DIR}.*")
206  get_filename_component(MITK_EXTENSION_ROOT_FOLDER ${MITK_EXTENSION_DIR} NAME)
207  set_property(TARGET ${PLUGIN_TARGET} PROPERTY FOLDER "${MITK_EXTENSION_ROOT_FOLDER}/Plugins")
208  break()
209  endif()
210  endforeach()
211  else()
212  set_property(TARGET ${PLUGIN_TARGET} PROPERTY FOLDER "${MITK_ROOT_FOLDER}/Plugins")
213  endif()
214 
215  set(plugin_c_flags)
216  set(plugin_cxx_flags)
217 
218  if(NOT _PLUGIN_WARNINGS_NO_ERRORS)
219  if(MSVC_VERSION)
220  mitkFunctionCheckCAndCXXCompilerFlags("/WX" plugin_c_flags plugin_cxx_flags)
221  else()
222  mitkFunctionCheckCAndCXXCompilerFlags(-Werror plugin_c_flags plugin_cxx_flags)
223  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=c++0x-static-nonintegral-init" plugin_c_flags plugin_cxx_flags)
224  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=static-member-init" plugin_c_flags plugin_cxx_flags)
225  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=unknown-warning" plugin_c_flags plugin_cxx_flags)
226  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=gnu" plugin_c_flags plugin_cxx_flags)
227  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=cast-function-type" plugin_c_flags plugin_cxx_flags)
228  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=inconsistent-missing-override" plugin_c_flags plugin_cxx_flags)
229  endif()
230  endif()
231 
232  if(plugin_c_flags)
233  string(REPLACE " " ";" plugin_c_flags "${plugin_c_flags}")
234  target_compile_options(${PLUGIN_TARGET} PRIVATE ${plugin_c_flags})
235  endif()
236 
237  if(plugin_cxx_flags)
238  string(REPLACE " " ";" plugin_cxx_flags "${plugin_cxx_flags}")
239  target_compile_options(${PLUGIN_TARGET} PRIVATE ${plugin_cxx_flags})
240  endif()
241 
242  if(NOT MY_SUBPROJECTS)
243  if(MITK_DEFAULT_SUBPROJECTS)
244  set(MY_SUBPROJECTS ${MITK_DEFAULT_SUBPROJECTS})
245  elseif(TARGET MITK-Plugins)
246  set(MY_SUBPROJECTS MITK-Plugins)
247  endif()
248  endif()
249 
250  if(MY_SUBPROJECTS)
251  set_property(TARGET ${PLUGIN_TARGET} PROPERTY LABELS ${MY_SUBPROJECTS})
252  foreach(subproject ${MY_SUBPROJECTS})
253  add_dependencies(${subproject} ${PLUGIN_TARGET})
254  endforeach()
255  endif()
256 
257  if(_PLUGIN_TEST_PLUGIN)
258  find_package(CppUnit REQUIRED)
259  target_include_directories(${PLUGIN_TARGET} PRIVATE ${CppUnit_INCLUDE_DIRS})
260  target_link_libraries(${PLUGIN_TARGET} PRIVATE ${CppUnit_LIBRARIES})
261  endif()
262 
263  if(mbilog_FOUND)
264  target_link_libraries(${PLUGIN_TARGET} PRIVATE mbilog)
265  endif()
266 
267  set(_PLUGIN_META_FILES "${CMAKE_CURRENT_SOURCE_DIR}/manifest_headers.cmake")
268  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/plugin.xml")
269  list(APPEND _PLUGIN_META_FILES "${CMAKE_CURRENT_SOURCE_DIR}/plugin.xml")
270  endif()
271 
272  set(PLUGIN_TARGET ${PLUGIN_TARGET} PARENT_SCOPE)
273 
274  #------------------------------------------------------------#
275  #------------------ Installer support -----------------------#
276  if(NOT _PLUGIN_NO_INSTALL)
277  set(install_directories "")
278  if(NOT MACOSX_BUNDLE_NAMES)
279  set(install_directories bin/plugins)
280  else(NOT MACOSX_BUNDLE_NAMES)
281  foreach(bundle_name ${MACOSX_BUNDLE_NAMES})
282  list(APPEND install_directories ${bundle_name}.app/Contents/MacOS/plugins)
283  endforeach(bundle_name)
284  endif(NOT MACOSX_BUNDLE_NAMES)
285 
286  foreach(install_subdir ${install_directories})
287 
288  mitkFunctionInstallCTKPlugin(TARGETS ${PLUGIN_TARGET}
289  DESTINATION ${install_subdir})
290 
291  endforeach()
292 
293  set(_autoload_targets )
294  foreach(_dependency ${_module_deps})
295  get_target_property(_dep_autoloads ${_dependency} MITK_AUTOLOAD_TARGETS)
296  if (_dep_autoloads)
297  list(APPEND _autoload_targets ${_dep_autoloads})
298  endif()
299  endforeach()
300 
301  # The MITK_AUTOLOAD_TARGETS property is used in the mitkFunctionInstallAutoLoadModules
302  # macro which expects a list of plug-in targets.
303  if (_autoload_targets)
304  list(REMOVE_DUPLICATES _autoload_targets)
305  set_target_properties(${PLUGIN_TARGET} PROPERTIES MITK_AUTOLOAD_TARGETS "${_autoload_targets}")
306  endif()
307  endif()
308 
309 endfunction()
310 
311 
312 function(_FUNCTION_CREATE_CTK_QT_COMPRESSED_HELP qch_file use_xsl)
313 
314  set(_manifest_path "${CMAKE_CURRENT_SOURCE_DIR}/manifest_headers.cmake")
315  if(NOT EXISTS ${_manifest_path})
316  message(FATAL_ERROR "${_manifest_path} not found")
317  endif()
318 
319  include(${_manifest_path})
320  string(REPLACE "_" "." Plugin-SymbolicName "${PLUGIN_TARGET}")
321 
322  configure_file(${MITK_SOURCE_DIR}/Documentation/doxygen_plugin_manual.conf.in
323  ${PLUGIN_DOXYGEN_OUTPUT_DIR}/doxygen.conf
324  )
325 
326  set(_qhp_xsl_file "${MITK_SOURCE_DIR}/Documentation/qhp_toc.xsl")
327  set(_generated_qhp_file "${PLUGIN_DOXYGEN_OUTPUT_DIR}/html/index.qhp")
328  set(_transformed_qhp_file "${PLUGIN_DOXYGEN_OUTPUT_DIR}/html/${PLUGIN_TARGET}.qhp")
329  set(${qch_file} "${CMAKE_CURRENT_BINARY_DIR}/resources/${PLUGIN_TARGET}.qch")
330 
331  set(_xsl_command )
332  if(use_xsl)
333  set(_xsl_command COMMAND ${QT_XMLPATTERNS_EXECUTABLE} ${_qhp_xsl_file} ${_generated_qhp_file} -output ${_transformed_qhp_file})
334  endif()
335 
336  file(GLOB _file_dependencies "${PLUGIN_DOXYGEN_INPUT_DIR}/*")
337 
338  add_custom_command(OUTPUT ${${qch_file}}
339  # Generate a Qt help project (index.qhp) with doxygen
340  COMMAND ${DOXYGEN_EXECUTABLE} ${PLUGIN_DOXYGEN_OUTPUT_DIR}/doxygen.conf
341  # Use a XSL transformation to get rid of the top-level entry
342  ${_xsl_command}
343  # Generate the final Qt compressed help file (.qch)
344  COMMAND ${QT_HELPGENERATOR_EXECUTABLE} ${_transformed_qhp_file} -o ${${qch_file}}
345  DEPENDS ${PLUGIN_DOXYGEN_OUTPUT_DIR}/doxygen.conf ${_file_dependencies}
346  )
347 
348  #set_source_files_properties(${qch_file} PROPERTIES GENERATED 1)
349 
350  set(${qch_file} ${${qch_file}} PARENT_SCOPE)
351 
352 endfunction()
353 
354 function(MACRO_CREATE_MITK_CTK_PLUGIN)
355  message(SEND_ERROR "The function MACRO_CREATE_MITK_CTK_PLUGIN was renamed to mitk_create_plugin in MITK 2015.05.")
356 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.