Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkFunctionCreateBlueBerryApplication.cmake
Go to the documentation of this file.
1 #!
2 #! Create a BlueBerry application.
3 #!
4 #! \brief This function will create a BlueBerry application together with all
5 #! necessary provisioning and configuration data and install support.
6 #!
7 #! \param NAME (required) The name of the executable.
8 #! \param DESCRIPTION (optional) A human-readable description of your application.
9 #! The usage depends on the CPack generator (on Windows, this is a descriptive
10 #! text for the created shortcuts).
11 #! \param SOURCES (optional) A list of source files to compile into your executable. Defaults
12 #! to <name>.cpp.
13 #! \param PLUGINS (optional) A list of required plug-ins. Defaults to all known plug-ins.
14 #! \param EXCLUDE_PLUGINS (optional) A list of plug-ins which should not be used. Mainly
15 #! useful if PLUGINS was not used.
16 #! \param LINK_LIBRARIES A list of libraries to be linked with the executable.
17 #! \param LIBRARY_DIRS A list of directories to pass through to MITK_INSTALL_TARGETS
18 #! \param NO_PROVISIONING (option) Do not create provisioning files.
19 #! \param NO_INSTALL (option) Do not install this executable
20 #!
21 #! Assuming that there exists a file called <code>MyApp.cpp</code>, an example call looks like:
22 #! \code
23 #! mitkFunctionCreateBlueBerryApplication(
24 #! NAME MyApp
25 #! DESCRIPTION "MyApp - New ways to explore medical data"
26 #! EXCLUDE_PLUGINS org.mitk.gui.qt.extapplication
27 #! )
28 #! \endcode
29 #!
31 
32 cmake_parse_arguments(_APP "NO_PROVISIONING;NO_INSTALL" "NAME;DESCRIPTION" "SOURCES;PLUGINS;EXCLUDE_PLUGINS;LINK_LIBRARIES;LIBRARY_DIRS" ${ARGN})
33 
34 if(NOT _APP_NAME)
35  message(FATAL_ERROR "NAME argument cannot be empty.")
36 endif()
37 
38 if(NOT _APP_SOURCES)
39  set(_APP_SOURCES ${_APP_NAME}.cpp)
40 endif()
41 
42 if(NOT _APP_PLUGINS)
43  ctkFunctionGetAllPluginTargets(_APP_PLUGINS)
44 else()
45  set(_plugins ${_APP_PLUGINS})
46  set(_APP_PLUGINS)
47  foreach(_plugin ${_plugins})
48  string(REPLACE "." "_" _plugin_target ${_plugin})
49  list(APPEND _APP_PLUGINS ${_plugin_target})
50  endforeach()
51 
52  # get all plug-in dependencies
53  ctkFunctionGetPluginDependencies(_plugin_deps PLUGINS ${_APP_PLUGINS} ALL)
54  # add the dependencies to the list of application plug-ins
55  list(APPEND _APP_PLUGINS ${_plugin_deps})
56 endif()
57 
58 # -----------------------------------------------------------------------
59 # Set up include and link dirs for the executable
60 # -----------------------------------------------------------------------
61 
62 include_directories(
63  ${org_blueberry_core_runtime_INCLUDE_DIRS}
64 )
65 
66 # -----------------------------------------------------------------------
67 # Add executable icon (Windows)
68 # -----------------------------------------------------------------------
69 set(WINDOWS_ICON_RESOURCE_FILE "")
70 if(WIN32)
71  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/icons/${_APP_NAME}.rc")
72  set(WINDOWS_ICON_RESOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/icons/${_APP_NAME}.rc")
73  endif()
74 endif()
75 
76 # -----------------------------------------------------------------------
77 # Create the executable and link libraries
78 # -----------------------------------------------------------------------
79 
80 set(_app_compile_flags )
81 if(WIN32)
82  set(_app_compile_flags "${_app_compile_flags} -DPOCO_NO_UNWINDOWS -DWIN32_LEAN_AND_MEAN")
83 endif()
84 
85 if(MITK_SHOW_CONSOLE_WINDOW)
86  add_executable(${_APP_NAME} MACOSX_BUNDLE ${_APP_SOURCES} ${WINDOWS_ICON_RESOURCE_FILE})
87 else()
88  add_executable(${_APP_NAME} MACOSX_BUNDLE WIN32 ${_APP_SOURCES} ${WINDOWS_ICON_RESOURCE_FILE})
89 endif()
90 
91 if(NOT CMAKE_CURRENT_SOURCE_DIR MATCHES "^${CMAKE_SOURCE_DIR}.*")
92  foreach(MITK_EXTENSION_DIR ${MITK_EXTENSION_DIRS})
93  if(CMAKE_CURRENT_SOURCE_DIR MATCHES "^${MITK_EXTENSION_DIR}.*")
94  get_filename_component(MITK_EXTENSION_ROOT_FOLDER ${MITK_EXTENSION_DIR} NAME)
95  set_property(TARGET ${_APP_NAME} PROPERTY FOLDER "${MITK_EXTENSION_ROOT_FOLDER}/Applications")
96  break()
97  endif()
98  endforeach()
99 else()
100  set_property(TARGET ${_APP_NAME} PROPERTY FOLDER "${MITK_ROOT_FOLDER}/Applications")
101 endif()
102 
103 mitk_use_modules(TARGET ${_APP_NAME} MODULES MitkAppUtil)
104 
105 set_target_properties(${_APP_NAME} PROPERTIES
106  COMPILE_FLAGS "${_app_compile_flags}")
107 
108 target_link_libraries(${_APP_NAME} PRIVATE org_blueberry_core_runtime ${_APP_LINK_LIBRARIES})
109 if(WIN32)
110  target_link_libraries(${_APP_NAME} PRIVATE ${QT_QTMAIN_LIBRARY})
111 endif()
112 
113 # -----------------------------------------------------------------------
114 # Add executable icon and bundle name (Mac)
115 # -----------------------------------------------------------------------
116 if(APPLE)
117  if( _APP_DESCRIPTION)
118  set_target_properties(${_APP_NAME} PROPERTIES MACOSX_BUNDLE_NAME "${_APP_DESCRIPTION}")
119  else()
120  set_target_properties(${_APP_NAME} PROPERTIES MACOSX_BUNDLE_NAME "${_APP_NAME}")
121  endif()
122  set(icon_name "icon.icns")
123  set(icon_full_path "${CMAKE_CURRENT_SOURCE_DIR}/icons/${icon_name}")
124  if(EXISTS "${icon_full_path}")
125  set_target_properties(${_APP_NAME} PROPERTIES MACOSX_BUNDLE_ICON_FILE "${icon_name}")
126  file(COPY ${icon_full_path} DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_APP_NAME}.app/Contents/Resources/")
127  INSTALL (FILES ${icon_full_path} DESTINATION "${_APP_NAME}.app/Contents/Resources/")
128  endif()
129 endif()
130 
131 # -----------------------------------------------------------------------
132 # Set build time dependencies
133 # -----------------------------------------------------------------------
134 
135 # This ensures that all enabled plug-ins are up-to-date when the
136 # executable is build.
137 if(_APP_PLUGINS)
138  ctkMacroGetAllProjectTargetLibraries("${_APP_PLUGINS}" _project_plugins)
139  if(_APP_EXCLUDE_PLUGINS AND _project_plugins)
140  set(_exclude_targets)
141  foreach(_exclude_plugin ${_APP_EXCLUDE_PLUGINS})
142  string(REPLACE "." "_" _exclude_target ${_exclude_plugin})
143  list(APPEND _exclude_targets ${_exclude_target})
144  endforeach()
145  list(REMOVE_ITEM _project_plugins ${_exclude_targets})
146  endif()
147  if(_project_plugins)
148  add_dependencies(${_APP_NAME} ${_project_plugins})
149  endif()
150 endif()
151 
152 # -----------------------------------------------------------------------
153 # Additional files needed for the executable
154 # -----------------------------------------------------------------------
155 
156 if(NOT _APP_NO_PROVISIONING)
157 
158  # Create a provisioning file, listing all plug-ins
159  set(_prov_file "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_APP_NAME}.provisioning")
160  mitkFunctionCreateProvisioningFile(FILE ${_prov_file}
161  PLUGINS ${_APP_PLUGINS}
162  EXCLUDE_PLUGINS ${_APP_EXCLUDE_PLUGINS}
163  )
164 
165 endif()
166 
167 # Create a .ini file for initial parameters
168 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_APP_NAME}.ini")
169  configure_file(${_APP_NAME}.ini
170  ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_APP_NAME}.ini)
171 endif()
172 
173 # Create batch and VS user files for Windows platforms
174 include(mitkFunctionCreateWindowsBatchScript)
175 
176 if(WIN32)
177  set(template_name "start${_APP_NAME}.bat.in")
178  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${template_name}")
179  foreach(BUILD_TYPE debug release)
180  mitkFunctionCreateWindowsBatchScript(${template_name}
181  ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/start${_APP_NAME}_${BUILD_TYPE}.bat
182  ${BUILD_TYPE})
183  endforeach()
184  endif()
185  mitkFunctionConfigureVisualStudioUserProjectFile(
186  NAME ${_APP_NAME}
187  )
188 endif(WIN32)
189 
190 # -----------------------------------------------------------------------
191 # Install support
192 # -----------------------------------------------------------------------
193 
194 if(NOT _APP_NO_INSTALL)
195 
196  # This installs all third-party CTK plug-ins
197  mitkFunctionInstallThirdPartyCTKPlugins(${_APP_PLUGINS} EXCLUDE ${_APP_EXCLUDE_PLUGINS})
198 
199  if(COMMAND BlueBerryApplicationInstallHook)
200  set(_real_app_plugins ${_APP_PLUGINS})
201  if(_APP_EXCLUDE_PLUGINS)
202  list(REMOVE_ITEM _real_app_plugins ${_APP_EXCLUDE_PLUGINS})
203  endif()
204  BlueBerryApplicationInstallHook(APP_NAME ${_APP_NAME} PLUGINS ${_real_app_plugins})
205  endif()
206 
207  # Install the executable
208  MITK_INSTALL_TARGETS(EXECUTABLES ${_APP_NAME} LIBRARY_DIRS ${_APP_LIBRARY_DIRS} GLOB_PLUGINS )
209 
210  if(NOT _APP_NO_PROVISIONING)
211  # Install the provisioning file
212  mitkFunctionInstallProvisioningFiles(${_prov_file})
213  endif()
214 
215  # On Linux, create a shell script to start a relocatable application
216  if(UNIX AND NOT APPLE)
217  install(PROGRAMS "${MITK_SOURCE_DIR}/CMake/RunInstalledApp.sh" DESTINATION "." RENAME ${_APP_NAME}.sh)
218  endif()
219 
220  # Tell cpack the executables that you want in the start menu as links
221  set(MITK_CPACK_PACKAGE_EXECUTABLES ${MITK_CPACK_PACKAGE_EXECUTABLES} "${_APP_NAME};${_APP_DESCRIPTION}" CACHE INTERNAL "Collecting windows shortcuts to executables")
222 
223 endif()
224 
225 endfunction()
226 
227 function(FunctionCreateBlueBerryApplication)
228  message(SEND_ERROR "The function FunctionCreateBlueBerryApplication was renamed to mitkFunctionCreateBlueBerryApplication in MITK 2015.05")
229 endfunction()
FunctionCreateBlueBerryApplication()
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
Definition: jsoncpp.cpp:244
mitkFunctionCreateBlueBerryApplication()
This function will create a BlueBerry application together with all necessary provisioning and config...