Medical Imaging Interaction Toolkit  2018.4.99-dfa0c14e
Medical Imaging Interaction Toolkit
mitkFunctionCreateModule.cmake
Go to the documentation of this file.
1 ##################################################################
2 #
3 # mitk_create_module
4 #
5 #! Creates a module for the automatic module dependency system within MITK.
6 #!
7 #! Example:
8 #!
9 #! \code
10 #! mitk_create_module(
11 #! DEPENDS PUBLIC MitkCore
12 #! PACKAGE_DEPENDS
13 #! PRIVATE Qt5|Xml+Networking
14 #! PUBLIC ITK|Watershed
15 #! \endcode
16 #!
17 #! The <moduleName> parameter specifies the name of the module which is used
18 #! to create a logical target name. The parameter is optional in case the
19 #! MITK_MODULE_NAME_DEFAULTS_TO_DIRECTORY_NAME variable evaluates to TRUE. The
20 #! module name will then be derived from the directory name in which this
21 #! function is called.
22 #!
23 #! If set, the following variables will be used to validate the module name:
24 #!
25 #! MITK_MODULE_NAME_REGEX_MATCH The module name must match this regular expression.
26 #! MITK_MODULE_NAME_REGEX_NOT_MATCH The module name must not match this regular expression.
27 #!
28 #! If the MITK_MODULE_NAME_PREFIX variable is set, the module name will be prefixed
29 #! with its contents.
30 #!
31 #! A modules source files are specified in a separate CMake file usually
32 #! called files.cmake, located in the module root directory. The
33 #! mitk_create_module() macro evaluates the following CMake variables
34 #! from the files.cmake file:
35 #!
36 #! - CPP_FILES A list of .cpp files
37 #! - H_FILES A list of .h files without a corresponding .cpp file
38 #! - TXX_FILES A list of .txx files
39 #! - RESOURCE_FILES A list of files (resources) which are embedded into the module
40 #! - MOC_H_FILES A list of Qt header files which should be processed by the MOC
41 #! - UI_FILES A list of .ui Qt UI files
42 #! - QRC_FILES A list of .qrc Qt resource files
43 #! - DOX_FILES A list of .dox Doxygen files
44 #!
45 #! List of variables available after the function is called:
46 #! - MODULE_NAME
47 #! - MODULE_TARGET
48 #! - MODULE_IS_ENABLED
49 #! - MODULE_SUBPROJECTS
50 #!
51 #! \sa mitk_create_executable
52 #!
53 #! Parameters (all optional):
54 #!
55 #! \param <moduleName> The module name (also used as target name)
56 #! \param FILES_CMAKE File name of a CMake file setting source list variables
57 #! (defaults to files.cmake)
58 #! \param VERSION Module version number, e.g. "1.2.0"
59 #! \param AUTOLOAD_WITH A module target name identifying the module which will
60 #! trigger the automatic loading of this module
61 #! \param DEPRECATED_SINCE Marks this modules as deprecated since <arg>
62 #! \param DESCRIPTION A description for this module
63 #!
64 #! Multi-value Parameters (all optional):
65 #!
66 
67 #! \param SUBPROJECTS List of CDash labels
68 #! \param INCLUDE_DIRS Include directories for this module:
69 #! \verbatim
70 #! [[PUBLIC|PRIVATE|INTERFACE] <dir1>...]...
71 #! \endverbatim
72 #! The default scope for include directories is PUBLIC.
73 #! \param DEPENDS List of module dependencies:
74 #! \verbatim
75 #! [[PUBLIC|PRIVATE|INTERFACE] <module1>...]...
76 #! \endverbatim
77 #! The default scope for module dependencies is PUBLIC.
78 #! \param PACKAGE_DEPENDS List of public packages dependencies (e.g. Qt, VTK, etc.).
79 #! Package dependencies have the following syntax:
80 #! \verbatim
81 #! [PUBLIC|PRIVATE|INTERFACE] PACKAGE[|COMPONENT1[+COMPONENT2]...]
82 #! \endverbatim
83 #! The default scope for package dependencies is PRIVATE.
84 #! \param ADDITIONAL_LIBS List of additional private libraries linked to this module.
85 #! The folder containing the library will be added to the global list of library search paths.
86 #! \param CPP_FILES List of source files for this module. If the list is non-empty,
87 #! the module does not need to provide a files.cmake file or FILES_CMAKE argument.
88 #! \param H_FILES List of public header files for this module. It is recommended to use
89 #! a files.cmake file instead.
90 #!
91 #! Options (optional)
92 #!
93 #! \param FORCE_STATIC Force building this module as a static library
94 #! \param GCC_DEFAULT_VISIBILITY Do not use gcc visibility flags - all
95 #! symbols will be exported
96 #! \param NO_INIT Do not create CppMicroServices initialization code
97 #! \param NO_FEATURE_INFO Do not create a feature info by calling add_feature_info()
98 #! \param WARNINGS_NO_ERRORS Do not treat compiler warnings as errors
99 #
100 ##################################################################
101 function(mitk_create_module)
102 
103  set(_macro_params
104  VERSION # module version number, e.g. "1.2.0"
105  EXPORT_DEFINE # export macro name for public symbols of this module (DEPRECATED)
106  AUTOLOAD_WITH # a module target name identifying the module which will trigger the
107  # automatic loading of this module
108  FILES_CMAKE # file name of a CMake file setting source list variables
109  # (defaults to files.cmake)
110  DEPRECATED_SINCE # marks this modules as deprecated
111  DESCRIPTION # a description for this module
112  )
113 
114  set(_macro_multiparams
115  SUBPROJECTS # list of CDash labels
116  INCLUDE_DIRS # include directories: [PUBLIC|PRIVATE|INTERFACE] <list>
117  INTERNAL_INCLUDE_DIRS # include dirs internal to this module (DEPRECATED)
118  DEPENDS # list of modules this module depends on: [PUBLIC|PRIVATE|INTERFACE] <list>
119  DEPENDS_INTERNAL # list of modules this module internally depends on (DEPRECATED)
120  PACKAGE_DEPENDS # list of "packages this module depends on (e.g. Qt, VTK, etc.): [PUBLIC|PRIVATE|INTERFACE] <package-list>
121  TARGET_DEPENDS # list of CMake targets this module should depend on
122  ADDITIONAL_LIBS # list of addidtional private libraries linked to this module.
123  CPP_FILES # list of cpp files
124  H_FILES # list of header files: [PUBLIC|PRIVATE] <list>
125  )
126 
127  set(_macro_options
128  FORCE_STATIC # force building this module as a static library
129  HEADERS_ONLY # this module is a headers-only library
130  GCC_DEFAULT_VISIBILITY # do not use gcc visibility flags - all symbols will be exported
131  NO_DEFAULT_INCLUDE_DIRS # do not add default include directories like "include" or "."
132  NO_INIT # do not create CppMicroServices initialization code
133  NO_FEATURE_INFO # do not create a feature info by calling add_feature_info()
134  WARNINGS_NO_ERRORS # do not treat compiler warnings as errors
135  EXECUTABLE # create an executable; do not use directly, use mitk_create_executable() instead
136  C_MODULE # compile all source files as C sources
137  CXX_MODULE # compile all source files as C++ sources
138  )
139 
140  cmake_parse_arguments(MODULE "${_macro_options}" "${_macro_params}" "${_macro_multiparams}" ${ARGN})
141 
142  set(MODULE_NAME ${MODULE_UNPARSED_ARGUMENTS})
143 
144  # -----------------------------------------------------------------
145  # Sanity checks
146 
147  if(NOT MODULE_NAME)
148  if(MITK_MODULE_NAME_DEFAULTS_TO_DIRECTORY_NAME)
149  get_filename_component(MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
150  else()
151  message(SEND_ERROR "The module name must not be empty")
152  endif()
153  endif()
154 
155  set(_deprecated_args INTERNAL_INCLUDE_DIRS DEPENDS_INTERNAL EXPORT_DEFINE TARGET_DEPENDS HEADERS_ONLY)
156  foreach(_deprecated_arg ${_deprecated_args})
157  if(MODULE_${_deprecated_arg})
158  message(WARNING "The ${_deprecated_arg} argument is deprecated")
159  endif()
160  endforeach()
161 
162  set(_module_type module)
163  set(_Module_type Module)
164  if(MODULE_EXECUTABLE)
165  set(_module_type executable)
166  set(_Module_type Executable)
167  endif()
168 
169  if(MITK_MODULE_NAME_REGEX_MATCH)
170  if(NOT ${MODULE_NAME} MATCHES ${MITK_MODULE_NAME_REGEX_MATCH})
171  message(SEND_ERROR "The ${_module_type} name \"${MODULE_NAME}\" does not match the regular expression \"${MITK_MODULE_NAME_REGEX_MATCH}\".")
172  endif()
173  endif()
174  if(MITK_MODULE_NAME_REGEX_NOT_MATCH)
175  if(${MODULE_NAME} MATCHES ${MITK_MODULE_NAME_REGEX_NOT_MATCH})
176  message(SEND_ERROR "The ${_module_type} name \"${MODULE_NAME}\" must not match the regular expression \"${MITK_MODULE_NAME_REGEX_NOT_MATCH}\".")
177  endif()
178  endif()
179 
180  if(MITK_MODULE_NAME_PREFIX AND NOT MODULE_NAME MATCHES "^${MITK_MODULE_NAME_PREFIX}.*$")
181  set(MODULE_NAME "${MITK_MODULE_NAME_PREFIX}${MODULE_NAME}")
182  endif()
183 
184  if(NOT MODULE_FILES_CMAKE)
185  set(MODULE_FILES_CMAKE files.cmake)
186  endif()
187  if(NOT IS_ABSOLUTE ${MODULE_FILES_CMAKE})
188  set(MODULE_FILES_CMAKE ${CMAKE_CURRENT_SOURCE_DIR}/${MODULE_FILES_CMAKE})
189  endif()
190 
191  if(NOT MODULE_SUBPROJECTS)
192  if(MITK_DEFAULT_SUBPROJECTS)
193  set(MODULE_SUBPROJECTS ${MITK_DEFAULT_SUBPROJECTS})
194  elseif(TARGET MITK-Modules)
195  set(MODULE_SUBPROJECTS MITK-Modules)
196  endif()
197  endif()
198 
199  # check if the subprojects exist as targets
200  if(MODULE_SUBPROJECTS)
201  foreach(subproject ${MODULE_SUBPROJECTS})
202  if(NOT TARGET ${subproject})
203  message(SEND_ERROR "The subproject ${subproject} does not have a corresponding target")
204  endif()
205  endforeach()
206  endif()
207 
208  # -----------------------------------------------------------------
209  # Check if module should be build
210 
211  set(MODULE_TARGET ${MODULE_NAME})
212 
213  # assume worst case
214  set(MODULE_IS_ENABLED 0)
215  # first we check if we have an explicit module build list
216  if(MITK_MODULES_TO_BUILD)
217  list(FIND MITK_MODULES_TO_BUILD ${MODULE_NAME} _MOD_INDEX)
218  if(_MOD_INDEX EQUAL -1)
219  set(MODULE_IS_EXCLUDED 1)
220  endif()
221  endif()
222 
223  if(NOT MODULE_IS_EXCLUDED)
224  # first of all we check for the dependencies
225  _mitk_parse_package_args(${MODULE_PACKAGE_DEPENDS})
226  mitk_check_module_dependencies(MODULES ${MODULE_DEPENDS}
227  PACKAGES ${PACKAGE_NAMES}
228  MISSING_DEPENDENCIES_VAR _MISSING_DEP
229  PACKAGE_DEPENDENCIES_VAR PACKAGE_NAMES)
230 
231  if(_MISSING_DEP)
232  if(MODULE_NO_FEATURE_INFO)
233  message("${_Module_type} ${MODULE_NAME} won't be built, missing dependency: ${_MISSING_DEP}")
234  endif()
235  set(MODULE_IS_ENABLED 0)
236  else()
237  foreach(dep ${MODULE_DEPENDS})
238  if(TARGET ${dep})
239  get_target_property(AUTLOAD_DEP ${dep} MITK_AUTOLOAD_DIRECTORY)
240  if (AUTLOAD_DEP)
241  message(SEND_ERROR "Module \"${MODULE_NAME}\" has an invalid dependency on autoload module \"${dep}\". Check MITK_CREATE_MODULE usage for \"${MODULE_NAME}\".")
242  endif()
243  endif()
244  endforeach(dep)
245 
246  set(MODULE_IS_ENABLED 1)
247  # now check for every package if it is enabled. This overlaps a bit with
248  # MITK_CHECK_MODULE ...
249  foreach(_package ${PACKAGE_NAMES})
250  if((DEFINED MITK_USE_${_package}) AND NOT (MITK_USE_${_package}))
251  message("${_Module_type} ${MODULE_NAME} won't be built. Turn on MITK_USE_${_package} if you want to use it.")
252  set(MODULE_IS_ENABLED 0)
253  break()
254  endif()
255  endforeach()
256  endif()
257  endif()
258 
259  # -----------------------------------------------------------------
260  # Start creating the module
261 
262  if(MODULE_IS_ENABLED)
263 
264  # clear variables defined in files.cmake
265  set(RESOURCE_FILES )
266  set(CPP_FILES )
267  set(H_FILES )
268  set(TXX_FILES )
269  set(DOX_FILES )
270  set(UI_FILES )
271  set(MOC_H_FILES )
272  set(QRC_FILES )
273 
274  # clear other variables
275  set(Q${KITNAME}_GENERATED_CPP )
276  set(Q${KITNAME}_GENERATED_MOC_CPP )
277  set(Q${KITNAME}_GENERATED_QRC_CPP )
278  set(Q${KITNAME}_GENERATED_UI_CPP )
279 
280  # check and set-up auto-loading
281  if(MODULE_AUTOLOAD_WITH)
282  if(NOT TARGET "${MODULE_AUTOLOAD_WITH}")
283  message(SEND_ERROR "The module target \"${MODULE_AUTOLOAD_WITH}\" specified as the auto-loading module for \"${MODULE_NAME}\" does not exist")
284  endif()
285  endif()
286  set(_module_autoload_meta_target "${CMAKE_PROJECT_NAME}-autoload")
287  # create a meta-target if it does not already exist
288  if(NOT TARGET ${_module_autoload_meta_target})
289  add_custom_target(${_module_autoload_meta_target})
290  set_property(TARGET ${_module_autoload_meta_target} PROPERTY FOLDER "${MITK_ROOT_FOLDER}/Modules/Autoload")
291  endif()
292 
293  if(NOT MODULE_EXPORT_DEFINE)
294  set(MODULE_EXPORT_DEFINE ${MODULE_NAME}_EXPORT)
295  endif()
296 
297  if(MITK_GENERATE_MODULE_DOT)
298  message("MODULEDOTNAME ${MODULE_NAME}")
299  foreach(dep ${MODULE_DEPENDS})
300  message("MODULEDOT \"${MODULE_NAME}\" -> \"${dep}\" ; ")
301  endforeach(dep)
302  endif(MITK_GENERATE_MODULE_DOT)
303 
304  if (EXISTS ${MODULE_FILES_CMAKE})
305  include(${MODULE_FILES_CMAKE})
306  endif()
307 
308  if(MODULE_CPP_FILES)
309  list(APPEND CPP_FILES ${MODULE_CPP_FILES})
310  endif()
311 
312  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src")
313  # Preprend the "src" directory to the cpp file list
314  set(_cpp_files ${CPP_FILES})
315  set(CPP_FILES )
316  foreach(_cpp_file ${_cpp_files})
317  list(APPEND CPP_FILES "src/${_cpp_file}")
318  endforeach()
319  endif()
320 
321  if(CPP_FILES OR RESOURCE_FILES OR UI_FILES OR MOC_H_FILES OR QRC_FILES)
322  set(MODULE_HEADERS_ONLY 0)
323  if(MODULE_C_MODULE)
324  set_source_files_properties(${CPP_FILES} PROPERTIES LANGUAGE C)
325  elseif(MODULE_CXX_MODULE)
326  set_source_files_properties(${CPP_FILES} PROPERTIES LANGUAGE CXX)
327  endif()
328  else()
329  set(MODULE_HEADERS_ONLY 1)
330  if(MODULE_AUTOLOAD_WITH)
331  message(SEND_ERROR "A headers only module cannot be auto-loaded")
332  endif()
333  endif()
334 
335  set(module_c_flags )
336  set(module_c_flags_debug )
337  set(module_c_flags_release )
338  set(module_cxx_flags )
339  set(module_cxx_flags_debug )
340  set(module_cxx_flags_release )
341 
342  if(MODULE_GCC_DEFAULT_VISIBILITY OR NOT CMAKE_COMPILER_IS_GNUCXX)
343  # We only support hidden visibility for gcc for now. Clang still has troubles with
344  # correctly marking template declarations and explicit template instantiations as exported.
345  # See http://comments.gmane.org/gmane.comp.compilers.clang.scm/50028
346  # and http://llvm.org/bugs/show_bug.cgi?id=10113
347  set(CMAKE_CXX_VISIBILITY_PRESET default)
348  set(CMAKE_VISIBILITY_INLINES_HIDDEN 0)
349  else()
350  set(CMAKE_CXX_VISIBILITY_PRESET hidden)
351  set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
352  endif()
353 
354  if(NOT MODULE_WARNINGS_NO_ERRORS)
355  if(MSVC_VERSION)
356  mitkFunctionCheckCAndCXXCompilerFlags("/WX" module_c_flags module_cxx_flags)
357  # this would turn on unused parameter warnings, but unfortunately MSVC cannot
358  # distinguish yet between internal and external headers so this would be triggered
359  # a lot by external code. There is support for it on the way so this line could be
360  # reactivated after https://gitlab.kitware.com/cmake/cmake/issues/17904 has been fixed.
361  # mitkFunctionCheckCAndCXXCompilerFlags("/w34100" module_c_flags module_cxx_flags)
362  else()
363  mitkFunctionCheckCAndCXXCompilerFlags(-Werror module_c_flags module_cxx_flags)
364 
365  # The flag "c++0x-static-nonintegral-init" has been renamed in newer Clang
366  # versions to "static-member-init", see
367  # http://clang-developers.42468.n3.nabble.com/Wc-0x-static-nonintegral-init-gone-td3999651.html
368  #
369  # Also, older Clang and seemingly all gcc versions do not warn if unknown
370  # "-no-*" flags are used, so CMake will happily append any -Wno-* flag to the
371  # command line. This may get confusing if unrelated compiler errors happen and
372  # the error output then additionally contains errors about unknown flags (which
373  # is not the case if there were no compile errors).
374  #
375  # So instead of using -Wno-* we use -Wno-error=*, which will be properly rejected by
376  # the compiler and if applicable, prints the specific warning as a real warning and
377  # not as an error (although -Werror was given).
378 
379  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=c++0x-static-nonintegral-init" module_c_flags module_cxx_flags)
380  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=static-member-init" module_c_flags module_cxx_flags)
381  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=unknown-warning" module_c_flags module_cxx_flags)
382  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=gnu" module_c_flags module_cxx_flags)
383  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=class-memaccess" module_c_flags module_cxx_flags)
384  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=inconsistent-missing-override" module_c_flags module_cxx_flags)
385  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=deprecated-copy" module_c_flags module_cxx_flags)
386  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=cast-function-type" module_c_flags module_cxx_flags)
387  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=deprecated-declarations" module_c_flags module_cxx_flags)
388  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=type-limits" module_c_flags module_cxx_flags)
389  endif()
390  endif()
391 
392  if(MODULE_FORCE_STATIC)
393  set(_STATIC STATIC)
394  else()
395  set(_STATIC )
396  endif(MODULE_FORCE_STATIC)
397 
398  if(NOT MODULE_HEADERS_ONLY)
399  if(NOT MODULE_NO_INIT OR RESOURCE_FILES)
400  find_package(CppMicroServices QUIET NO_MODULE REQUIRED)
401  endif()
402  if(NOT MODULE_NO_INIT)
403  usFunctionGenerateModuleInit(CPP_FILES)
404  endif()
405 
406  set(binary_res_files )
407  set(source_res_files )
408  if(RESOURCE_FILES)
409  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/resource")
410  set(res_dir resource)
411  elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Resources")
412  set(res_dir Resources)
413  else()
414  message(SEND_ERROR "Resources specified but ${CMAKE_CURRENT_SOURCE_DIR}/resource directory not found.")
415  endif()
416  foreach(res_file ${RESOURCE_FILES})
417  if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${res_dir}/${res_file})
418  list(APPEND binary_res_files "${res_file}")
419  else()
420  list(APPEND source_res_files "${res_file}")
421  endif()
422  endforeach()
423 
424  # Add a source level dependencies on resource files
425  usFunctionGetResourceSource(TARGET ${MODULE_TARGET} OUT CPP_FILES)
426  endif()
427  endif()
428 
429  if(MITK_USE_Qt5)
430  if(UI_FILES)
431  qt5_wrap_ui(Q${KITNAME}_GENERATED_UI_CPP ${UI_FILES})
432  endif()
433  if(MOC_H_FILES)
434  qt5_wrap_cpp(Q${KITNAME}_GENERATED_MOC_CPP ${MOC_H_FILES} OPTIONS -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
435  endif()
436  if(QRC_FILES)
437  qt5_add_resources(Q${KITNAME}_GENERATED_QRC_CPP ${QRC_FILES})
438  endif()
439  endif()
440 
441  set(Q${KITNAME}_GENERATED_CPP ${Q${KITNAME}_GENERATED_CPP} ${Q${KITNAME}_GENERATED_UI_CPP} ${Q${KITNAME}_GENERATED_MOC_CPP} ${Q${KITNAME}_GENERATED_QRC_CPP})
442 
443  mitkFunctionOrganizeSources(
444  SOURCE ${CPP_FILES}
445  HEADER ${H_FILES}
446  TXX ${TXX_FILES}
447  DOC ${DOX_FILES}
448  UI ${UI_FILES}
449  QRC ${QRC_FILES}
450  MOC ${Q${KITNAME}_GENERATED_MOC_CPP}
451  GEN_QRC ${Q${KITNAME}_GENERATED_QRC_CPP}
452  GEN_UI ${Q${KITNAME}_GENERATED_UI_CPP}
453  )
454 
455  set(coverage_sources
456  ${CPP_FILES} ${H_FILES} ${GLOBBED__H_FILES} ${CORRESPONDING__H_FILES} ${TXX_FILES}
457  ${TOOL_CPPS} ${TOOL_GUI_CPPS})
458 
459  if(MODULE_SUBPROJECTS)
460  set_property(SOURCE ${coverage_sources} APPEND PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK)
461  endif()
462 
463  # ---------------------------------------------------------------
464  # Create the actual module target
465 
466  if(MODULE_HEADERS_ONLY)
467  add_library(${MODULE_TARGET} INTERFACE)
468  # INTERFACE_LIBRARY targets may only have whitelisted properties. The property "FOLDER" is not allowed.
469  # set_property(TARGET ${MODULE_TARGET} PROPERTY FOLDER "${MITK_ROOT_FOLDER}/Modules")
470  else()
471  if(MODULE_EXECUTABLE)
472  add_executable(${MODULE_TARGET}
473  ${MODULE_CPP_FILES} ${coverage_sources} ${CPP_FILES_GENERATED} ${Q${KITNAME}_GENERATED_CPP}
474  ${DOX_FILES} ${UI_FILES} ${QRC_FILES})
475  set_property(TARGET ${MODULE_TARGET} PROPERTY FOLDER "${MITK_ROOT_FOLDER}/Modules/Executables")
476  set(_us_module_name main)
477  else()
478  add_library(${MODULE_TARGET} ${_STATIC}
479  ${coverage_sources} ${CPP_FILES_GENERATED} ${Q${KITNAME}_GENERATED_CPP}
480  ${DOX_FILES} ${UI_FILES} ${QRC_FILES})
481  set_property(TARGET ${MODULE_TARGET} PROPERTY FOLDER "${MITK_ROOT_FOLDER}/Modules")
482  set(_us_module_name ${MODULE_TARGET})
483  endif()
484 
485  # Apply properties to the module target.
486  target_compile_definitions(${MODULE_TARGET} PRIVATE US_MODULE_NAME=${_us_module_name})
487  if(MODULE_C_MODULE)
488  if(module_c_flags)
489  string(REPLACE " " ";" module_c_flags "${module_c_flags}")
490  target_compile_options(${MODULE_TARGET} PRIVATE ${module_c_flags})
491  endif()
492  if(module_c_flags_debug)
493  string(REPLACE " " ";" module_c_flags_debug "${module_c_flags_debug}")
494  target_compile_options(${MODULE_TARGET} PRIVATE $<$<CONFIG:Debug>:${module_c_flags_debug}>)
495  endif()
496  if(module_c_flags_release)
497  string(REPLACE " " ";" module_c_flags_release "${module_c_flags_release}")
498  target_compile_options(${MODULE_TARGET} PRIVATE $<$<CONFIG:Release>:${module_c_flags_release}>)
499  endif()
500  else()
501  if(module_cxx_flags)
502  string(REPLACE " " ";" module_cxx_flags "${module_cxx_flags}")
503  target_compile_options(${MODULE_TARGET} PRIVATE ${module_cxx_flags})
504  endif()
505  if(module_cxx_flags_debug)
506  string(REPLACE " " ";" module_cxx_flags_debug "${module_cxx_flags_debug}")
507  target_compile_options(${MODULE_TARGET} PRIVATE $<$<CONFIG:Debug>:${module_cxx_flags_debug}>)
508  endif()
509  if(module_cxx_flags_release)
510  string(REPLACE " " ";" module_cxx_flags_release "${module_cxx_flags_release}")
511  target_compile_options(${MODULE_TARGET} PRIVATE $<$<CONFIG:Release>:${module_cxx_flags_release}>)
512  endif()
513  endif()
514 
515  set_property(TARGET ${MODULE_TARGET} PROPERTY US_MODULE_NAME ${_us_module_name})
516 
517  # Add additional library search directories to a global property which
518  # can be evaluated by other CMake macros, e.g. our install scripts.
519  if(MODULE_ADDITIONAL_LIBS)
520  target_link_libraries(${MODULE_TARGET} PRIVATE ${MODULE_ADDITIONAL_LIBS})
521  get_property(_mitk_additional_library_search_paths GLOBAL PROPERTY MITK_ADDITIONAL_LIBRARY_SEARCH_PATHS)
522  foreach(_lib_filepath ${MODULE_ADDITIONAL_LIBS})
523  get_filename_component(_search_path "${_lib_filepath}" PATH)
524  if(_search_path)
525  list(APPEND _mitk_additional_library_search_paths "${_search_path}")
526  endif()
527  endforeach()
528  if(_mitk_additional_library_search_paths)
529  list(REMOVE_DUPLICATES _mitk_additional_library_search_paths)
530  set_property(GLOBAL PROPERTY MITK_ADDITIONAL_LIBRARY_SEARCH_PATHS ${_mitk_additional_library_search_paths})
531  endif()
532  endif()
533 
534  # add the target name to a global property which is used in the top-level
535  # CMakeLists.txt file to export the target
536  set_property(GLOBAL APPEND PROPERTY MITK_MODULE_TARGETS ${MODULE_TARGET})
537  if(MODULE_AUTOLOAD_WITH)
538  # for auto-loaded modules, adapt the output directory
539  add_dependencies(${_module_autoload_meta_target} ${MODULE_TARGET})
540  if(WIN32)
541  set(_module_output_prop RUNTIME_OUTPUT_DIRECTORY)
542  else()
543  set(_module_output_prop LIBRARY_OUTPUT_DIRECTORY)
544  endif()
545  set(_module_output_dir ${CMAKE_${_module_output_prop}}/${MODULE_AUTOLOAD_WITH})
546  get_target_property(_module_is_imported ${MODULE_AUTOLOAD_WITH} IMPORTED)
547  if(NOT _module_is_imported)
548  # if the auto-loading module is not imported, get its location
549  # and put the auto-load module relative to it.
550  get_target_property(_module_output_dir ${MODULE_AUTOLOAD_WITH} ${_module_output_prop})
551  set_target_properties(${MODULE_TARGET} PROPERTIES
552  ${_module_output_prop} ${_module_output_dir}/${MODULE_AUTOLOAD_WITH})
553  else()
554  set_target_properties(${MODULE_TARGET} PROPERTIES
555  ${_module_output_prop} ${CMAKE_${_module_output_prop}}/${MODULE_AUTOLOAD_WITH})
556  endif()
557  set_target_properties(${MODULE_TARGET} PROPERTIES
558  MITK_AUTOLOAD_DIRECTORY ${MODULE_AUTOLOAD_WITH})
559 
560  # add the auto-load module name as a property
561  set_property(TARGET ${MODULE_AUTOLOAD_WITH} APPEND PROPERTY MITK_AUTOLOAD_TARGETS ${MODULE_TARGET})
562  endif()
563 
564  if(binary_res_files)
565  usFunctionAddResources(TARGET ${MODULE_TARGET}
566  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${res_dir}
567  FILES ${binary_res_files})
568  endif()
569  if(source_res_files)
570  usFunctionAddResources(TARGET ${MODULE_TARGET}
571  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${res_dir}
572  FILES ${source_res_files})
573  endif()
574  if(binary_res_files OR source_res_files)
575  usFunctionEmbedResources(TARGET ${MODULE_TARGET})
576  endif()
577 
578  if(MODULE_DEPRECATED_SINCE)
579  set_property(TARGET ${MODULE_TARGET} PROPERTY MITK_MODULE_DEPRECATED_SINCE ${MODULE_DEPRECATED_SINCE})
580  endif()
581 
582  # create export macros
583  if (NOT MODULE_EXECUTABLE)
584  set(_export_macro_name )
585  if(MITK_LEGACY_EXPORT_MACRO_NAME)
586  set(_export_macro_names
587  EXPORT_MACRO_NAME ${MODULE_EXPORT_DEFINE}
588  NO_EXPORT_MACRO_NAME ${MODULE_NAME}_NO_EXPORT
589  DEPRECATED_MACRO_NAME ${MODULE_NAME}_DEPRECATED
590  NO_DEPRECATED_MACRO_NAME ${MODULE_NAME}_NO_DEPRECATED
591  )
592  endif()
593  generate_export_header(${MODULE_NAME}
594  ${_export_macro_names}
595  EXPORT_FILE_NAME ${MODULE_NAME}Exports.h
596  )
597  endif()
598 
599  target_include_directories(${MODULE_TARGET} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
600 
601  endif()
602 
603  # ---------------------------------------------------------------
604  # Properties for both header-only and compiled modules
605 
606  if(MODULE_HEADERS_ONLY)
607  set(_module_property_type INTERFACE)
608  else()
609  set(_module_property_type PUBLIC)
610  endif()
611 
612  if(MODULE_TARGET_DEPENDS)
613  add_dependencies(${MODULE_TARGET} ${MODULE_TARGET_DEPENDS})
614  endif()
615 
616  if(MODULE_SUBPROJECTS AND NOT MODULE_HEADERS_ONLY)
617  set_property(TARGET ${MODULE_TARGET} PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK)
618  foreach(subproject ${MODULE_SUBPROJECTS})
619  add_dependencies(${subproject} ${MODULE_TARGET})
620  endforeach()
621  endif()
622 
623  set(DEPENDS "${MODULE_DEPENDS}")
624  if(NOT MODULE_NO_INIT AND NOT MODULE_HEADERS_ONLY)
625  # Add a CppMicroServices dependency implicitly, since it is
626  # needed for the generated "module initialization" code.
627  set(DEPENDS "CppMicroServices;${DEPENDS}")
628  endif()
629  if(DEPENDS OR MODULE_PACKAGE_DEPENDS)
630  mitk_use_modules(TARGET ${MODULE_TARGET}
631  MODULES ${DEPENDS}
632  PACKAGES ${MODULE_PACKAGE_DEPENDS}
633  )
634  endif()
635 
636  if(NOT MODULE_C_MODULE)
637  target_compile_features(${MODULE_TARGET} ${_module_property_type} ${MITK_CXX_FEATURES})
638  endif()
639 
640  # add include directories
641  if(MODULE_INTERNAL_INCLUDE_DIRS)
642  target_include_directories(${MODULE_TARGET} PRIVATE ${MODULE_INTERNAL_INCLUDE_DIRS})
643  endif()
644  if(NOT MODULE_NO_DEFAULT_INCLUDE_DIRS)
645  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include)
646  target_include_directories(${MODULE_TARGET} ${_module_property_type} include)
647  else()
648  target_include_directories(${MODULE_TARGET} ${_module_property_type} .)
649  endif()
650  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src)
651  target_include_directories(${MODULE_TARGET} PRIVATE src)
652  endif()
653  endif()
654  target_include_directories(${MODULE_TARGET} ${_module_property_type} ${MODULE_INCLUDE_DIRS})
655 
656  endif()
657 
658  # -----------------------------------------------------------------
659  # Record missing dependency information
660 
661  if(_MISSING_DEP)
662  if(MODULE_DESCRIPTION)
663  set(MODULE_DESCRIPTION "${MODULE_DESCRIPTION} (missing dependencies: ${_MISSING_DEP})")
664  else()
665  set(MODULE_DESCRIPTION "(missing dependencies: ${_MISSING_DEP})")
666  endif()
667  endif()
668  if(NOT MODULE_NO_FEATURE_INFO)
669  add_feature_info(${MODULE_NAME} MODULE_IS_ENABLED "${MODULE_DESCRIPTION}")
670  endif()
671 
672  set(MODULE_NAME ${MODULE_NAME} PARENT_SCOPE)
673  set(MODULE_TARGET ${MODULE_TARGET} PARENT_SCOPE)
674  set(MODULE_IS_ENABLED ${MODULE_IS_ENABLED} PARENT_SCOPE)
675  set(MODULE_SUBPROJECTS ${MODULE_SUBPROJECTS} PARENT_SCOPE)
676 
677 endfunction()
mitk_create_module()
static const unsigned int unknown
Unknown size marker.
Definition: jsoncpp.cpp:1583
#define DEPRECATED(func)
Definition: mitkCommon.h:179