Medical Imaging Interaction Toolkit  2016.11.0
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 #! WARNINGS_AS_ERRORS
16 #! \endcode
17 #!
18 #! The <moduleName> parameter specifies the name of the module which is used
19 #! to create a logical target name. The parameter is optional in case the
20 #! MITK_MODULE_NAME_DEFAULTS_TO_DIRECTORY_NAME variable evaluates to TRUE. The
21 #! module name will then be derived from the directory name in which this
22 #! function is called.
23 #!
24 #! If set, the following variables will be used to validate the module name:
25 #!
26 #! MITK_MODULE_NAME_REGEX_MATCH The module name must match this regular expression.
27 #! MITK_MODULE_NAME_REGEX_NOT_MATCH The module name must not match this regular expression.
28 #!
29 #! If the MITK_MODULE_NAME_PREFIX variable is set, the module name will be prefixed
30 #! with its contents.
31 #!
32 #! A modules source files are specified in a separate CMake file usually
33 #! called files.cmake, located in the module root directory. The
34 #! mitk_create_module() macro evaluates the following CMake variables
35 #! from the files.cmake file:
36 #!
37 #! - CPP_FILES A list of .cpp files
38 #! - H_FILES A list of .h files without a corresponding .cpp file
39 #! - TXX_FILES A list of .txx files
40 #! - RESOURCE_FILES A list of files (resources) which are embedded into the module
41 #! - MOC_H_FILES A list of Qt header files which should be processed by the MOC
42 #! - UI_FILES A list of .ui Qt UI files
43 #! - QRC_FILES A list of .qrc Qt resource files
44 #! - DOX_FILES A list of .dox Doxygen files
45 #!
46 #! List of variables available after the function is called:
47 #! - MODULE_NAME
48 #! - MODULE_TARGET
49 #! - MODULE_IS_ENABLED
50 #! - MODULE_SUBPROJECTS
51 #!
52 #! \sa mitk_create_executable
53 #!
54 #! Parameters (all optional):
55 #!
56 #! \param <moduleName> The module name (also used as target name)
57 #! \param FILES_CMAKE File name of a CMake file setting source list variables
58 #! (defaults to files.cmake)
59 #! \param VERSION Module version number, e.g. "1.2.0"
60 #! \param AUTOLOAD_WITH A module target name identifying the module which will
61 #! trigger the automatic loading of this module
62 #! \param DEPRECATED_SINCE Marks this modules as deprecated since <arg>
63 #! \param DESCRIPTION A description for this module
64 #!
65 #! Multi-value Parameters (all optional):
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_AS_ERRORS 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_AS_ERRORS # treat all 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  endif()
195  endif()
196 
197  # check if the subprojects exist as targets
198  if(MODULE_SUBPROJECTS)
199  foreach(subproject ${MODULE_SUBPROJECTS})
200  if(NOT TARGET ${subproject})
201  message(SEND_ERROR "The subproject ${subproject} does not have a corresponding target")
202  endif()
203  endforeach()
204  endif()
205 
206  # -----------------------------------------------------------------
207  # Check if module should be build
208 
209  set(MODULE_TARGET ${MODULE_NAME})
210 
211  # assume worst case
212  set(MODULE_IS_ENABLED 0)
213  # first we check if we have an explicit module build list
214  if(MITK_MODULES_TO_BUILD)
215  list(FIND MITK_MODULES_TO_BUILD ${MODULE_NAME} _MOD_INDEX)
216  if(_MOD_INDEX EQUAL -1)
217  set(MODULE_IS_EXCLUDED 1)
218  endif()
219  endif()
220 
221  if(NOT MODULE_IS_EXCLUDED)
222  # first of all we check for the dependencies
223  _mitk_parse_package_args(${MODULE_PACKAGE_DEPENDS})
224  mitk_check_module_dependencies(MODULES ${MODULE_DEPENDS}
225  PACKAGES ${PACKAGE_NAMES}
226  MISSING_DEPENDENCIES_VAR _MISSING_DEP
227  PACKAGE_DEPENDENCIES_VAR PACKAGE_NAMES)
228 
229  if(_MISSING_DEP)
230  if(MODULE_NO_FEATURE_INFO)
231  message("${_Module_type} ${MODULE_NAME} won't be built, missing dependency: ${_MISSING_DEP}")
232  endif()
233  set(MODULE_IS_ENABLED 0)
234  else()
235  set(MODULE_IS_ENABLED 1)
236  # now check for every package if it is enabled. This overlaps a bit with
237  # MITK_CHECK_MODULE ...
238  foreach(_package ${PACKAGE_NAMES})
239  if((DEFINED MITK_USE_${_package}) AND NOT (MITK_USE_${_package}))
240  message("${_Module_type} ${MODULE_NAME} won't be built. Turn on MITK_USE_${_package} if you want to use it.")
241  set(MODULE_IS_ENABLED 0)
242  break()
243  endif()
244  endforeach()
245  endif()
246  endif()
247 
248  # -----------------------------------------------------------------
249  # Start creating the module
250 
251  if(MODULE_IS_ENABLED)
252 
253  # clear variables defined in files.cmake
254  set(RESOURCE_FILES )
255  set(CPP_FILES )
256  set(H_FILES )
257  set(TXX_FILES )
258  set(DOX_FILES )
259  set(UI_FILES )
260  set(MOC_H_FILES )
261  set(QRC_FILES )
262 
263  # clear other variables
264  set(Q${KITNAME}_GENERATED_CPP )
265  set(Q${KITNAME}_GENERATED_MOC_CPP )
266  set(Q${KITNAME}_GENERATED_QRC_CPP )
267  set(Q${KITNAME}_GENERATED_UI_CPP )
268 
269  # check and set-up auto-loading
270  if(MODULE_AUTOLOAD_WITH)
271  if(NOT TARGET "${MODULE_AUTOLOAD_WITH}")
272  message(SEND_ERROR "The module target \"${MODULE_AUTOLOAD_WITH}\" specified as the auto-loading module for \"${MODULE_NAME}\" does not exist")
273  endif()
274  endif()
275  set(_module_autoload_meta_target "${CMAKE_PROJECT_NAME}-autoload")
276  # create a meta-target if it does not already exist
277  if(NOT TARGET ${_module_autoload_meta_target})
278  add_custom_target(${_module_autoload_meta_target})
279  endif()
280 
281  if(NOT MODULE_EXPORT_DEFINE)
282  set(MODULE_EXPORT_DEFINE ${MODULE_NAME}_EXPORT)
283  endif()
284 
285  if(MITK_GENERATE_MODULE_DOT)
286  message("MODULEDOTNAME ${MODULE_NAME}")
287  foreach(dep ${MODULE_DEPENDS})
288  message("MODULEDOT \"${MODULE_NAME}\" -> \"${dep}\" ; ")
289  endforeach(dep)
290  endif(MITK_GENERATE_MODULE_DOT)
291 
292  if (EXISTS ${MODULE_FILES_CMAKE})
293  include(${MODULE_FILES_CMAKE})
294  endif()
295 
296  if(MODULE_CPP_FILES)
297  list(APPEND CPP_FILES ${MODULE_CPP_FILES})
298  endif()
299 
300  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src")
301  # Preprend the "src" directory to the cpp file list
302  set(_cpp_files ${CPP_FILES})
303  set(CPP_FILES )
304  foreach(_cpp_file ${_cpp_files})
305  list(APPEND CPP_FILES "src/${_cpp_file}")
306  endforeach()
307  endif()
308 
309  if(CPP_FILES OR RESOURCE_FILES OR UI_FILES OR MOC_H_FILES OR QRC_FILES)
310  set(MODULE_HEADERS_ONLY 0)
311  if(MODULE_C_MODULE)
312  set_source_files_properties(${CPP_FILES} PROPERTIES LANGUAGE C)
313  elseif(MODULE_CXX_MODULE)
314  set_source_files_properties(${CPP_FILES} PROPERTIES LANGUAGE CXX)
315  endif()
316  else()
317  set(MODULE_HEADERS_ONLY 1)
318  if(MODULE_AUTOLOAD_WITH)
319  message(SEND_ERROR "A headers only module cannot be auto-loaded")
320  endif()
321  endif()
322 
323  set(module_c_flags )
324  set(module_c_flags_debug )
325  set(module_c_flags_release )
326  set(module_cxx_flags )
327  set(module_cxx_flags_debug )
328  set(module_cxx_flags_release )
329 
330  if(MODULE_GCC_DEFAULT_VISIBILITY OR NOT CMAKE_COMPILER_IS_GNUCXX)
331  # We only support hidden visibility for gcc for now. Clang still has troubles with
332  # correctly marking template declarations and explicit template instantiations as exported.
333  # See http://comments.gmane.org/gmane.comp.compilers.clang.scm/50028
334  # and http://llvm.org/bugs/show_bug.cgi?id=10113
335  set(CMAKE_CXX_VISIBILITY_PRESET default)
336  set(CMAKE_VISIBILITY_INLINES_HIDDEN 0)
337  else()
338  set(CMAKE_CXX_VISIBILITY_PRESET hidden)
339  set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
340  endif()
341 
342  if(MODULE_WARNINGS_AS_ERRORS)
343  if(MSVC_VERSION)
344  mitkFunctionCheckCAndCXXCompilerFlags("/WX" module_c_flags module_cxx_flags)
345  else()
346  mitkFunctionCheckCAndCXXCompilerFlags(-Werror module_c_flags module_cxx_flags)
347 
348  # The flag "c++0x-static-nonintegral-init" has been renamed in newer Clang
349  # versions to "static-member-init", see
350  # http://clang-developers.42468.n3.nabble.com/Wc-0x-static-nonintegral-init-gone-td3999651.html
351  #
352  # Also, older Clang and seemingly all gcc versions do not warn if unknown
353  # "-no-*" flags are used, so CMake will happily append any -Wno-* flag to the
354  # command line. This may get confusing if unrelated compiler errors happen and
355  # the error output then additionally contains errors about unknown flags (which
356  # is not the case if there were no compile errors).
357  #
358  # So instead of using -Wno-* we use -Wno-error=*, which will be properly rejected by
359  # the compiler and if applicable, prints the specific warning as a real warning and
360  # not as an error (although -Werror was given).
361 
362  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=c++0x-static-nonintegral-init" module_c_flags module_cxx_flags)
363  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=static-member-init" module_c_flags module_cxx_flags)
364  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=unknown-warning" module_c_flags module_cxx_flags)
365  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=gnu" module_c_flags module_cxx_flags)
366  mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=inconsistent-missing-override" module_c_flags module_cxx_flags)
367  endif()
368  endif(MODULE_WARNINGS_AS_ERRORS)
369 
370  if(MODULE_FORCE_STATIC)
371  set(_STATIC STATIC)
372  else()
373  set(_STATIC )
374  endif(MODULE_FORCE_STATIC)
375 
376  if(NOT MODULE_HEADERS_ONLY)
377  if(NOT MODULE_NO_INIT OR RESOURCE_FILES)
378  find_package(CppMicroServices QUIET NO_MODULE REQUIRED)
379  endif()
380  if(NOT MODULE_NO_INIT)
381  usFunctionGenerateModuleInit(CPP_FILES)
382  endif()
383 
384  set(binary_res_files )
385  set(source_res_files )
386  if(RESOURCE_FILES)
387  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/resource")
388  set(res_dir resource)
389  elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Resources")
390  set(res_dir Resources)
391  else()
392  message(SEND_ERROR "Resources specified but ${CMAKE_CURRENT_SOURCE_DIR}/resource directory not found.")
393  endif()
394  foreach(res_file ${RESOURCE_FILES})
395  if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${res_dir}/${res_file})
396  list(APPEND binary_res_files "${res_file}")
397  else()
398  list(APPEND source_res_files "${res_file}")
399  endif()
400  endforeach()
401 
402  # Add a source level dependencies on resource files
403  usFunctionGetResourceSource(TARGET ${MODULE_TARGET} OUT CPP_FILES)
404  endif()
405  endif()
406 
407  if(MITK_USE_Qt5)
408  if(UI_FILES)
409  qt5_wrap_ui(Q${KITNAME}_GENERATED_UI_CPP ${UI_FILES})
410  endif()
411  if(MOC_H_FILES)
412  qt5_wrap_cpp(Q${KITNAME}_GENERATED_MOC_CPP ${MOC_H_FILES} OPTIONS -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
413  endif()
414  if(QRC_FILES)
415  qt5_add_resources(Q${KITNAME}_GENERATED_QRC_CPP ${QRC_FILES})
416  endif()
417  endif()
418 
419  set(Q${KITNAME}_GENERATED_CPP ${Q${KITNAME}_GENERATED_CPP} ${Q${KITNAME}_GENERATED_UI_CPP} ${Q${KITNAME}_GENERATED_MOC_CPP} ${Q${KITNAME}_GENERATED_QRC_CPP})
420 
421  mitkFunctionOrganizeSources(
422  SOURCE ${CPP_FILES}
423  HEADER ${H_FILES}
424  TXX ${TXX_FILES}
425  DOC ${DOX_FILES}
426  UI ${UI_FILES}
427  QRC ${QRC_FILES}
428  MOC ${Q${KITNAME}_GENERATED_MOC_CPP}
429  GEN_QRC ${Q${KITNAME}_GENERATED_QRC_CPP}
430  GEN_UI ${Q${KITNAME}_GENERATED_UI_CPP}
431  )
432 
433  set(coverage_sources
434  ${CPP_FILES} ${H_FILES} ${GLOBBED__H_FILES} ${CORRESPONDING__H_FILES} ${TXX_FILES}
435  ${TOOL_CPPS} ${TOOL_GUI_CPPS})
436 
437  if(MODULE_SUBPROJECTS)
438  set_property(SOURCE ${coverage_sources} APPEND PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK)
439  endif()
440 
441  # ---------------------------------------------------------------
442  # Create the actual module target
443 
444  if(MODULE_HEADERS_ONLY)
445  add_library(${MODULE_TARGET} INTERFACE)
446  else()
447  if(MODULE_EXECUTABLE)
448  add_executable(${MODULE_TARGET}
449  ${MODULE_CPP_FILES} ${coverage_sources} ${CPP_FILES_GENERATED} ${Q${KITNAME}_GENERATED_CPP}
450  ${DOX_FILES} ${UI_FILES} ${QRC_FILES})
451  set(_us_module_name main)
452  else()
453  add_library(${MODULE_TARGET} ${_STATIC}
454  ${coverage_sources} ${CPP_FILES_GENERATED} ${Q${KITNAME}_GENERATED_CPP}
455  ${DOX_FILES} ${UI_FILES} ${QRC_FILES})
456  set(_us_module_name ${MODULE_TARGET})
457  endif()
458 
459  # Apply properties to the module target.
460  target_compile_definitions(${MODULE_TARGET} PRIVATE US_MODULE_NAME=${_us_module_name})
461  if(MODULE_C_MODULE)
462  if(module_c_flags)
463  string(REPLACE " " ";" module_c_flags "${module_c_flags}")
464  target_compile_options(${MODULE_TARGET} PRIVATE ${module_c_flags})
465  endif()
466  if(module_c_flags_debug)
467  string(REPLACE " " ";" module_c_flags_debug "${module_c_flags_debug}")
468  target_compile_options(${MODULE_TARGET} PRIVATE $<$<CONFIG:Debug>:${module_c_flags_debug}>)
469  endif()
470  if(module_c_flags_release)
471  string(REPLACE " " ";" module_c_flags_release "${module_c_flags_release}")
472  target_compile_options(${MODULE_TARGET} PRIVATE $<$<CONFIG:Release>:${module_c_flags_release}>)
473  endif()
474  else()
475  if(module_cxx_flags)
476  string(REPLACE " " ";" module_cxx_flags "${module_cxx_flags}")
477  target_compile_options(${MODULE_TARGET} PRIVATE ${module_cxx_flags})
478  endif()
479  if(module_cxx_flags_debug)
480  string(REPLACE " " ";" module_cxx_flags_debug "${module_cxx_flags_debug}")
481  target_compile_options(${MODULE_TARGET} PRIVATE $<$<CONFIG:Debug>:${module_cxx_flags_debug}>)
482  endif()
483  if(module_cxx_flags_release)
484  string(REPLACE " " ";" module_cxx_flags_release "${module_cxx_flags_release}")
485  target_compile_options(${MODULE_TARGET} PRIVATE $<$<CONFIG:Release>:${module_cxx_flags_release}>)
486  endif()
487  endif()
488 
489  set_property(TARGET ${MODULE_TARGET} PROPERTY US_MODULE_NAME ${_us_module_name})
490 
491  if(MINGW)
492  target_link_libraries(${MODULE_TARGET} ssp) # add stack smash protection lib
493  endif()
494 
495  # Add additional library search directories to a global property which
496  # can be evaluated by other CMake macros, e.g. our install scripts.
497  if(MODULE_ADDITIONAL_LIBS)
498  target_link_libraries(${MODULE_TARGET} PRIVATE ${MODULE_ADDITIONAL_LIBS})
499  get_property(_mitk_additional_library_search_paths GLOBAL PROPERTY MITK_ADDITIONAL_LIBRARY_SEARCH_PATHS)
500  foreach(_lib_filepath ${MODULE_ADDITIONAL_LIBS})
501  get_filename_component(_search_path "${_lib_filepath}" PATH)
502  if(_search_path)
503  list(APPEND _mitk_additional_library_search_paths "${_search_path}")
504  endif()
505  endforeach()
506  if(_mitk_additional_library_search_paths)
507  list(REMOVE_DUPLICATES _mitk_additional_library_search_paths)
508  set_property(GLOBAL PROPERTY MITK_ADDITIONAL_LIBRARY_SEARCH_PATHS ${_mitk_additional_library_search_paths})
509  endif()
510  endif()
511 
512  # add the target name to a global property which is used in the top-level
513  # CMakeLists.txt file to export the target
514  set_property(GLOBAL APPEND PROPERTY MITK_MODULE_TARGETS ${MODULE_TARGET})
515  if(MODULE_AUTOLOAD_WITH)
516  # for auto-loaded modules, adapt the output directory
517  add_dependencies(${_module_autoload_meta_target} ${MODULE_TARGET})
518  if(WIN32)
519  set(_module_output_prop RUNTIME_OUTPUT_DIRECTORY)
520  else()
521  set(_module_output_prop LIBRARY_OUTPUT_DIRECTORY)
522  endif()
523  set(_module_output_dir ${CMAKE_${_module_output_prop}}/${MODULE_AUTOLOAD_WITH})
524  get_target_property(_module_is_imported ${MODULE_AUTOLOAD_WITH} IMPORTED)
525  if(NOT _module_is_imported)
526  # if the auto-loading module is not imported, get its location
527  # and put the auto-load module relative to it.
528  get_target_property(_module_output_dir ${MODULE_AUTOLOAD_WITH} ${_module_output_prop})
529  set_target_properties(${MODULE_TARGET} PROPERTIES
530  ${_module_output_prop} ${_module_output_dir}/${MODULE_AUTOLOAD_WITH})
531  else()
532  set_target_properties(${MODULE_TARGET} PROPERTIES
533  ${_module_output_prop} ${CMAKE_${_module_output_prop}}/${MODULE_AUTOLOAD_WITH})
534  endif()
535  set_target_properties(${MODULE_TARGET} PROPERTIES
536  MITK_AUTOLOAD_DIRECTORY ${MODULE_AUTOLOAD_WITH})
537 
538  # add the auto-load module name as a property
539  set_property(TARGET ${MODULE_AUTOLOAD_WITH} APPEND PROPERTY MITK_AUTOLOAD_TARGETS ${MODULE_TARGET})
540  endif()
541 
542  if(binary_res_files)
543  usFunctionAddResources(TARGET ${MODULE_TARGET}
544  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${res_dir}
545  FILES ${binary_res_files})
546  endif()
547  if(source_res_files)
548  usFunctionAddResources(TARGET ${MODULE_TARGET}
549  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${res_dir}
550  FILES ${source_res_files})
551  endif()
552  if(binary_res_files OR source_res_files)
553  usFunctionEmbedResources(TARGET ${MODULE_TARGET})
554  endif()
555 
556  if(MODULE_DEPRECATED_SINCE)
557  set_property(TARGET ${MODULE_TARGET} PROPERTY MITK_MODULE_DEPRECATED_SINCE ${MODULE_DEPRECATED_SINCE})
558  endif()
559 
560  # create export macros
561  if (NOT MODULE_EXECUTABLE)
562  set(_export_macro_name )
563  if(MITK_LEGACY_EXPORT_MACRO_NAME)
564  set(_export_macro_names
565  EXPORT_MACRO_NAME ${MODULE_EXPORT_DEFINE}
566  NO_EXPORT_MACRO_NAME ${MODULE_NAME}_NO_EXPORT
567  DEPRECATED_MACRO_NAME ${MODULE_NAME}_DEPRECATED
568  NO_DEPRECATED_MACRO_NAME ${MODULE_NAME}_NO_DEPRECATED
569  )
570  endif()
571  generate_export_header(${MODULE_NAME}
572  ${_export_macro_names}
573  EXPORT_FILE_NAME ${MODULE_NAME}Exports.h
574  )
575  endif()
576 
577  target_include_directories(${MODULE_TARGET} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
578 
579  endif()
580 
581  # ---------------------------------------------------------------
582  # Properties for both header-only and compiled modules
583 
584  if(MODULE_HEADERS_ONLY)
585  set(_module_property_type INTERFACE)
586  else()
587  set(_module_property_type PUBLIC)
588  endif()
589 
590  if(MODULE_TARGET_DEPENDS)
591  add_dependencies(${MODULE_TARGET} ${MODULE_TARGET_DEPENDS})
592  endif()
593 
594  if(MODULE_SUBPROJECTS AND NOT MODULE_HEADERS_ONLY)
595  set_property(TARGET ${MODULE_TARGET} PROPERTY LABELS ${MODULE_SUBPROJECTS} MITK)
596  foreach(subproject ${MODULE_SUBPROJECTS})
597  add_dependencies(${subproject} ${MODULE_TARGET})
598  endforeach()
599  endif()
600 
601  set(DEPENDS "${MODULE_DEPENDS}")
602  if(NOT MODULE_NO_INIT AND NOT MODULE_HEADERS_ONLY)
603  # Add a CppMicroServices dependency implicitly, since it is
604  # needed for the generated "module initialization" code.
605  set(DEPENDS "CppMicroServices;${DEPENDS}")
606  endif()
607  if(DEPENDS OR MODULE_PACKAGE_DEPENDS)
608  mitk_use_modules(TARGET ${MODULE_TARGET}
609  MODULES ${DEPENDS}
610  PACKAGES ${MODULE_PACKAGE_DEPENDS}
611  )
612  endif()
613 
614  if(NOT MODULE_C_MODULE)
615  target_compile_features(${MODULE_TARGET} ${_module_property_type} ${MITK_CXX_FEATURES})
616  endif()
617 
618  # add include directories
619  if(MODULE_INTERNAL_INCLUDE_DIRS)
620  target_include_directories(${MODULE_TARGET} PRIVATE ${MODULE_INTERNAL_INCLUDE_DIRS})
621  endif()
622  if(NOT MODULE_NO_DEFAULT_INCLUDE_DIRS)
623  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include)
624  target_include_directories(${MODULE_TARGET} ${_module_property_type} include)
625  else()
626  target_include_directories(${MODULE_TARGET} ${_module_property_type} .)
627  endif()
628  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src)
629  target_include_directories(${MODULE_TARGET} PRIVATE src)
630  endif()
631  endif()
632  target_include_directories(${MODULE_TARGET} ${_module_property_type} ${MODULE_INCLUDE_DIRS})
633 
634  endif()
635 
636  # -----------------------------------------------------------------
637  # Record missing dependency information
638 
639  if(_MISSING_DEP)
640  if(MODULE_DESCRIPTION)
641  set(MODULE_DESCRIPTION "${MODULE_DESCRIPTION} (missing dependencies: ${_MISSING_DEP})")
642  else()
643  set(MODULE_DESCRIPTION "(missing dependencies: ${_MISSING_DEP})")
644  endif()
645  endif()
646  if(NOT MODULE_NO_FEATURE_INFO)
647  add_feature_info(${MODULE_NAME} MODULE_IS_ENABLED "${MODULE_DESCRIPTION}")
648  endif()
649 
650  set(MODULE_NAME ${MODULE_NAME} PARENT_SCOPE)
651  set(MODULE_TARGET ${MODULE_TARGET} PARENT_SCOPE)
652  set(MODULE_IS_ENABLED ${MODULE_IS_ENABLED} PARENT_SCOPE)
653  set(MODULE_SUBPROJECTS ${MODULE_SUBPROJECTS} PARENT_SCOPE)
654 
655 endfunction()
mitk_create_module()
static const unsigned int unknown
Unknown size marker.
Definition: jsoncpp.cpp:1583
static void info(const char *fmt,...)
Definition: svm.cpp:100
#define DEPRECATED(func)
Definition: mitkCommon.h:183
const std::string NAME
mitk_create_executable()