Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkMacroInstall.cmake
Go to the documentation of this file.
1 #
2 # MITK specific install macro
3 #
4 # On Mac everything is installed for each bundle listed in MACOSX_BUNDLE_NAMES
5 # by replacing the DESTINATION parameter. Everything else is passed to the CMake INSTALL command
6 #
7 # Usage: MITK_INSTALL( )
8 #
9 macro(MITK_INSTALL)
10 
11  set(ARGS ${ARGN})
12 
13  set(install_directories "")
14  list(FIND ARGS DESTINATION _destination_index)
15  # set(_install_DESTINATION "")
16  if(_destination_index GREATER -1)
17  message(SEND_ERROR "MITK_INSTALL macro must not be called with a DESTINATION parameter.")
18  ### This code was a try to replace a given DESTINATION
19  #math(EXPR _destination_index ${_destination_index} + 1)
20  #list(GET ARGS ${_destination_index} _install_DESTINATION)
21  #string(REGEX REPLACE ^bin "" _install_DESTINATION ${_install_DESTINATION})
22  else()
23  if(NOT MACOSX_BUNDLE_NAMES)
24  install(${ARGS} DESTINATION bin)
25  else()
26  foreach(bundle_name ${MACOSX_BUNDLE_NAMES})
27  install(${ARGS} DESTINATION ${bundle_name}.app/Contents/MacOS/${_install_DESTINATION})
28  endforeach()
29  endif()
30  endif()
31 
32 endmacro()
33 
34 # Fix _target_location
35 # This is used in several install macros
36 macro(_fixup_target)
37 
38  if(NOT intermediate_dir)
39  if(WIN32 AND NOT MINGW)
40  set(intermediate_dir Release)
41  else()
42  set(intermediate_dir .)
43  endif()
44  endif()
45 
46  if(MITK_USE_Python)
47  set(_python_libs)
48  set(_python_search_paths)
50  mitkFunctionInstallPython(_python_libs _python_search_paths "${_bundle_dest_dir}")
51  endif()
52 
53  mitkFunctionGetLibrarySearchPaths(_search_paths ${intermediate_dir})
54 
55  install(CODE "
56 
57  set(_bundle_dest_dir \"${_bundle_dest_dir}\")
58  if(_bundle_dest_dir)
59  set(_bin_path \"\${CMAKE_INSTALL_PREFIX}/\${_bundle_dest_dir}\")
60  else()
61  set(_bin_path \"\${CMAKE_INSTALL_PREFIX}/bin\")
62  endif()
63 
64  macro(gp_item_default_embedded_path_override item default_embedded_path_var)
65  get_filename_component(_item_name \"\${item}\" NAME)
66  get_filename_component(_item_path \"\${item}\" PATH)
67 
68  # We have to fix all path references to build trees for plugins
69 
70  if(NOT _item_path MATCHES \"\${CMAKE_INSTALL_PREFIX}/${_bundle_dest_dir}\")
71  # item with relative path or embedded path pointing to some build dir
72  set(full_path \"full_path-NOTFOUND\")
73  file(GLOB_RECURSE full_path \${CMAKE_INSTALL_PREFIX}/${_bundle_dest_dir}/\${_item_name} )
74  list(LENGTH full_path full_path_length)
75  if(full_path_length GREATER 1)
76  list(GET full_path 0 full_path)
77  endif()
78  get_filename_component(_item_path \"\${full_path}\" PATH)
79  endif()
80 
81  set(_plugins_path \"\${_bin_path}/plugins\")
82 
83  if(_item_path STREQUAL _plugins_path
84  OR (_item_path MATCHES \"\${_plugins_path}/\" AND _item_name MATCHES \"liborg\") # this is for legacy BlueBerry bundle support
85  )
86  # Only fix plugins
87  message(\"override: \${item}\")
88  message(\"found file: \${_item_path}/\${_item_name}\")
89  if(APPLE)
90  string(REPLACE
91  \${CMAKE_INSTALL_PREFIX}/${_bundle_dest_dir}
92  @executable_path \${default_embedded_path_var} \"\${_item_path}\" )
93  else()
94  set(\${default_embedded_path_var} \"\${_item_path}\")
95  endif()
96  message(\"override result: \${\${default_embedded_path_var}}\")
97  endif()
98  endmacro(gp_item_default_embedded_path_override)
99 
100  macro(gp_resolved_file_type_override file type)
101  if(NOT APPLE)
102  get_filename_component(_file_path \"\${file}\" PATH)
103  get_filename_component(_file_name \"\${file}\" NAME)
104  if(_file_path MATCHES \"^\${CMAKE_INSTALL_PREFIX}\")
105  set(\${type} \"local\")
106  endif()
107  if(_file_name MATCHES gdiplus)
108  set(\${type} \"system\")
109  endif(_file_name MATCHES gdiplus)
110  endif()
111  if(WIN32)
112  if(file MATCHES \"BluetoothApis.dll\")
113  set(\${type} \"system\" )
114  endif()
115  endif()
116  endmacro(gp_resolved_file_type_override)
117 
118  if(NOT APPLE)
119  macro(gp_resolve_item_override context item exepath dirs resolved_item_var resolved_var)
120  if(\${item} MATCHES \"blueberry_core_runtime\")
121  get_filename_component(_item_name \${item} NAME)
122  set(\${resolved_item_var} \"\${exepath}/plugins/\${_item_name}\")
123  set(\${resolved_var} 1)
124  endif()
125  endmacro()
126  endif()
127 
128  if(\"${_install_GLOB_PLUGINS}\" STREQUAL \"TRUE\")
129  set(GLOBBED_PLUGINS )
130  set(_bb_runtime_lib \"\${_bin_path}/liborg_blueberry_core_runtime${CMAKE_SHARED_LIBRARY_SUFFIX}\")
131  if(EXISTS \"\${_bb_runtime_lib}\")
132  list(APPEND GLOBBED_PLUGINS \"\${_bb_runtime_lib}\")
133  endif()
134 
135  # Iterate over all sub-directories which contain plug-ins
136  # (BlueBerry plug-ins, Qt plug-ins, and auto-load modules)
137  file(GLOB _children \"\${_bin_path}/*\")
138  foreach(_child \${_children})
139  if(IS_DIRECTORY \${_child})
140  set(_plugins )
141  set(_modules )
142  file(GLOB_RECURSE _plugins \"\${_child}/*${CMAKE_SHARED_LIBRARY_SUFFIX}\")
143  if(_plugins)
144  list(APPEND GLOBBED_PLUGINS \${_plugins})
145  endif()
146  # Now glob for all modules which might have a different extensions.
147  # E.g. on MacOS plugins could have a .dylib extension as well as a .so extension
148  if(NOT \"${CMAKE_SHARED_MODULE_SUFFIX}\" STREQUAL \"\" AND NOT \"${CMAKE_SHARED_MODULE_SUFFIX}\" STREQUAL \"${CMAKE_SHARED_LIBRARY_SUFFIX}\")
149  file(GLOB_RECURSE _modules \"\${_child}/*${CMAKE_SHARED_MODULE_SUFFIX}\")
150  endif()
151  if(_modules)
152  list(APPEND GLOBBED_PLUGINS \${_modules})
153  endif()
154  endif()
155  endforeach()
156  endif()
157 
158  set(PLUGINS )
159  foreach(_plugin ${_install_PLUGINS} \${GLOBBED_PLUGINS})
160  get_filename_component(_plugin_realpath \${_plugin} REALPATH)
161  list(APPEND PLUGINS \${_plugin_realpath})
162  endforeach()
163 
164  foreach(_py_lib ${_python_libs})
165  list(APPEND PLUGINS \"\${_bin_path}/\${_py_lib}\")
166  endforeach()
167 
168  if(PLUGINS)
169  list(REMOVE_DUPLICATES PLUGINS)
170  endif(PLUGINS)
171  message(\"globbed plugins: \${PLUGINS}\")
172 
173  set(CMAKE_MODULE_PATH ${MITK_SOURCE_DIR}/CMake ${CMAKE_MODULE_PATH} )
174 
175  set(DIRS \"${_search_paths}\")
176 
177  set(_additional_search_paths ${_install_LIBRARY_DIRS})
178  if(_additional_search_paths)
179  set(DIRS \"\${DIRS};\${_additional_search_paths}\")
180  endif()
181  if(_python_search_paths)
182  set(DIRS \"\${DIRS};\${_python_search_paths}\")
183  endif()
184  foreach(_plugin \${PLUGINS})
185  get_filename_component(_pluginpath \${_plugin} PATH)
186  list(APPEND DIRS \"\${_pluginpath}\")
187  endforeach(_plugin)
188 
189  list(REMOVE_DUPLICATES DIRS)
190 
191  # use custom version of BundleUtilities
192  include(BundleUtilities)
193 
194  fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${_target_location}\" \"\${PLUGINS}\" \"\${DIRS}\")
195  ")
196 endmacro()
_fixup_target()
MITK_INSTALL()
mitkFunctionInstallPython(_python_libs_out, _search_path_out, _app_bundle)