diff --git a/Applications/PluginGenerator/ProjectTemplate/CMakeExternals/MITK.cmake b/Applications/PluginGenerator/ProjectTemplate/CMakeExternals/MITK.cmake index 695a930245..5ae151fe47 100644 --- a/Applications/PluginGenerator/ProjectTemplate/CMakeExternals/MITK.cmake +++ b/Applications/PluginGenerator/ProjectTemplate/CMakeExternals/MITK.cmake @@ -1,115 +1,213 @@ #----------------------------------------------------------------------------- # MITK #----------------------------------------------------------------------------- set(MITK_DEPENDS) set(proj_DEPENDENCIES) set(proj MITK) if(NOT MITK_DIR) #----------------------------------------------------------------------------- - # Generate cmake variable names for BlueBerry bundles + # Create CMake options to customize the MITK build #----------------------------------------------------------------------------- option(MITK_USE_SUPERBUILD "Use superbuild for MITK" ON) option(MITK_USE_BLUEBERRY "Build the BlueBerry platform in MITK" ON) option(MITK_BUILD_TUTORIAL "Build the MITK tutorial" OFF) option(MITK_BUILD_ALL_PLUGINS "Build all MITK plugins" OFF) + option(MITK_BUILD_TESTING "Build the MITK unit tests" OFF) option(MITK_USE_CTK "Use CTK in MITK" ${MITK_USE_BLUEBERRY}) - option(MITK_USE_GDCMIO "Use the GDCMIO class instead of ImageIO2 for DICOM" ON) option(MITK_USE_DCMTK "Use DCMTK in MITK" ON) - option(MITK_USE_QT "Use Trolltech's Qt library in MITK" ON) + option(MITK_USE_QT "Use Nokia's Qt library in MITK" ON) option(MITK_USE_Boost "Use the Boost library in MITK" OFF) option(MITK_USE_OpenCV "Use Intel's OpenCV library" OFF) + option(MITK_USE_Python "Enable Python wrapping in MITK" OFF) - + if(MITK_USE_BLUEBERRY AND NOT MITK_USE_CTK) + message("Forcing MITK_USE_CTK to ON because of MITK_USE_BLUEBERRY") + set(MITK_USE_CTK ON CACHE BOOL "Use CTK in MITK" FORCE) + endif() + + if(MITK_USE_CTK AND NOT MITK_USE_QT) + message("Forcing MITK_USE_QT to ON because of MITK_USE_CTK") + set(MITK_USE_QT ON CACHE BOOL "Use Nokia's Qt library in MITK" FORCE) + endif() + + set(MITK_USE_CableSwig ${MITK_USE_Python}) + set(MITK_USE_GDCM 1) + set(MITK_USE_ITK 1) + set(MITK_USE_VTK 1) + mark_as_advanced(MITK_USE_SUPERBUILD MITK_BUILD_ALL_PLUGINS + MITK_BUILD_TESTING ) set(mitk_cmake_boolean_args MITK_USE_SUPERBUILD MITK_USE_BLUEBERRY MITK_BUILD_TUTORIAL MITK_BUILD_ALL_PLUGINS MITK_USE_CTK - MITK_USE_GDCMIO MITK_USE_DCMTK MITK_USE_QT MITK_USE_Boost MITK_USE_OpenCV + MITK_USE_Python ) + + if(MITK_USE_QT) + # Look for Qt at the superbuild level, to catch missing Qt libs early + find_package(Qt4 4.6.0 REQUIRED) + endif() + + set(additional_mitk_cmakevars ) + + # Configure the set of default pixel types + set(MITK_ACCESSBYITK_INTEGRAL_PIXEL_TYPES + "int, unsigned int, short, unsigned short, char, unsigned char" + CACHE STRING "List of integral pixel types used in AccessByItk and InstantiateAccessFunction macros") + + set(MITK_ACCESSBYITK_FLOATING_PIXEL_TYPES + "double, float" + CACHE STRING "List of floating pixel types used in AccessByItk and InstantiateAccessFunction macros") + + set(MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES + "" + CACHE STRING "List of composite pixel types used in AccessByItk and InstantiateAccessFunction macros") + + set(MITK_ACCESSBYITK_DIMENSIONS + "2,3" + CACHE STRING "List of dimensions used in AccessByItk and InstantiateAccessFunction macros") + + foreach(_arg MITK_ACCESSBYITK_INTEGRAL_PIXEL_TYPES MITK_ACCESSBYITK_FLOATING_PIXEL_TYPES + MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES MITK_ACCESSBYITK_DIMENSIONS) + mark_as_advanced(${_arg}) + list(APPEND additional_mitk_cmakevars "-D${_arg}:STRING=${${_arg}}") + endforeach() + + #----------------------------------------------------------------------------- + # Create options to inject pre-build dependencies + #----------------------------------------------------------------------------- + + foreach(proj CTK DCMTK GDCM VTK ITK OpenCV CableSwig) + if(MITK_USE_${proj}) + set(MITK_${proj}_DIR "${${proj}_DIR}" CACHE PATH "Path to ${proj} build directory") + mark_as_advanced(MITK_${proj}_DIR) + if(MITK_${proj}_DIR) + list(APPEND additional_mitk_cmakevars "-D${proj}_DIR:PATH=${MITK_${proj}_DIR}") + endif() + endif() + endforeach() + + if(MITK_USE_Boost) + set(MITK_BOOST_ROOT "${BOOST_ROOT}" CACHE PATH "Path to Boost directory") + mark_as_advanced(MITK_BOOST_ROOT) + if(MITK_BOOST_ROOT) + list(APPEND additional_mitk_cmakevars "-DBOOST_ROOT:PATH=${MITK_BOOST_ROOT}") + endif() + endif() + + set(MITK_SOURCE_DIR "" CACHE PATH "MITK source code location. If empty, MITK will be cloned from MITK_GIT_REPOSITORY") + set(MITK_GIT_REPOSITORY "http://git.mitk.org/MITK.git" CACHE STRING "The git repository for cloning MITK") + set(MITK_GIT_TAG "origin/master" CACHE STRING "The git tag/hash to be used when cloning from MITK_GIT_REPOSITORY") + mark_as_advanced(MITK_SOURCE_DIR MITK_GIT_REPOSITORY MITK_GIT_TAG) #----------------------------------------------------------------------------- # Create the final variable containing superbuild boolean args #----------------------------------------------------------------------------- set(mitk_boolean_args) foreach(mitk_cmake_arg ${mitk_cmake_boolean_args}) list(APPEND mitk_boolean_args -D${mitk_cmake_arg}:BOOL=${${mitk_cmake_arg}}) endforeach() #----------------------------------------------------------------------------- # Additional MITK CMake variables #----------------------------------------------------------------------------- - set(additional_mitk_cmakevars ) - foreach(proj CTK DCMTK VTK ITK OpenCV) - if(${proj}_DIR) - list(APPEND additional_mitk_cmakevars "-D${proj}_DIR:PATH=${${proj}_DIR}") - endif() - endforeach() - if(MITK_USE_QT AND QT_QMAKE_EXECUTABLE) list(APPEND additional_mitk_cmakevars "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}") endif() - - if(BOOST_ROOT) - list(APPEND additional_mitk_cmakevars "-DBOOST_ROOT:INTERNAL=${BOOST_ROOT}") + + if(MITK_USE_CTK) + list(APPEND additional_mitk_cmakevars "-DGIT_EXECUTABLE:FILEPATH=${GIT_EXECUTABLE}") endif() if(MITK_INITIAL_CACHE_FILE) list(APPEND additional_mitk_cmakevars "-DMITK_INITIAL_CACHE_FILE:INTERNAL=${MITK_INITIAL_CACHE_FILE}") endif() if(MITK_USE_SUPERBUILD) set(MITK_BINARY_DIR ${proj}-superbuild) else() set(MITK_BINARY_DIR ${proj}-build) endif() set(proj_DEPENDENCIES) set(MITK_DEPENDS ${proj}) + + # Configure the MITK souce code location + + if(NOT MITK_SOURCE_DIR) + set(mitk_source_location + SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj} + GIT_REPOSITORY ${MITK_GIT_REPOSITORY} + GIT_TAG ${MITK_GIT_TAG} + ) + else() + set(mitk_source_location + SOURCE_DIR ${MITK_SOURCE_DIR} + ) + endif() ExternalProject_Add(${proj} - SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj} + ${mitk_source_location} BINARY_DIR ${MITK_BINARY_DIR} PREFIX ${proj}${ep_suffix} - GIT_REPOSITORY "${git_protocol}://git.mitk.org/MITK.git" - GIT_TAG "origin/master" INSTALL_COMMAND "" CMAKE_GENERATOR ${gen} CMAKE_ARGS ${ep_common_args} ${mitk_boolean_args} ${additional_mitk_cmakevars} -DBUILD_SHARED_LIBS:BOOL=ON + -DBUILD_TESTING:BOOL=${MITK_BUILD_TESTING} DEPENDS ${proj_DEPENDENCIES} ) if(MITK_USE_SUPERBUILD) set(MITK_DIR "${CMAKE_CURRENT_BINARY_DIR}/${MITK_BINARY_DIR}/MITK-build") else() set(MITK_DIR "${CMAKE_CURRENT_BINARY_DIR}/${MITK_BINARY_DIR}") endif() else() # The project is provided using MITK_DIR, nevertheless since other # projects may depend on MITK, let's add an 'empty' one MacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}") + + # Further, do some sanity checks in the case of a pre-built MITK + set(my_itk_dir ${ITK_DIR}) + set(my_vtk_dir ${VTK_DIR}) + set(my_qmake_executable ${QT_QMAKE_EXECUTABLE}) + + find_package(MITK REQUIRED) + + if(my_itk_dir AND NOT my_itk_dir STREQUAL ${ITK_DIR}) + message(FATAL_ERROR "ITK packages do not match:\n ${MY_PROJECT_NAME}: ${my_itk_dir}\n MITK: ${ITK_DIR}") + endif() + + if(my_vtk_dir AND NOT my_vtk_dir STREQUAL ${VTK_DIR}) + message(FATAL_ERROR "VTK packages do not match:\n ${MY_PROJECT_NAME}: ${my_vtk_dir}\n MITK: ${VTK_DIR}") + endif() + + if(my_qmake_executable AND NOT my_qmake_executable STREQUAL ${MITK_QMAKE_EXECUTABLE}) + message(FATAL_ERROR "Qt qmake does not match:\n ${MY_PROJECT_NAME}: ${my_qmake_executable}\n MITK: ${MITK_QMAKE_EXECUTABLE}") + endif() endif() diff --git a/Applications/PluginGenerator/ProjectTemplate/SuperBuild.cmake b/Applications/PluginGenerator/ProjectTemplate/SuperBuild.cmake index 6660beb1f8..93e4f41de8 100644 --- a/Applications/PluginGenerator/ProjectTemplate/SuperBuild.cmake +++ b/Applications/PluginGenerator/ProjectTemplate/SuperBuild.cmake @@ -1,201 +1,167 @@ -#-------------------------- ITK/VTK ------------------------- -# Provide an option to supply pre-built versions of ITK and VTK. -# If not found, MITK will build them itself during superbuild -set(VTK_DIR "" CACHE PATH "Use the supplied VTK installation/binary dir instead of superbuilding it") -set(ITK_DIR "" CACHE PATH "Use the supplied ITK installation/binary dir instead of superbuilding it") -mark_as_advanced(VTK_DIR ITK_DIR) - -#---------------------------- MITK -------------------------- - -if(MITK_DIR) - - # sanity checks in the case of a pre-built MITK - set(my_itk_dir ${ITK_DIR}) - set(my_vtk_dir ${VTK_DIR}) - set(my_qmake_executable ${QT_QMAKE_EXECUTABLE}) - - find_package(MITK REQUIRED) - - if(my_itk_dir AND NOT my_itk_dir STREQUAL ${ITK_DIR}) - message(FATAL_ERROR "ITK packages do not match:\n ${MY_PROJECT_NAME}: ${my_itk_dir}\n MITK: ${ITK_DIR}") - endif() - - if(my_vtk_dir AND NOT my_vtk_dir STREQUAL ${VTK_DIR}) - message(FATAL_ERROR "VTK packages do not match:\n ${MY_PROJECT_NAME}: ${my_vtk_dir}\n MITK: ${VTK_DIR}") - endif() - - if(my_qmake_executable AND NOT my_qmake_executable STREQUAL ${MITK_QMAKE_EXECUTABLE}) - message(FATAL_ERROR "Qt qmake does not match:\n ${MY_PROJECT_NAME}: ${my_qmake_executable}\n MITK: ${MITK_QMAKE_EXECUTABLE}") - endif() - +#----------------------------------------------------------------------------- +# ExternalProjects +#----------------------------------------------------------------------------- + +set(external_projects + MITK + ) + +set(EXTERNAL_MITK_DIR "${MITK_DIR}" CACHE PATH "Path to MITK build directory") +mark_as_advanced(EXTERNAL_MITK_DIR) +if(EXTERNAL_MITK_DIR) + set(MITK_DIR ${EXTERNAL_MITK_DIR}) endif() +# Look for git early on, if needed +if(NOT MITK_DIR AND MITK_USE_CTK AND NOT CTK_DIR) + find_package(Git REQUIRED) +endif() #----------------------------------------------------------------------------- # External project settings #----------------------------------------------------------------------------- include(ExternalProject) set(ep_base "${CMAKE_BINARY_DIR}/CMakeExternals") set_property(DIRECTORY PROPERTY EP_BASE ${ep_base}) set(ep_install_dir "${CMAKE_BINARY_DIR}/CMakeExternals/Install") set(ep_suffix "-cmake") set(ep_build_shared_libs ON) set(ep_build_testing OFF) # Compute -G arg for configuring external projects with the same CMake generator: if(CMAKE_EXTRA_GENERATOR) set(gen "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}") else() set(gen "${CMAKE_GENERATOR}") endif() # Use this value where semi-colons are needed in ep_add args: set(sep "^^") ## if(MSVC90 OR MSVC10) set(ep_common_C_FLAGS "${CMAKE_C_FLAGS} /bigobj /MP") set(ep_common_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /MP") else() set(ep_common_C_FLAGS "${CMAKE_C_FLAGS} -DLINUX_EXTRA") set(ep_common_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLINUX_EXTRA") endif() set(ep_common_args -DBUILD_TESTING:BOOL=${ep_build_testing} -DCMAKE_INSTALL_PREFIX:PATH=${ep_install_dir} -DBUILD_SHARED_LIBS:BOOL=${ep_build_shared_libs} -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} "-DCMAKE_C_FLAGS:STRING=${ep_common_C_FLAGS}" "-DCMAKE_CXX_FLAGS:STRING=${ep_common_CXX_FLAGS}" ) -#----------------------------------------------------------------------------- -# Git protocol option -#----------------------------------------------------------------------------- - -option(${MY_PROJECT_NAME}_USE_GIT_PROTOCOL "If behind a firewall turn this OFF to use http instead." OFF) -mark_as_advanced(${MY_PROJECT_NAME}_USE_GIT_PROTOCOL) - -set(git_protocol "git") -if(NOT ${MY_PROJECT_NAME}_USE_GIT_PROTOCOL) - set(git_protocol "http") -endif() - -#----------------------------------------------------------------------------- -# ExternalProjects -#----------------------------------------------------------------------------- - -set(external_projects - MITK - ) - # Include external projects foreach(p ${external_projects}) include(CMakeExternals/${p}.cmake) endforeach() #----------------------------------------------------------------------------- # Set superbuild boolean args #----------------------------------------------------------------------------- set(my_cmake_boolean_args WITH_COVERAGE BUILD_TESTING ${MY_PROJECT_NAME}_BUILD_ALL_PLUGINS ) #----------------------------------------------------------------------------- # Create the final variable containing superbuild boolean args #----------------------------------------------------------------------------- set(my_superbuild_boolean_args) foreach(my_cmake_arg ${my_cmake_boolean_args}) list(APPEND my_superbuild_boolean_args -D${my_cmake_arg}:BOOL=${${my_cmake_arg}}) endforeach() #----------------------------------------------------------------------------- # Project Utilities #----------------------------------------------------------------------------- set(proj ${MY_PROJECT_NAME}-Utilities) ExternalProject_Add(${proj} DOWNLOAD_COMMAND "" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" DEPENDS # Mandatory dependencies ${MITK_DEPENDS} # Optional dependencies ) #----------------------------------------------------------------------------- # Project Configure #----------------------------------------------------------------------------- set(proj ${MY_PROJECT_NAME}-Configure) ExternalProject_Add(${proj} DOWNLOAD_COMMAND "" CMAKE_GENERATOR ${gen} CMAKE_CACHE_ARGS ${ep_common_args} ${my_superbuild_boolean_args} -D${MY_PROJECT_NAME}_USE_SUPERBUILD:BOOL=OFF -D${MY_PROJECT_NAME}_CONFIGURED_VIA_SUPERBUILD:BOOL=ON -DCTEST_USE_LAUNCHERS:BOOL=${CTEST_USE_LAUNCHERS} -D${MY_PROJECT_NAME}_SUPERBUILD_BINARY_DIR:PATH=${PROJECT_BINARY_DIR} -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DMITK_DIR:PATH=${MITK_DIR} -DITK_DIR:PATH=${ITK_DIR} -DVTK_DIR:PATH=${VTK_DIR} SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} BINARY_DIR ${CMAKE_BINARY_DIR}/${MY_PROJECT_NAME}-build BUILD_COMMAND "" INSTALL_COMMAND "" DEPENDS ${MY_PROJECT_NAME}-Utilities ) #----------------------------------------------------------------------------- # Project #----------------------------------------------------------------------------- if(CMAKE_GENERATOR MATCHES ".*Makefiles.*") set(_build_cmd "$(MAKE)") else() set(_build_cmd ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/${MY_PROJECT_NAME}-build --config ${CMAKE_CFG_INTDIR}) endif() # The variable SUPERBUILD_EXCLUDE_${MY_PROJECT_NAME}BUILD_TARGET should be set when submitting to a dashboard if(NOT DEFINED SUPERBUILD_EXCLUDE_${MY_PROJECT_NAME}BUILD_TARGET OR NOT SUPERBUILD_EXCLUDE_${MY_PROJECT_NAME}BUILD_TARGET) set(_target_all_option "ALL") else() set(_target_all_option "") endif() add_custom_target(${MY_PROJECT_NAME}-build ${_target_all_option} COMMAND ${_build_cmd} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${MY_PROJECT_NAME}-build DEPENDS ${MY_PROJECT_NAME}-Configure ) #----------------------------------------------------------------------------- # Custom target allowing to drive the build of the project itself #----------------------------------------------------------------------------- add_custom_target(${MY_PROJECT_NAME} COMMAND ${_build_cmd} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${MY_PROJECT_NAME}-build )