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