SlicerTools.cmake
Go to the documentation of this file.
1 # ============================================================================
2 # Copyright (c) 2011-2012 University of Pennsylvania
3 # Copyright (c) 2013-2016 Andreas Schuh
4 # All rights reserved.
5 #
6 # See COPYING file for license information or visit
7 # https://cmake-basis.github.io/download.html#license
8 # ============================================================================
9 
10 ##############################################################################
11 # @file SlicerTools.cmake
12 # @brief Definition of tools for Slicer Extensions.
13 ##############################################################################
14 
15 # ----------------------------------------------------------------------------
16 # include guard
18  return ()
19 else ()
21 endif ()
22 
23 # ============================================================================
24 # meta-data
25 # ============================================================================
26 
27 # ----------------------------------------------------------------------------
28 ## @brief Define project meta-data of Slicer module.
29 #
30 # This macro should be used instead of basis_project() for a Slicer module.
31 # It extends the considered meta-data by some additional variables that
32 # have to be set for a Slicer module and identifies this project as a Slicer
33 # module.
34 #
35 # @ingroup CMakeAPI
36 macro (basis_slicer_module)
37  CMAKE_PARSE_ARGUMENTS (
38  PROJECT
40  "${BASIS_METADATA_LIST_SINGLE};${BASIS_SLICER_METADATA_LIST_SINGLE}"
41  "${BASIS_METADATA_LIST_MULTI};${BASIS_SLICER_METADATA_LIST_MULTI}"
42  ${ARGN}
43  )
44  foreach (_L IN LISTS BASIS_SLICER_METADATA_LIST_MULTI)
45  if (_L MATCHES "^(CATEGORY|CONTRIBUTORS)$")
46  basis_list_to_delimited_string (PROJECT_${_L} ", " ${PROJECT_${_L}})
47  else ()
48  basis_list_to_string (PROJECT_${_L} ${PROJECT_${_L}})
49  endif ()
50  endforeach ()
51  set (PROJECT_IS_SLICER_MODULE TRUE)
52  basis_project_check_metadata ()
53 endmacro ()
54 
55 
56 ## @addtogroup CMakeUtilities
57 # @{
58 
59 
60 # ============================================================================
61 # initialization
62 # ============================================================================
63 
64 # ----------------------------------------------------------------------------
65 ## @brief Initialize slicer module meta-data.
66 #
67 # At the moment, only one module, most often the top-level project can be a
68 # Slicer module, i.e., call basis_slicer_module() either in the
69 # BasisProject.cmake file of the top-level project or in the corresponding file
70 # of at most one of the project modules.
71 macro (basis_slicer_module_initialize)
72  if (NOT PROJECT_IS_MODULE)
73  set (_N 0)
74  foreach (_M IN LISTS PROJECT_MODULES_ENABLED)
75  if (${_M}_IS_SLICER_MODULE)
76  math (EXPR _N "${_N} + 1")
77  endif ()
78  endforeach ()
79  if (PROJECT_IS_SLICER_MODULE)
80  if (_N GREATER 0)
81  message (FATAL_ERROR "BASIS does not support projects with multiple Slicer modules!")
82  endif ()
83  set (_FIND_SLICER TRUE)
84  elseif (_N GREATER 0)
85  if (_N GREATER 1)
86  message (FATAL_ERROR "BASIS does not support projects with multiple Slicer modules!")
87  endif ()
88  set (_FIND_SLICER TRUE)
89  else ()
90  set (_FIND_SLICER FALSE)
91  endif ()
92  # convert PROJECT_* or <Module>_* to MODULE_* variables
93  if (PROJECT_IS_SLICER_MODULE)
94  foreach (_D IN LISTS BASIS_SLICER_METADATA_LIST)
95  if (DEFINED PROJECT_${_D})
96  set (MODULE_${_D} "${PROJECT_${_D}}")
97  endif ()
98  endforeach ()
99  else ()
100  foreach (_M IN LISTS PROJECT_MODULES_ENABLED)
101  if (${_M}_IS_SLICER_MODULE)
102  foreach (_D IN LISTS BASIS_SLICER_METADATA_LIST)
103  if (DEFINED ${_M}_${_D})
104  set (MODULE_${_D} "${${_M}_${_D}}")
105  endif ()
106  endforeach ()
107  break ()
108  endif ()
109  endforeach ()
110  endif ()
111  # find Slicer package
112  if (_FIND_SLICER)
113  # set metadata
114  set (MODULE_DESCRIPTION "${PROJECT_DESCRIPTION}")
115  set (MODULE_NAME "${PROJECT_NAME}")
116  set (MODULE_README_FILE "${PROJECT_SOURCE_DIR}/README.txt")
117  set (MODULE_LICENSE_FILE "${PROJECT_SOURCE_DIR}/COPYING.txt")
118  set (MODULE_MAJOR_VERSION "${PROJECT_VERSION_MAJOR}")
119  set (MODULE_MINOR_VERSION "${PROJECT_VERSION_MINOR}")
120  set (MODULE_PATCH_VERSION "${PROJECT_VERSION_PATCH}")
121  # skip project() command
122  set (Slicer_SKIP_PROJECT_COMMAND TRUE)
123  set (Slicer_SKIP_USE_FILE_INCLUDE_CHECK TRUE)
124  # work-around for bug 1901 in Slicer 4.1.0
125  set (Slicer_SKIP_SlicerBlockModuleToExtensionMetadata TRUE)
126  basis_slicer_module_to_extension_metadata ()
127  # find Slicer
128  basis_find_package (Slicer REQUIRED)
129  basis_use_package (Slicer REQUIRED)
130  endif ()
131  unset (_M)
132  unset (_N)
133  unset (_FIND_SLICER)
134  endif ()
135 endmacro ()
136 
137 # ============================================================================
138 # auxiliary functions
139 # ============================================================================
140 
141 # ----------------------------------------------------------------------------
142 ## @brief Copy MODULE_* metadata to EXTENSION_* metadata of Slicer Extension.
143 #
144 # This function is required to work-around bug 1901 in Slicer 4.1.0. It basically
145 # implements what the SlicerBlockModuleToExtensionMetadata.cmake module which
146 # can be found in the Extensions/CMake/ directory of the Slicer 4 source tree
147 # is implementing. The list of metadata has been copied from this particular
148 # CMake module of the 4.1.0 release of Slicer.
149 #
150 # @sa http://www.na-mic.org/Bug/view.php?id=1901
151 function (basis_slicer_module_to_extension_metadata)
152  foreach (varname IN ITEMS ${BASIS_SLICER_METADATA_LIST} DESCRIPTION)
153  if (DEFINED MODULE_${varname} AND NOT DEFINED EXTENSION_${varname})
154  set (EXTENSION_${varname} ${MODULE_${varname}} PARENT_SCOPE)
155  endif ()
156  endforeach ()
157 endfunction ()
158 
159 
160 ## @}
161 # Doxygen group CMakeUtilities
string PROJECT
Project name.
Definition: utilities.sh:79
BASIS_METADATA_LIST_SWITCH
Names of project meta-data switches.
cmake __BASIS_SLICERTOOLS_INCLUDED
macro basis_slicer_module()
Define project meta-data of Slicer module.