Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkFunctionAddExternalProject.cmake
Go to the documentation of this file.
1 #! Register an external project.
2 #!
3 #! Calling this function registers an external project with the MITK
4 #! build system. Usage:
5 #!
6 #! mitkFunctionAddExternalProject(NAME name [ON|OFF]
7 #! [PACKAGE package] [COMPONENTS comp1...]
8 #! [DEPENDS dep1...]
9 #! [DOC docstring]
10 #! [NO_CACHE] [ADVANCED] [NO_PACKAGE]
11 #! )
12 #!
13 #! The function creates a MITK_USE_<name> internal cache variable if the
14 #! NO_CACHE option is given. If the NO_CACHE option is not set, a normal
15 #! boolean cache option is created with the given DOC argument as help string.
16 #! The option is marked as advanced if the ADVANCED option is set. The
17 #! option's initial value matches the ON or OFF option and defaults to OFF
18 #! if none is given. The DEPENDS arguments are used to force the
19 #! corresponding MITK_USE_<depN> cache variables to ON if MITK_USE_<name>
20 #! is ON.
21 #!
22 #! The PACKAGE argument names the argument for the
23 #! corresponding find_package() call in MITKs top-level CMakeLists.txt
24 #! and MITKConfig.cmake file. It defaults to <name>. If COMPONENTS are
25 #! specified, these are passed to the find_package() call. If the
26 #! NO_PACKAGE option is given, the find_package() call is suppressed.
27 #!
28 #! For each registered external project there must exist a file called
29 #! CMakeExternals/<name>.cmake which defines the build process for
30 #! the external project.
31 #!
32 #! \note Note that multiple calls of this function must be ordered
33 #! relative to their declared dependencies. This applies to the DEPENDS
34 #! arguments of this function as well as the actual target dependencies
35 #! declared in the CMakeExternals/<name>.cmake file.
36 #!
38  cmake_parse_arguments(EP "ON;OFF;NO_CACHE;ADVANCED;NO_PACKAGE" "NAME;DOC;PACKAGE" "DEPENDS;COMPONENTS" ${ARGN})
39  if(NOT EP_NAME)
40  message(SEND_ERROR "The NAME argument is missing.")
41  endif()
42  set_property(GLOBAL APPEND PROPERTY MITK_EXTERNAL_PROJECTS ${EP_NAME})
43  if(NOT EP_DOC)
44  set(EP_DOC "Use ${EP_NAME}")
45  endif()
46  if(NOT EP_PACKAGE AND NOT EP_NO_PACKAGE)
47  set(EP_PACKAGE ${EP_NAME})
48  endif()
49 
50  set(_use_var "MITK_USE_${EP_NAME}")
51  set(_on 0)
52  if(DEFINED ${_use_var})
53  set(_on ${${_use_var}})
54  else()
55  set(_on ${EP_ON})
56  endif()
57 
58  if(_on AND EP_DEPENDS)
59  # Get all transitive dependencies
60  set(_depends_all)
61  set(_depends_cur ${EP_DEPENDS})
62  list(REMOVE_DUPLICATES _depends_cur)
63  set(_depends_new ${_depends_cur})
64  while(NOT "${_depends_all}" STREQUAL "${_depends_cur}")
65  list(APPEND _depends_all ${_depends_new})
66  set(_depends_new_tmp )
67  foreach(dep ${_depends_new})
68  get_property(_dep_dep GLOBAL PROPERTY MITK_${dep}_DEPENDS)
69  list(APPEND _depends_new_tmp ${_dep_dep})
70  endforeach()
71  set(_depends_new ${_depends_new_tmp})
72  if(_depends_new)
73  list(REMOVE_DUPLICATES _depends_new)
74  list(APPEND _depends_cur ${_depends_new})
75  endif()
76  endwhile()
77  # Force dependencies to ON
78  foreach(dep ${_depends_all})
79  if(NOT MITK_USE_${dep})
80  get_property(_depends_doc CACHE MITK_USE_${dep} PROPERTY HELPSTRING)
81  get_property(_depends_type CACHE MITK_USE_${dep} PROPERTY TYPE)
82  if(NOT TYPE STREQUAL "INTERNAL")
83  # This is a cache UI variable
84  message("> Forcing MITK_USE_${dep} to ON because of ${_use_var}")
85  set(MITK_USE_${dep} ON CACHE BOOL "${_depends_doc}" FORCE)
86  else()
87  # This is an internal cache variable
88  set(MITK_USE_${dep} ON CACHE INTERNAL "${_depends_doc}" FORCE)
89  endif()
90  endif()
91  endforeach()
92  endif()
93 
94  # Set the actual MITK_USE_<name> cache variable
95  if(EP_NO_CACHE)
96  set(${_use_var} ${_on} CACHE INTERNAL "${EP_DOC}" FORCE)
97  else()
98  env_option(${_use_var} "${EP_DOC}" ${_on})
99  #set(${_use_var} ${_on} CACHE BOOL "${EP_DOC}" FORCE)
100  if(EP_ADVANCED)
101  mark_as_advanced(${_use_var})
102  endif()
103  endif()
104  set_property(GLOBAL PROPERTY MITK_${EP_NAME}_PACKAGE ${EP_PACKAGE})
105  set_property(GLOBAL PROPERTY MITK_${EP_NAME}_COMPONENTS "${EP_COMPONENTS}")
106  set_property(GLOBAL PROPERTY MITK_${EP_NAME}_DEPENDS "${EP_DEPENDS}")
107 endfunction()
mitkFunctionAddExternalProject()