3 #-----------------------------------------------------------------------------
4 # Convenient macro allowing to download a file
5 #-----------------------------------------------------------------------------
7 if(NOT MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL)
8 set(MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL http:
12 file(DOWNLOAD ${url} ${dest} STATUS status)
13 list(GET status 0 error_code)
14 list(GET status 1 error_msg)
16 message(FATAL_ERROR
"error: Failed to download ${url} - ${error_msg}")
20 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
24 if(UNIX AND NOT APPLE)
31 # Check
for libtiff4-dev
34 # Check
for libwrap0-dev
39 # We need a proper patch program. On Linux and MacOS, we assume
40 # that
"patch" is
available. On Windows, we download patch.exe
41 #
if not patch program is found.
42 find_program(PATCH_COMMAND patch)
43 if((NOT PATCH_COMMAND OR NOT EXISTS ${PATCH_COMMAND}) AND WIN32)
44 downloadFile(${MITK_THIRDPARTY_DOWNLOAD_PREFIX_URL}/patch.exe
45 ${CMAKE_CURRENT_BINARY_DIR}/patch.exe)
46 find_program(PATCH_COMMAND patch ${CMAKE_CURRENT_BINARY_DIR})
49 message(FATAL_ERROR "No patch program found.")
52 #-----------------------------------------------------------------------------
54 #-----------------------------------------------------------------------------
56 get_property(external_projects GLOBAL PROPERTY MITK_EXTERNAL_PROJECTS)
58 if(MITK_CTEST_SCRIPT_MODE)
59 # Write a file containing the list of enabled external project targets.
60 # This file can be read by a ctest script to separately build projects.
61 set(SUPERBUILD_TARGETS )
62 foreach(proj ${external_projects})
64 list(APPEND SUPERBUILD_TARGETS ${proj})
67 file(WRITE "${CMAKE_BINARY_DIR}/SuperBuildTargets.cmake
" "set(SUPERBUILD_TARGETS ${SUPERBUILD_TARGETS})
")
70 # A list of "nice
" external projects, playing well together with CMake
71 set(nice_external_projects ${external_projects})
72 list(REMOVE_ITEM nice_external_projects Boost Python)
73 foreach(proj ${nice_external_projects})
75 set(EXTERNAL_${proj}_DIR "${${proj}_DIR}
" CACHE PATH "Path to ${proj} build directory
")
76 mark_as_advanced(EXTERNAL_${proj}_DIR)
77 if(EXTERNAL_${proj}_DIR)
78 set(${proj}_DIR ${EXTERNAL_${proj}_DIR})
83 set(EXTERNAL_BOOST_ROOT "${BOOST_ROOT}
" CACHE PATH "Path to Boost directory
")
84 mark_as_advanced(EXTERNAL_BOOST_ROOT)
85 if(EXTERNAL_BOOST_ROOT)
86 set(BOOST_ROOT ${EXTERNAL_BOOST_ROOT})
89 # Setup file for setting custom ctest vars
91 CMake/SuperbuildCTestCustom.cmake.in
92 ${MITK_BINARY_DIR}/CTestCustom.cmake
97 set(EXTERNAL_MITK_DATA_DIR "${
MITK_DATA_DIR}
" CACHE PATH "Path to the MITK data directory
")
98 mark_as_advanced(EXTERNAL_MITK_DATA_DIR)
99 if(EXTERNAL_MITK_DATA_DIR)
100 set(MITK_DATA_DIR ${EXTERNAL_MITK_DATA_DIR})
104 #-----------------------------------------------------------------------------
105 # External project settings
106 #-----------------------------------------------------------------------------
108 include(ExternalProject)
110 set(ep_prefix "${CMAKE_BINARY_DIR}/ep
")
111 set_property(DIRECTORY PROPERTY EP_PREFIX ${ep_prefix})
113 # Compute -G arg for configuring external projects with the same CMake generator:
114 if(CMAKE_EXTRA_GENERATOR)
115 set(gen "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}
")
117 set(gen "${CMAKE_GENERATOR}
")
120 # Use this value where semi-colons are needed in ep_add args:
126 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj /MP
")
127 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /MP
")
130 # This is a workaround for passing linker flags
131 # actually down to the linker invocation
132 set(_cmake_required_flags_orig ${CMAKE_REQUIRED_FLAGS})
133 set(CMAKE_REQUIRED_FLAGS "-Wl,-rpath
")
134 mitkFunctionCheckCompilerFlags(${CMAKE_REQUIRED_FLAGS} _has_rpath_flag)
135 set(CMAKE_REQUIRED_FLAGS ${_cmake_required_flags_orig})
137 set(_install_rpath_linkflag )
140 set(_install_rpath_linkflag "-Wl,-rpath,@loader_path/../lib
")
142 set(_install_rpath_linkflag "-Wl,-rpath=
'$ORIGIN/../lib'")
148 set(_install_rpath "@loader_path/../lib
")
150 # this work for libraries as well as executables
151 set(_install_rpath "\$ORIGIN/../lib
")
155 -DCMAKE_CXX_EXTENSIONS:STRING=${CMAKE_CXX_EXTENSIONS}
156 -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD}
157 -DCMAKE_CXX_STANDARD_REQUIRED:BOOL=${CMAKE_CXX_STANDARD_REQUIRED}
158 -DCMAKE_MACOSX_RPATH:BOOL=TRUE
159 "-DCMAKE_INSTALL_RPATH:STRING=${_install_rpath}
"
160 -DBUILD_TESTING:BOOL=OFF
161 -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
162 -DBUILD_SHARED_LIBS:BOOL=ON
163 -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
164 -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
165 -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
166 -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
167 "-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} ${MITK_CXX11_FLAG}
"
169 -DCMAKE_CXX_FLAGS_DEBUG:STRING=${CMAKE_CXX_FLAGS_DEBUG}
170 -DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG}
172 -DCMAKE_CXX_FLAGS_RELEASE:STRING=${CMAKE_CXX_FLAGS_RELEASE}
173 -DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}
175 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_CXX_FLAGS_RELWITHDEBINFO}
176 -DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}
178 -DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}
179 -DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS}
180 -DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS}
183 set(DCMTK_CMAKE_DEBUG_POSTFIX )
185 # python libraries wont work with it
186 if(NOT MITK_USE_Python)
187 list(APPEND ep_common_args -DCMAKE_DEBUG_POSTFIX:STRING=d)
188 set(DCMTK_CMAKE_DEBUG_POSTFIX d)
191 set(ep_common_cache_args
194 set(ep_common_cache_default_args
195 "-DCMAKE_PREFIX_PATH:PATH=<INSTALL_DIR>;${CMAKE_PREFIX_PATH}
"
196 "-DCMAKE_INCLUDE_PATH:PATH=${CMAKE_INCLUDE_PATH}
"
197 "-DCMAKE_LIBRARY_PATH:PATH=${CMAKE_LIBRARY_PATH}
"
200 # Pass the CMAKE_OSX variables to external projects
202 set(MAC_OSX_ARCHITECTURE_ARGS
203 -DCMAKE_OSX_ARCHITECTURES:PATH=${CMAKE_OSX_ARCHITECTURES}
204 -DCMAKE_OSX_DEPLOYMENT_TARGET:PATH=${CMAKE_OSX_DEPLOYMENT_TARGET}
205 -DCMAKE_OSX_SYSROOT:PATH=${CMAKE_OSX_SYSROOT}
208 ${MAC_OSX_ARCHITECTURE_ARGS}
213 set(mitk_superbuild_ep_args)
216 # Include external projects
217 include(CMakeExternals/MITKData.cmake)
218 foreach(p ${external_projects})
219 include(CMakeExternals/${p}.cmake)
221 list(APPEND mitk_superbuild_ep_args
222 -DMITK_USE_${p}:BOOL=${MITK_USE_${p}}
224 get_property(_package GLOBAL PROPERTY MITK_${p}_PACKAGE)
226 list(APPEND mitk_superbuild_ep_args -D${p}_DIR:PATH=${${p}_DIR})
229 list(APPEND mitk_depends ${${p}_DEPENDS})
232 #-----------------------------------------------------------------------------
233 # Set superbuild boolean args
234 #-----------------------------------------------------------------------------
236 set(mitk_cmake_boolean_args
241 MITK_BUILD_ALL_PLUGINS
246 MITK_USE_Qt5_WebEngine
247 MITK_USE_SYSTEM_Boost
251 MITK_ENABLE_PIC_READER
254 #-----------------------------------------------------------------------------
255 # Create the final variable containing superbuild boolean args
256 #-----------------------------------------------------------------------------
258 set(mitk_superbuild_boolean_args)
259 foreach(mitk_cmake_arg ${mitk_cmake_boolean_args})
260 list(APPEND mitk_superbuild_boolean_args -D${mitk_cmake_arg}:BOOL=${${mitk_cmake_arg}})
263 if(MITK_BUILD_ALL_PLUGINS)
264 list(APPEND mitk_superbuild_boolean_args -DBLUEBERRY_BUILD_ALL_PLUGINS:BOOL=ON)
267 #-----------------------------------------------------------------------------
269 #-----------------------------------------------------------------------------
271 set(proj MITK-Utilities)
272 ExternalProject_Add(${proj}
280 #-----------------------------------------------------------------------------
281 # Additional MITK CXX/C Flags
282 #-----------------------------------------------------------------------------
284 set(MITK_ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags
for MITK
")
285 set(MITK_ADDITIONAL_C_FLAGS_RELEASE "" CACHE STRING "Additional Release C Flags
for MITK
")
286 set(MITK_ADDITIONAL_C_FLAGS_DEBUG "" CACHE STRING "Additional
Debug C Flags
for MITK
")
287 mark_as_advanced(MITK_ADDITIONAL_C_FLAGS MITK_ADDITIONAL_C_FLAGS_DEBUG MITK_ADDITIONAL_C_FLAGS_RELEASE)
289 set(MITK_ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags
for MITK
")
290 set(MITK_ADDITIONAL_CXX_FLAGS_RELEASE "" CACHE STRING "Additional Release CXX Flags
for MITK
")
291 set(MITK_ADDITIONAL_CXX_FLAGS_DEBUG "" CACHE STRING "Additional
Debug CXX Flags
for MITK
")
292 mark_as_advanced(MITK_ADDITIONAL_CXX_FLAGS MITK_ADDITIONAL_CXX_FLAGS_DEBUG MITK_ADDITIONAL_CXX_FLAGS_RELEASE)
294 set(MITK_ADDITIONAL_EXE_LINKER_FLAGS "" CACHE STRING "Additional exe linker flags
for MITK
")
295 set(MITK_ADDITIONAL_SHARED_LINKER_FLAGS "" CACHE STRING "Additional shared linker flags
for MITK
")
296 set(MITK_ADDITIONAL_MODULE_LINKER_FLAGS "" CACHE STRING "Additional module linker flags
for MITK
")
297 mark_as_advanced(MITK_ADDITIONAL_EXE_LINKER_FLAGS MITK_ADDITIONAL_SHARED_LINKER_FLAGS MITK_ADDITIONAL_MODULE_LINKER_FLAGS)
299 #-----------------------------------------------------------------------------
301 #-----------------------------------------------------------------------------
303 if(MITK_INITIAL_CACHE_FILE)
304 set(mitk_initial_cache_arg -C "${MITK_INITIAL_CACHE_FILE}
")
307 set(mitk_optional_cache_args )
308 foreach(type RUNTIME ARCHIVE LIBRARY)
309 if(DEFINED CTK_PLUGIN_${type}_OUTPUT_DIRECTORY)
310 list(APPEND mitk_optional_cache_args -DCTK_PLUGIN_${type}_OUTPUT_DIRECTORY:PATH=${CTK_PLUGIN_${type}_OUTPUT_DIRECTORY})
314 # Optional python variables
316 list(APPEND mitk_optional_cache_args
317 -DMITK_USE_Python:BOOL=${MITK_USE_Python}
318 -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE}
319 -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR}
320 -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
321 -DPYTHON_INCLUDE_DIR2:PATH=${PYTHON_INCLUDE_DIR2}
322 -DMITK_USE_SYSTEM_PYTHON:BOOL=${MITK_USE_SYSTEM_PYTHON}
326 set(proj MITK-Configure)
328 ExternalProject_Add(${proj}
329 LIST_SEPARATOR ${sep}
331 CMAKE_GENERATOR ${gen}
333 # --------------- Build options ----------------
334 -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
335 -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
336 "-DCMAKE_PREFIX_PATH:PATH=${ep_prefix};${CMAKE_PREFIX_PATH}
"
337 "-DCMAKE_LIBRARY_PATH:PATH=${CMAKE_LIBRARY_PATH}
"
338 "-DCMAKE_INCLUDE_PATH:PATH=${CMAKE_INCLUDE_PATH}
"
339 # --------------- Compile options ----------------
340 -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
341 -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
342 "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS} ${MITK_ADDITIONAL_C_FLAGS}
"
343 "-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} ${MITK_ADDITIONAL_CXX_FLAGS}
"
345 "-DCMAKE_CXX_FLAGS_DEBUG:STRING=${CMAKE_CXX_FLAGS_DEBUG} ${MITK_ADDITIONAL_CXX_FLAGS_DEBUG}
"
346 "-DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG} ${MITK_ADDITIONAL_C_FLAGS_DEBUG}
"
348 "-DCMAKE_CXX_FLAGS_RELEASE:STRING=${CMAKE_CXX_FLAGS_RELEASE} ${MITK_ADDITIONAL_CXX_FLAGS_RELEASE}
"
349 "-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE} ${MITK_ADDITIONAL_C_FLAGS_RELEASE}
"
351 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_CXX_FLAGS_RELWITHDEBINFO}
352 -DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}
354 "-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS} ${MITK_ADDITIONAL_EXE_LINKER_FLAGS}
"
355 "-DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS} ${MITK_ADDITIONAL_SHARED_LINKER_FLAGS}
"
356 "-DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS} ${MITK_ADDITIONAL_MODULE_LINKER_FLAGS}
"
358 -DMITK_CMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH=${MITK_CMAKE_LIBRARY_OUTPUT_DIRECTORY}
359 -DMITK_CMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=${MITK_CMAKE_RUNTIME_OUTPUT_DIRECTORY}
360 -DMITK_CMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH=${MITK_CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
361 # ------------- Boolean build options --------------
362 ${mitk_superbuild_boolean_args}
363 ${mitk_optional_cache_args}
364 -DMITK_USE_SUPERBUILD:BOOL=OFF
365 -DMITK_BUILD_CONFIGURATION:STRING=${MITK_BUILD_CONFIGURATION}
366 -DCTEST_USE_LAUNCHERS:BOOL=${CTEST_USE_LAUNCHERS}
367 # ----------------- Miscellaneous ---------------
368 -DCMAKE_LIBRARY_PATH:PATH=${CMAKE_LIBRARY_PATH}
369 -DCMAKE_INCLUDE_PATH:PATH=${CMAKE_INCLUDE_PATH}
370 -DMITK_CTEST_SCRIPT_MODE:STRING=${MITK_CTEST_SCRIPT_MODE}
371 -DMITK_SUPERBUILD_BINARY_DIR:PATH=${MITK_BINARY_DIR}
372 -DMITK_MODULES_TO_BUILD:INTERNAL=${MITK_MODULES_TO_BUILD}
373 -DMITK_WHITELIST:STRING=${MITK_WHITELIST}
374 -DMITK_WHITELISTS_EXTERNAL_PATH:STRING=${MITK_WHITELISTS_EXTERNAL_PATH}
375 -DMITK_WHITELISTS_INTERNAL_PATH:STRING=${MITK_WHITELISTS_INTERNAL_PATH}
376 -DMITK_ACCESSBYITK_INTEGRAL_PIXEL_TYPES:STRING=${MITK_ACCESSBYITK_INTEGRAL_PIXEL_TYPES}
377 -DMITK_ACCESSBYITK_FLOATING_PIXEL_TYPES:STRING=${MITK_ACCESSBYITK_FLOATING_PIXEL_TYPES}
378 -DMITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES:STRING=${MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES}
379 -DMITK_ACCESSBYITK_VECTOR_PIXEL_TYPES:STRING=${MITK_ACCESSBYITK_VECTOR_PIXEL_TYPES}
380 -DMITK_ACCESSBYITK_DIMENSIONS:STRING=${MITK_ACCESSBYITK_DIMENSIONS}
381 # --------------- External project options ---------------
382 -DMITK_DATA_DIR:PATH=${MITK_DATA_DIR}
383 -DMITK_EXTERNAL_PROJECT_PREFIX:PATH=${ep_prefix}
384 -DCppMicroServices_DIR:PATH=${CppMicroServices_DIR}
385 -DMITK_KWSTYLE_EXECUTABLE:FILEPATH=${MITK_KWSTYLE_EXECUTABLE}
386 -DDCMTK_CMAKE_DEBUG_POSTFIX:STRING=${DCMTK_CMAKE_DEBUG_POSTFIX}
387 -DBOOST_ROOT:PATH=${BOOST_ROOT}
388 -DBOOST_LIBRARYDIR:PATH=${BOOST_LIBRARYDIR}
389 -DMITK_USE_Boost_LIBRARIES:STRING=${MITK_USE_Boost_LIBRARIES}
391 ${mitk_initial_cache_arg}
392 ${MAC_OSX_ARCHITECTURE_ARGS}
393 ${mitk_superbuild_ep_args}
394 SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
395 BINARY_DIR ${CMAKE_BINARY_DIR}/MITK-build
402 mitkFunctionInstallExternalCMakeProject(${proj})
404 #-----------------------------------------------------------------------------
406 #-----------------------------------------------------------------------------
408 if(CMAKE_GENERATOR MATCHES ".*Makefiles.*
")
409 set(mitk_build_cmd "$(MAKE)
")
411 set(mitk_build_cmd ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/MITK-build --config ${CMAKE_CFG_INTDIR})
414 if(NOT DEFINED SUPERBUILD_EXCLUDE_MITKBUILD_TARGET OR NOT SUPERBUILD_EXCLUDE_MITKBUILD_TARGET)
415 set(MITKBUILD_TARGET_ALL_OPTION "ALL")
417 set(MITKBUILD_TARGET_ALL_OPTION "")
420 add_custom_target(MITK-build ${MITKBUILD_TARGET_ALL_OPTION}
421 COMMAND ${mitk_build_cmd}
422 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/MITK-build
423 DEPENDS MITK-Configure
426 #-----------------------------------------------------------------------------
427 # Custom target allowing to drive the build of the MITK project itself
428 #-----------------------------------------------------------------------------
430 add_custom_target(MITK
431 COMMAND ${mitk_build_cmd}
432 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/MITK-build
mitkFunctionCheckPackageHeader(_header, _provider)
section MAP_FRAME_Mapper_Settings Mapper settings For the mapping of corrected you have several settings available
mitkFunctionInstallExternalCMakeProject(ep_name)