Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkFunctionCreateProvisioningFile.cmake
Go to the documentation of this file.
1 #!
2 #! \brief Create a provisioning file
3 #!
4 #! \param FILE <provisioning-file> (required) An absolute filename for
5 #! the new provisioning file.
6 #! \param INCLUDE <file-list> (optional) A list of additional provisioning files
7 #! which should be included.
8 #! \param PLUGINS <plugin-list> (optional) A list of target names for which provisioning
9 #! entries should be created. The entries must be valid targets or
10 #! be of the form [subdir/]target_name:OFF (this is the same form as
11 #! passed to the ctkMacroSetupPlugins macro) If the list is empty,
12 #! all known plug-in targets (external or internal) are considered.
13 #! \param EXCLUDE_PLUGINS <plugin-list> (optional) A list of plug-in symbolic names which should be excluded
14 #! from the provisioning entries.
15 #! \param NO_INSTALL (option) Suppress the creation of an additional provisioning file suitable for packaging.
16 #!
17 #! This function creates a provisioning file which can be used to provision a BlueBerry
18 #! application. The syntax of entries in the file is
19 #! \code
20 #! (READ|INSTALL|START) <file-url>
21 #! \endcode
22 #! READ includes the file at <file-url> and interprets it as a provisioning file, INSTALL installs <file-url>,
23 #! and START installs and starts <file-url> as a plug-in in the framework.
24 #!
25 #! <p>
26 #! For example the following provisioning file instructs the BlueBerry framework to read the entries in
27 #! a file called SomeApp.provisioning and subsequently INSTALL and START the plug-in com.mycompany.plugin
28 #! \code
29 #! READ file:
30 #! START file:
31 #! \endcode
32 #!
33 #! <p>
34 #! An example invocation of this macro may look like:
35 #! \code
36 #! set(_my_prov_file "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/MyApp.provisioning")
37 #! set(_my_plugins
38 #! com.mycompany.plugin
39 #! org.mitk.gui.qt.extapplication
40 #! )
41 #! FunctionCreateProvisioningFile(FILE ${_my_prov_file} PLUGINS ${_my_plugins})
42 #! \endcode
43 #!
44 #! \note This function will automatically create entries for all plug-in
45 #! dependencies of the specified plug-ins.
46 #!
48 
49  cmake_parse_arguments(_PROV "NO_INSTALL" "FILE" "INCLUDE;PLUGINS;EXCLUDE_PLUGINS" ${ARGN})
50 
51  if(NOT _PROV_FILE)
52  message(SEND_ERROR "FILE argument must not be empty")
53  return()
54  endif()
55 
56  set(out_var )
57  set(out_var_install )
58  if(WIN32)
59  set(file_url "file:
60  else()
61  set(file_url "file://")
62  endif()
63 
64  # Include other provisioning files
65  foreach(incl ${_PROV_INCLUDE})
66  get_filename_component(incl_filename "${incl}" NAME)
67  set(out_var "${out_var}READ ${file_url}${incl}\n")
68  set(out_var_install "${out_var_install}READ ${file_url}@EXECUTABLE_DIR/${incl_filename}\n")
69  endforeach()
70 
71  if(_PROV_INCLUDE)
72  set(out_var "${out_var}\n")
73  set(out_var_install "${out_var_install}\n")
74  endif()
75 
76  set(_plugin_list )
77  if(_PROV_PLUGINS)
78  foreach(_plugin ${_PROV_PLUGINS})
79  string(REPLACE "." "_" _plugin_target ${_plugin})
80  list(APPEND _plugin_list ${_plugin_target})
81  endforeach()
82  # get all plug-in dependencies
83  ctkFunctionGetPluginDependencies(_plugin_deps PLUGINS ${_plugin_list} ALL)
84  # add the dependencies to the list of plug-ins
85  list(APPEND _plugin_list ${_plugin_deps})
86  else()
87  # Fill the _plugin_list variable with external and internal plug-in target names.
88  ctkFunctionGetAllPluginTargets(_plugin_list)
89  endif()
90 
91  if(_plugin_list)
92  list(REMOVE_DUPLICATES _plugin_list)
93  endif()
94 
95  set(_exclude_targets )
96  if(_PROV_EXCLUDE_PLUGINS)
97  # Convert the plug-in symbolic names to valid target names
98  foreach(_exclude_entry ${_PROV_EXCLUDE_PLUGINS})
99  string(REPLACE "." "_" _exclude_target ${_exclude_entry})
100  list(APPEND _exclude_targets ${_exclude_target})
101  endforeach()
102  list(REMOVE_ITEM _plugin_list ${_exclude_targets})
103  endif()
104 
105  # Go through the list of plug-ins
106  foreach(plugin ${_plugin_list})
107  set(_plugin_target)
108  if(TARGET ${plugin})
109  # The entry already is a valid target (either imported or declared in the current project)
110  set(_plugin_target ${plugin})
111  elseif(${plugin} MATCHES "^[- :/A-Za-z0-9._]+:(ON|OFF)$")
112  # Check if the entry if of the form "Some/Dir/org.my.plugin:OPTION"
113  ctkFunctionExtractOptionNameAndValue(${plugin} plugin_name_with_dirs plugin_value)
114  string(REPLACE "/" ";" _tokens ${plugin_name_with_dirs})
115  list(GET _tokens -1 plugin_name)
116  string(REPLACE "." "_" _plugin_target_name ${plugin_name})
117  if(TARGET ${_plugin_target_name})
118  # Check if the extracted last directory entry is a valid target
119  set(_plugin_target ${_plugin_target_name})
120  endif()
121  endif()
122 
123  if(_plugin_target)
124  # We got a valid target, either imported or from this project.
125  set(_plugin_location)
126  get_target_property(_is_imported ${_plugin_target} IMPORTED)
127  if(_is_imported)
128  get_target_property(_plugin_location ${_plugin_target} IMPORTED_LOCATION)
129  if(NOT _plugin_location)
130  get_target_property(_plugin_configs ${_plugin_target} IMPORTED_CONFIGURATIONS)
131  foreach(_plugin_config ${_plugin_configs})
132  get_target_property(_plugin_location ${_plugin_target} IMPORTED_LOCATION_${_plugin_config})
133  if(_plugin_location)
134  if(CMAKE_CONFIGURATION_TYPES)
135  # Strip the last directory and filename
136  string(REGEX REPLACE "(.*)/[^/]*/[^/]*$" "\\1" _plugin_location "${_plugin_location}")
137  else()
138  # Just strip the filename
139  get_filename_component(_plugin_location "${_plugin_location}" PATH)
140  endif()
141  break()
142  endif()
143  endforeach()
144  endif()
145  else()
146  if(WIN32)
147  get_target_property(_plugin_location ${_plugin_target} RUNTIME_OUTPUT_DIRECTORY)
148  else()
149  get_target_property(_plugin_location ${_plugin_target} LIBRARY_OUTPUT_DIRECTORY)
150  endif()
151  endif()
152 
153  set(plugin_url "${file_url}${_plugin_location}/lib${_plugin_target}${CMAKE_SHARED_LIBRARY_SUFFIX}")
154  set(plugin_url_install "${file_url}@EXECUTABLE_DIR/plugins/lib${_plugin_target}${CMAKE_SHARED_LIBRARY_SUFFIX}")
155 
156  set(out_var "${out_var}START ${plugin_url}\n")
157  set(out_var_install "${out_var_install}START ${plugin_url_install}\n")
158  else()
159  #message(WARNING "Ignoring unknown plug-in target \"${plugin}\" for provisioning.")
160  endif()
161 
162  endforeach()
163 
164  file(WRITE ${_PROV_FILE} "${out_var}")
165 
166  if(NOT _PROV_NO_INSTALL)
167  file(WRITE ${_PROV_FILE}.install "${out_var_install}")
168  endif()
169 
170 endfunction()
static const unsigned int unknown
Unknown size marker.
Definition: jsoncpp.cpp:1583
mitkFunctionCreateProvisioningFile()
Create a provisioning file.
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
Definition: jsoncpp.cpp:244
const std::string NAME