Medical Imaging Interaction Toolkit  2016.11.0
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 SHOW_CONSOLE (option) Show the console output window (on Windows).
19 #! \param NO_PROVISIONING (option) Do not create provisioning files.
20 #! \param NO_INSTALL (option) Do not install this executable
21 #!
22 #! Assuming that there exists a file called <code>MyApp.cpp</code>, an example call looks like:
23 #! \code
24 #! mitkFunctionCreateBlueBerryApplication(
25 #! NAME MyApp
26 #! DESCRIPTION "MyApp - New ways to explore medical data"
27 #! EXCLUDE_PLUGINS org.mitk.gui.qt.extapplication
28 #! SHOW_CONSOLE
29 #! )
30 #! \endcode
31 #!
33 
34 cmake_parse_arguments(_APP "SHOW_CONSOLE;NO_PROVISIONING;NO_INSTALL" "NAME;DESCRIPTION" "SOURCES;PLUGINS;EXCLUDE_PLUGINS;LINK_LIBRARIES;LIBRARY_DIRS" ${ARGN})
35 
36 if(NOT _APP_NAME)
37  message(FATAL_ERROR "NAME argument cannot be empty.")
38 endif()
39 
40 if(NOT _APP_SOURCES)
41  set(_APP_SOURCES ${_APP_NAME}.cpp)
42 endif()
43 
44 if(NOT _APP_PLUGINS)
45  ctkFunctionGetAllPluginTargets(_APP_PLUGINS)
46 else()
47  set(_plugins ${_APP_PLUGINS})
48  set(_APP_PLUGINS)
49  foreach(_plugin ${_plugins})
50  string(REPLACE "." "_" _plugin_target ${_plugin})
51  list(APPEND _APP_PLUGINS ${_plugin_target})
52  endforeach()
53 
54  # get all plug-in dependencies
55  ctkFunctionGetPluginDependencies(_plugin_deps PLUGINS ${_APP_PLUGINS} ALL)
56  # add the dependencies to the list of application plug-ins
57  list(APPEND _APP_PLUGINS ${_plugin_deps})
58 endif()
59 
60 # -----------------------------------------------------------------------
61 # Set up include and link dirs for the executable
62 # -----------------------------------------------------------------------
63 
64 include_directories(
65  ${org_blueberry_core_runtime_INCLUDE_DIRS}
66 )
67 
68 # -----------------------------------------------------------------------
69 # Add executable icon (Windows)
70 # -----------------------------------------------------------------------
71 set(WINDOWS_ICON_RESOURCE_FILE "")
72 if(WIN32)
73  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/icons/${_APP_NAME}.rc")
74  set(WINDOWS_ICON_RESOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/icons/${_APP_NAME}.rc")
75  endif()
76 endif()
77 
78 # -----------------------------------------------------------------------
79 # Create the executable and link libraries
80 # -----------------------------------------------------------------------
81 
82 set(_app_compile_flags )
83 if(WIN32)
84  set(_app_compile_flags "${_app_compile_flags} -DPOCO_NO_UNWINDOWS -DWIN32_LEAN_AND_MEAN")
85 endif()
86 
87 if(_APP_SHOW_CONSOLE)
88  add_executable(${_APP_NAME} MACOSX_BUNDLE ${_APP_SOURCES} ${WINDOWS_ICON_RESOURCE_FILE})
89 else()
90  add_executable(${_APP_NAME} MACOSX_BUNDLE WIN32 ${_APP_SOURCES} ${WINDOWS_ICON_RESOURCE_FILE})
91 endif()
92 mitk_use_modules(TARGET ${_APP_NAME} MODULES mbilog PACKAGES Poco Qt5|Core)
93 
94 set_target_properties(${_APP_NAME} PROPERTIES
95  COMPILE_FLAGS "${_app_compile_flags}")
96 
97 target_link_libraries(${_APP_NAME} PRIVATE org_blueberry_core_runtime ${_APP_LINK_LIBRARIES})
98 if(WIN32)
99  target_link_libraries(${_APP_NAME} PRIVATE ${QT_QTMAIN_LIBRARY})
100 endif()
101 
102 # -----------------------------------------------------------------------
103 # Add executable icon and bundle name (Mac)
104 # -----------------------------------------------------------------------
105 if(APPLE)
106  if( _APP_DESCRIPTION)
107  set_target_properties(${_APP_NAME} PROPERTIES MACOSX_BUNDLE_NAME "${_APP_DESCRIPTION}")
108  else()
109  set_target_properties(${_APP_NAME} PROPERTIES MACOSX_BUNDLE_NAME "${_APP_NAME}")
110  endif()
111  set(icon_name "icon.icns")
112  set(icon_full_path "${CMAKE_CURRENT_SOURCE_DIR}/icons/${icon_name}")
113  if(EXISTS "${icon_full_path}")
114  set_target_properties(${_APP_NAME} PROPERTIES MACOSX_BUNDLE_ICON_FILE "${icon_name}")
115  file(COPY ${icon_full_path} DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_APP_NAME}.app/Contents/Resources/")
116  INSTALL (FILES ${icon_full_path} DESTINATION "${_APP_NAME}.app/Contents/Resources/")
117  endif()
118 endif()
119 
120 # -----------------------------------------------------------------------
121 # Set build time dependencies
122 # -----------------------------------------------------------------------
123 
124 # This ensures that all enabled plug-ins are up-to-date when the
125 # executable is build.
126 if(_APP_PLUGINS)
127  ctkMacroGetAllProjectTargetLibraries("${_APP_PLUGINS}" _project_plugins)
128  if(_APP_EXCLUDE_PLUGINS AND _project_plugins)
129  set(_exclude_targets)
130  foreach(_exclude_plugin ${_APP_EXCLUDE_PLUGINS})
131  string(REPLACE "." "_" _exclude_target ${_exclude_plugin})
132  list(APPEND _exclude_targets ${_exclude_target})
133  endforeach()
134  list(REMOVE_ITEM _project_plugins ${_exclude_targets})
135  endif()
136  if(_project_plugins)
137  add_dependencies(${_APP_NAME} ${_project_plugins})
138  endif()
139 endif()
140 
141 # -----------------------------------------------------------------------
142 # Additional files needed for the executable
143 # -----------------------------------------------------------------------
144 
145 if(NOT _APP_NO_PROVISIONING)
146 
147  # Create a provisioning file, listing all plug-ins
148  set(_prov_file "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_APP_NAME}.provisioning")
149  mitkFunctionCreateProvisioningFile(FILE ${_prov_file}
150  PLUGINS ${_APP_PLUGINS}
151  EXCLUDE_PLUGINS ${_APP_EXCLUDE_PLUGINS}
152  )
153 
154 endif()
155 
156 # Create a .ini file for initial parameters
157 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_APP_NAME}.ini")
158  configure_file(${_APP_NAME}.ini
159  ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_APP_NAME}.ini)
160 endif()
161 
162 # Create batch and VS user files for Windows platforms
163 include(mitkFunctionCreateWindowsBatchScript)
164 
165 if(WIN32)
166  set(template_name "start${_APP_NAME}.bat.in")
167  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${template_name}")
168  foreach(BUILD_TYPE debug release)
169  mitkFunctionCreateWindowsBatchScript(${template_name}
170  ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/start${_APP_NAME}_${BUILD_TYPE}.bat
171  ${BUILD_TYPE})
172  endforeach()
173  endif()
174  mitkFunctionConfigureVisualStudioUserProjectFile(
175  NAME ${_APP_NAME}
176  )
177 endif(WIN32)
178 
179 # -----------------------------------------------------------------------
180 # Install support
181 # -----------------------------------------------------------------------
182 
183 if(NOT _APP_NO_INSTALL)
184 
185  # This installs all third-party CTK plug-ins
186  mitkFunctionInstallThirdPartyCTKPlugins(${_APP_PLUGINS} EXCLUDE ${_APP_EXCLUDE_PLUGINS})
187 
188  if(COMMAND BlueBerryApplicationInstallHook)
189  set(_real_app_plugins ${_APP_PLUGINS})
190  if(_APP_EXCLUDE_PLUGINS)
191  list(REMOVE_ITEM _real_app_plugins ${_APP_EXCLUDE_PLUGINS})
192  endif()
193  BlueBerryApplicationInstallHook(APP_NAME ${_APP_NAME} PLUGINS ${_real_app_plugins})
194  endif()
195 
196  # Install the executable
197  MITK_INSTALL_TARGETS(EXECUTABLES ${_APP_NAME} LIBRARY_DIRS ${_APP_LIBRARY_DIRS} GLOB_PLUGINS )
198 
199  if(NOT _APP_NO_PROVISIONING)
200  # Install the provisioning file
201  mitkFunctionInstallProvisioningFiles(${_prov_file})
202  endif()
203 
204  # On Linux, create a shell script to start a relocatable application
205  if(UNIX AND NOT APPLE)
206  install(PROGRAMS "${MITK_SOURCE_DIR}/CMake/RunInstalledApp.sh" DESTINATION "." RENAME ${_APP_NAME}.sh)
207  endif()
208 
209  # Tell cpack the executables that you want in the start menu as links
210  set(MITK_CPACK_PACKAGE_EXECUTABLES ${MITK_CPACK_PACKAGE_EXECUTABLES} "${_APP_NAME};${_APP_DESCRIPTION}" CACHE INTERNAL "Collecting windows shortcuts to executables")
211 
212 endif()
213 
214 endfunction()
215 
216 function(FunctionCreateBlueBerryApplication)
217  message(SEND_ERROR "The function FunctionCreateBlueBerryApplication was renamed to mitkFunctionCreateBlueBerryApplication in MITK 2015.05")
218 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...