Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
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  set(MODULE_IS_ENABLED 1)
238  # now check for every package if it is enabled. This overlaps a bit with
239  # MITK_CHECK_MODULE ...
240  foreach(_package ${PACKAGE_NAMES})
241  if((DEFINED MITK_USE_${_package}) AND NOT (MITK_USE_${_package}))
242  message("${_Module_type} ${MODULE_NAME} won't be built. Turn on MITK_USE_${_package} if you want to use it.")
243  set(MODULE_IS_ENABLED 0)
244  break()
245  endif()
246  endforeach()
247  endif()
248  endif()
249 
250  # -----------------------------------------------------------------
251  # Start creating the module
252 
253  if(MODULE_IS_ENABLED)
254 
255  # clear variables defined in files.cmake
256  set(RESOURCE_FILES )
257  set(CPP_FILES )
258  set(H_FILES )
259  set(TXX_FILES )
260  set(DOX_FILES )
261  set(UI_FILES )
262  set(MOC_H_FILES )
263  set(QRC_FILES )
264 
265  # clear other variables
266  set(Q${KITNAME}_GENERATED_CPP )
267  set(Q${KITNAME}_GENERATED_MOC_CPP )
268  set(Q${KITNAME}_GENERATED_QRC_CPP )
269  set(Q${KITNAME}_GENERATED_UI_CPP )
270 
271  # check and set-up auto-loading
272  if(MODULE_AUTOLOAD_WITH)
273  if(NOT TARGET "${MODULE_AUTOLOAD_WITH}")
274  message(SEND_ERROR "The module target \"${MODULE_AUTOLOAD_WITH}\" specified as the auto-loading module for \"${MODULE_NAME}\" does not exist")
275  endif()
276  endif()
277  set(_module_autoload_meta_target "${CMAKE_PROJECT_NAME}-autoload")
278  # create a meta-target if it does not already exist
279  if(NOT TARGET ${_module_autoload_meta_target})
280  add_custom_target(${_module_autoload_meta_target})
281  set_property(TARGET ${_module_autoload_meta_target} PROPERTY FOLDER "${MITK_ROOT_FOLDER}/Modules/Autoload")
282  endif()
283 
284  if(NOT MODULE_EXPORT_DEFINE)
285  set(MODULE_EXPORT_DEFINE ${MODULE_NAME}_EXPORT)
286  endif()
287 
288  if(MITK_GENERATE_MODULE_DOT)
289  message("MODULEDOTNAME ${MODULE_NAME}")
290  foreach(dep ${MODULE_DEPENDS})
291  message("MODULEDOT \"${MODULE_NAME}\" -> \"${dep}\" ; ")
292  endforeach(dep)
293  endif(MITK_GENERATE_MODULE_DOT)
294 
295  if (EXISTS ${MODULE_FILES_CMAKE})
296  include(${MODULE_FILES_CMAKE})
297  endif()
298 
299  if(MODULE_CPP_FILES)
300  list(APPEND CPP_FILES ${MODULE_CPP_FILES})
301  endif()
302 
303  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src")
304  # Preprend the "src" directory to the cpp file list
305  set(_cpp_files ${CPP_FILES})
306  set(CPP_FILES )
307  foreach(_cpp_file ${_cpp_files})
308  list(APPEND CPP_FILES "src/${_cpp_file}")
309  endforeach()
310  endif()
311 
312  if(CPP_FILES OR RESOURCE_FILES OR UI_FILES OR MOC_H_FILES OR QRC_FILES)
313  set(MODULE_HEADERS_ONLY 0)
314  if(MODULE_C_MODULE)
315  set_source_files_properties(${CPP_FILES} PROPERTIES LANGUAGE C)
316  elseif(MODULE_CXX_MODULE)
317  set_source_files_properties(${CPP_FILES} PROPERTIES LANGUAGE CXX)
318  endif()
319  else()
320  set(MODULE_HEADERS_ONLY 1)
321  if(MODULE_AUTOLOAD_WITH)
322  message(SEND_ERROR "A headers only module cannot be auto-loaded")
323  endif()
324  endif()
325 
326  set(module_c_flags )
327  set(module_c_flags_debug )
328  set(module_c_flags_release )
329  set(module_cxx_flags )
330  set(module_cxx_flags_debug )
331  set(module_cxx_flags_release )
332 
333  if(MODULE_GCC_DEFAULT_VISIBILITY OR NOT CMAKE_COMPILER_IS_GNUCXX)
334  # We only support hidden visibility for gcc for now. Clang still has troubles with
335  # correctly marking template declarations and explicit template instantiations as exported.
336  # See http://comments.gmane.org/gmane.comp.compilers.clang.scm/50028
337  # and http://llvm.org/bugs/show_bug.cgi?id=10113
338  set(CMAKE_CXX_VISIBILITY_PRESET default)
339  set(CMAKE_VISIBILITY_INLINES_HIDDEN 0)
340  else()
341  set(CMAKE_CXX_VISIBILITY_PRESET hidden)
342  set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
343  endif()
344 
345  if(NOT MODULE_WARNINGS_NO_ERRORS)
346  if(MSVC_VERSION)
347  mitkFunctionCheckCAndCXXCompilerFlags("/WX" module_c_flags module_cxx_flags)
348  # this would turn on unused parameter warnings, but unfortunately MSVC cannot
349  # distinguish yet between internal and external headers so this would be triggered
350  # a lot by external code. There is support for it on the way so this line could be
351  # reactivated after https://gitlab.kitware.com/cmake/cmake/issues/17904 has been fixed.
352  # mitkFunctionCheckCAndCXXCompilerFlags("/w34100" module_c_flags module_cxx_flags)
353  else()
354  mitkFunctionCheckCAndCXXCompilerFlags(-Werror module_c_flags module_cxx_flags)
355 
356  # The flag "c++0x-static-nonintegral-init" has been renamed in newer Clang
357  # versions to "static-member-init", see
358  # http://clang-developers.42468.n3.nabble.com/Wc-0x-static-nonintegral-init-gone-td3999651.html
359  #
360  # Also, older Clang and seemingly all gcc versions do not warn if unknown
361  # "-no-*" flags are used, so CMake will happily append any -Wno-* flag to the
362  # command line. This may get confusing if unrelated compiler errors happen and
363  # the error output then additionally contains errors about unknown flags (which
364  # is not the case if there were no compile errors).
365  #
366  # So instead of using -Wno-* we use -Wno-error=*, which will be properly rejected by
367  # the compiler and if applicable, prints the specific warning as a real warning and
368  # not as an error (although -Werror was given).
369 
370  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=c++0x-static-nonintegral-init" module_c_flags module_cxx_flags)
371  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=static-member-init" module_c_flags module_cxx_flags)
372  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=unknown-warning" module_c_flags module_cxx_flags)
373  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=gnu" module_c_flags module_cxx_flags)
374  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=class-memaccess" module_c_flags module_cxx_flags)
375  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=inconsistent-missing-override" module_c_flags module_cxx_flags)
376  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=deprecated-copy" module_c_flags module_cxx_flags)
377  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=cast-function-type" module_c_flags module_cxx_flags)
378  endif()
379  endif()
380 
381  if(MODULE_FORCE_STATIC)
382  set(_STATIC STATIC)
383  else()
384  set(_STATIC )
385  endif(MODULE_FORCE_STATIC)
386 
387  if(NOT MODULE_HEADERS_ONLY)
388  if(NOT MODULE_NO_INIT OR RESOURCE_FILES)
389  find_package(CppMicroServices QUIET NO_MODULE REQUIRED)
390  endif()
391  if(NOT MODULE_NO_INIT)
392  usFunctionGenerateModuleInit(CPP_FILES)
393  endif()
394 
395  set(binary_res_files )
396  set(source_res_files )
397  if(RESOURCE_FILES)
398  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/resource")
399  set(res_dir resource)
400  elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Resources")
401  set(res_dir Resources)
402  else()
403  message(SEND_ERROR "Resources specified but ${CMAKE_CURRENT_SOURCE_DIR}/resource directory not found.")
404  endif()
405  foreach(res_file ${RESOURCE_FILES})
406  if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${res_dir}/${res_file})
407  list(APPEND binary_res_files "${res_file}")
408  else()
409  list(APPEND source_res_files "${res_file}")
410  endif()
411  endforeach()
412 
413  # Add a source level dependencies on resource files
414  usFunctionGetResourceSource(TARGET ${MODULE_TARGET} OUT CPP_FILES)
415  endif()
416  endif()
417 
418  if(MITK_USE_Qt5)
419  if(UI_FILES)
420  qt5_wrap_ui(Q${KITNAME}_GENERATED_UI_CPP ${UI_FILES})
421  endif()
422  if(MOC_H_FILES)
423  qt5_wrap_cpp(Q${KITNAME}_GENERATED_MOC_CPP ${MOC_H_FILES} OPTIONS -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
424  endif()
425  if(QRC_FILES)
426  qt5_add_resources(Q${KITNAME}_GENERATED_QRC_CPP ${QRC_FILES})
427  endif()
428  endif()
429 
430  set(Q${KITNAME}_GENERATED_CPP ${Q${KITNAME}_GENERATED_CPP} ${Q${KITNAME}_GENERATED_UI_CPP} ${Q${KITNAME}_GENERATED_MOC_CPP} ${Q${KITNAME}_GENERATED_QRC_CPP})
431 
432  mitkFunctionOrganizeSources(
433  SOURCE ${CPP_FILES}
434  HEADER ${H_FILES}
435  TXX ${TXX_FILES}
436  DOC ${DOX_FILES}
437  UI ${UI_FILES}
438  QRC ${QRC_FILES}
439  MOC ${Q${KITNAME}_GENERATED_MOC_CPP}
440  GEN_QRC ${Q${KITNAME}_GENERATED_QRC_CPP}
441  GEN_UI ${Q${KITNAME}_GENERATED_UI_CPP}
442  )
443 
444  set(coverage_sources
445  ${CPP_FILES} ${H_FILES} ${GLOBBED__H_FILES} ${CORRESPONDING__H_FILES} ${TXX_FILES}
446  ${TOOL_CPPS} ${TOOL_GUI_CPPS})
447 
448  if(MODULE_SUBPROJECTS)
449  set_property(SOURCE ${coverage_sources} APPEND PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK)
450  endif()
451 
452  # ---------------------------------------------------------------
453  # Create the actual module target
454 
455  if(MODULE_HEADERS_ONLY)
456  add_library(${MODULE_TARGET} INTERFACE)
457  set_property(TARGET ${MODULE_TARGET} PROPERTY FOLDER "${MITK_ROOT_FOLDER}/Modules")
458  else()
459  if(MODULE_EXECUTABLE)
460  add_executable(${MODULE_TARGET}
461  ${MODULE_CPP_FILES} ${coverage_sources} ${CPP_FILES_GENERATED} ${Q${KITNAME}_GENERATED_CPP}
462  ${DOX_FILES} ${UI_FILES} ${QRC_FILES})
463  set_property(TARGET ${MODULE_TARGET} PROPERTY FOLDER "${MITK_ROOT_FOLDER}/Modules/Executables")
464  set(_us_module_name main)
465  else()
466  add_library(${MODULE_TARGET} ${_STATIC}
467  ${coverage_sources} ${CPP_FILES_GENERATED} ${Q${KITNAME}_GENERATED_CPP}
468  ${DOX_FILES} ${UI_FILES} ${QRC_FILES})
469  set_property(TARGET ${MODULE_TARGET} PROPERTY FOLDER "${MITK_ROOT_FOLDER}/Modules")
470  set(_us_module_name ${MODULE_TARGET})
471  endif()
472 
473  # Apply properties to the module target.
474  target_compile_definitions(${MODULE_TARGET} PRIVATE US_MODULE_NAME=${_us_module_name})
475  if(MODULE_C_MODULE)
476  if(module_c_flags)
477  string(REPLACE " " ";" module_c_flags "${module_c_flags}")
478  target_compile_options(${MODULE_TARGET} PRIVATE ${module_c_flags})
479  endif()
480  if(module_c_flags_debug)
481  string(REPLACE " " ";" module_c_flags_debug "${module_c_flags_debug}")
482  target_compile_options(${MODULE_TARGET} PRIVATE $<$<CONFIG:Debug>:${module_c_flags_debug}>)
483  endif()
484  if(module_c_flags_release)
485  string(REPLACE " " ";" module_c_flags_release "${module_c_flags_release}")
486  target_compile_options(${MODULE_TARGET} PRIVATE $<$<CONFIG:Release>:${module_c_flags_release}>)
487  endif()
488  else()
489  if(module_cxx_flags)
490  string(REPLACE " " ";" module_cxx_flags "${module_cxx_flags}")
491  target_compile_options(${MODULE_TARGET} PRIVATE ${module_cxx_flags})
492  endif()
493  if(module_cxx_flags_debug)
494  string(REPLACE " " ";" module_cxx_flags_debug "${module_cxx_flags_debug}")
495  target_compile_options(${MODULE_TARGET} PRIVATE $<$<CONFIG:Debug>:${module_cxx_flags_debug}>)
496  endif()
497  if(module_cxx_flags_release)
498  string(REPLACE " " ";" module_cxx_flags_release "${module_cxx_flags_release}")
499  target_compile_options(${MODULE_TARGET} PRIVATE $<$<CONFIG:Release>:${module_cxx_flags_release}>)
500  endif()
501  endif()
502 
503  set_property(TARGET ${MODULE_TARGET} PROPERTY US_MODULE_NAME ${_us_module_name})
504 
505  # Add additional library search directories to a global property which
506  # can be evaluated by other CMake macros, e.g. our install scripts.
507  if(MODULE_ADDITIONAL_LIBS)
508  target_link_libraries(${MODULE_TARGET} PRIVATE ${MODULE_ADDITIONAL_LIBS})
509  get_property(_mitk_additional_library_search_paths GLOBAL PROPERTY MITK_ADDITIONAL_LIBRARY_SEARCH_PATHS)
510  foreach(_lib_filepath ${MODULE_ADDITIONAL_LIBS})
511  get_filename_component(_search_path "${_lib_filepath}" PATH)
512  if(_search_path)
513  list(APPEND _mitk_additional_library_search_paths "${_search_path}")
514  endif()
515  endforeach()
516  if(_mitk_additional_library_search_paths)
517  list(REMOVE_DUPLICATES _mitk_additional_library_search_paths)
518  set_property(GLOBAL PROPERTY MITK_ADDITIONAL_LIBRARY_SEARCH_PATHS ${_mitk_additional_library_search_paths})
519  endif()
520  endif()
521 
522  # add the target name to a global property which is used in the top-level
523  # CMakeLists.txt file to export the target
524  set_property(GLOBAL APPEND PROPERTY MITK_MODULE_TARGETS ${MODULE_TARGET})
525  if(MODULE_AUTOLOAD_WITH)
526  # for auto-loaded modules, adapt the output directory
527  add_dependencies(${_module_autoload_meta_target} ${MODULE_TARGET})
528  if(WIN32)
529  set(_module_output_prop RUNTIME_OUTPUT_DIRECTORY)
530  else()
531  set(_module_output_prop LIBRARY_OUTPUT_DIRECTORY)
532  endif()
533  set(_module_output_dir ${CMAKE_${_module_output_prop}}/${MODULE_AUTOLOAD_WITH})
534  get_target_property(_module_is_imported ${MODULE_AUTOLOAD_WITH} IMPORTED)
535  if(NOT _module_is_imported)
536  # if the auto-loading module is not imported, get its location
537  # and put the auto-load module relative to it.
538  get_target_property(_module_output_dir ${MODULE_AUTOLOAD_WITH} ${_module_output_prop})
539  set_target_properties(${MODULE_TARGET} PROPERTIES
540  ${_module_output_prop} ${_module_output_dir}/${MODULE_AUTOLOAD_WITH})
541  else()
542  set_target_properties(${MODULE_TARGET} PROPERTIES
543  ${_module_output_prop} ${CMAKE_${_module_output_prop}}/${MODULE_AUTOLOAD_WITH})
544  endif()
545  set_target_properties(${MODULE_TARGET} PROPERTIES
546  MITK_AUTOLOAD_DIRECTORY ${MODULE_AUTOLOAD_WITH})
547 
548  # add the auto-load module name as a property
549  set_property(TARGET ${MODULE_AUTOLOAD_WITH} APPEND PROPERTY MITK_AUTOLOAD_TARGETS ${MODULE_TARGET})
550  endif()
551 
552  if(binary_res_files)
553  usFunctionAddResources(TARGET ${MODULE_TARGET}
554  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${res_dir}
555  FILES ${binary_res_files})
556  endif()
557  if(source_res_files)
558  usFunctionAddResources(TARGET ${MODULE_TARGET}
559  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${res_dir}
560  FILES ${source_res_files})
561  endif()
562  if(binary_res_files OR source_res_files)
563  usFunctionEmbedResources(TARGET ${MODULE_TARGET})
564  endif()
565 
566  if(MODULE_DEPRECATED_SINCE)
567  set_property(TARGET ${MODULE_TARGET} PROPERTY MITK_MODULE_DEPRECATED_SINCE ${MODULE_DEPRECATED_SINCE})
568  endif()
569 
570  # create export macros
571  if (NOT MODULE_EXECUTABLE)
572  set(_export_macro_name )
573  if(MITK_LEGACY_EXPORT_MACRO_NAME)
574  set(_export_macro_names
575  EXPORT_MACRO_NAME ${MODULE_EXPORT_DEFINE}
576  NO_EXPORT_MACRO_NAME ${MODULE_NAME}_NO_EXPORT
577  DEPRECATED_MACRO_NAME ${MODULE_NAME}_DEPRECATED
578  NO_DEPRECATED_MACRO_NAME ${MODULE_NAME}_NO_DEPRECATED
579  )
580  endif()
581  generate_export_header(${MODULE_NAME}
582  ${_export_macro_names}
583  EXPORT_FILE_NAME ${MODULE_NAME}Exports.h
584  )
585  endif()
586 
587  target_include_directories(${MODULE_TARGET} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
588 
589  endif()
590 
591  # ---------------------------------------------------------------
592  # Properties for both header-only and compiled modules
593 
594  if(MODULE_HEADERS_ONLY)
595  set(_module_property_type INTERFACE)
596  else()
597  set(_module_property_type PUBLIC)
598  endif()
599 
600  if(MODULE_TARGET_DEPENDS)
601  add_dependencies(${MODULE_TARGET} ${MODULE_TARGET_DEPENDS})
602  endif()
603 
604  if(MODULE_SUBPROJECTS AND NOT MODULE_HEADERS_ONLY)
605  set_property(TARGET ${MODULE_TARGET} PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK)
606  foreach(subproject ${MODULE_SUBPROJECTS})
607  add_dependencies(${subproject} ${MODULE_TARGET})
608  endforeach()
609  endif()
610 
611  set(DEPENDS "${MODULE_DEPENDS}")
612  if(NOT MODULE_NO_INIT AND NOT MODULE_HEADERS_ONLY)
613  # Add a CppMicroServices dependency implicitly, since it is
614  # needed for the generated "module initialization" code.
615  set(DEPENDS "CppMicroServices;${DEPENDS}")
616  endif()
617  if(DEPENDS OR MODULE_PACKAGE_DEPENDS)
618  mitk_use_modules(TARGET ${MODULE_TARGET}
619  MODULES ${DEPENDS}
620  PACKAGES ${MODULE_PACKAGE_DEPENDS}
621  )
622  endif()
623 
624  if(NOT MODULE_C_MODULE)
625  target_compile_features(${MODULE_TARGET} ${_module_property_type} ${MITK_CXX_FEATURES})
626  endif()
627 
628  # add include directories
629  if(MODULE_INTERNAL_INCLUDE_DIRS)
630  target_include_directories(${MODULE_TARGET} PRIVATE ${MODULE_INTERNAL_INCLUDE_DIRS})
631  endif()
632  if(NOT MODULE_NO_DEFAULT_INCLUDE_DIRS)
633  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include)
634  target_include_directories(${MODULE_TARGET} ${_module_property_type} include)
635  else()
636  target_include_directories(${MODULE_TARGET} ${_module_property_type} .)
637  endif()
638  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src)
639  target_include_directories(${MODULE_TARGET} PRIVATE src)
640  endif()
641  endif()
642  target_include_directories(${MODULE_TARGET} ${_module_property_type} ${MODULE_INCLUDE_DIRS})
643 
644  endif()
645 
646  # -----------------------------------------------------------------
647  # Record missing dependency information
648 
649  if(_MISSING_DEP)
650  if(MODULE_DESCRIPTION)
651  set(MODULE_DESCRIPTION "${MODULE_DESCRIPTION} (missing dependencies: ${_MISSING_DEP})")
652  else()
653  set(MODULE_DESCRIPTION "(missing dependencies: ${_MISSING_DEP})")
654  endif()
655  endif()
656  if(NOT MODULE_NO_FEATURE_INFO)
657  add_feature_info(${MODULE_NAME} MODULE_IS_ENABLED "${MODULE_DESCRIPTION}")
658  endif()
659 
660  set(MODULE_NAME ${MODULE_NAME} PARENT_SCOPE)
661  set(MODULE_TARGET ${MODULE_TARGET} PARENT_SCOPE)
662  set(MODULE_IS_ENABLED ${MODULE_IS_ENABLED} PARENT_SCOPE)
663  set(MODULE_SUBPROJECTS ${MODULE_SUBPROJECTS} PARENT_SCOPE)
664 
665 endfunction()
mitk_create_module()
static const unsigned int unknown
Unknown size marker.
Definition: jsoncpp.cpp:1583
#define DEPRECATED(func)
Definition: mitkCommon.h:179