diff --git a/CMake/MITKDashboardScript.NEWTEMPLATE.cmake b/CMake/MITKDashboardScript.NEWTEMPLATE.cmake index b74dd8f960..c1173b847d 100644 --- a/CMake/MITKDashboardScript.NEWTEMPLATE.cmake +++ b/CMake/MITKDashboardScript.NEWTEMPLATE.cmake @@ -1,388 +1,413 @@ #[===========================================================================[ Configuration ]===========================================================================] set(CTEST_CMAKE_GENERATOR # "Visual Studio 15 2017" "Visual Studio 16 2019" # "Unix Makefiles" # "Ninja" ) set(CTEST_CMAKE_GENERATOR_PLATFORM # Win32 x64 ) set(CTEST_BUILD_CONFIGURATION # Debug Release # MinSizeRel # RelWithDebInfo ) set(CTEST_DASHBOARD_MODEL # Continuous Experimental # Nightly ) set(MITK_BUILD_CONFIGURATION # All WorkbenchRelease ) set(MITK_REPOSITORY https://phabricator.mitk.org/source/mitk.git) set(MITK_TAG master) # Git branch name, tag, or commit hash set(MITK_EXTENSIONS "MITK-ProjectTemplate|https://phabricator.mitk.org/source/mitk-projecttemplate.git|master" # "MITK-Diffusion|https://phabricator.mitk.org/source/mitk-diffusion.git|master" ) set(CTEST_BUILD_NAME "") # Automatically set but can be overridden here set(GIT_SHALLOW_CLONE ON) # TODO: Explain implications and when to switch off #[===========================================================================[ Helper functions ]===========================================================================] #[[ Call vswhere tool to query properties of the installed Visual Studio versions. Use OUTPUT_VARIABLE to specify the variable that is used to store the output of vswhere. All other arguments are passed to vswhere. The OUTPUT_VARIABLE is not touched if vswhere was not found or returned an error. ]] function(vswhere) cmake_parse_arguments(VSWHERE "" OUTPUT_VARIABLE "" ${ARGN}) if(NOT VSWHERE_OUTPUT_VARIABLE) return() endif() set(program_files_x86 "ProgramFiles(x86)") set(vswhere_executable "$ENV{${program_files_x86}}\\Microsoft Visual Studio\\Installer\\vswhere.exe") if(EXISTS ${vswhere_executable}) execute_process(COMMAND ${vswhere_executable} ${VSWHERE_UNPARSED_ARGUMENTS} RESULT_VARIABLE exit_code OUTPUT_VARIABLE output OUTPUT_STRIP_TRAILING_WHITESPACE) if(exit_code EQUAL 0 AND output) set(${VSWHERE_OUTPUT_VARIABLE} ${output} PARENT_SCOPE) endif() endif() endfunction() #[[ Extract the product line and major version from CTEST_CMAKE_GENERATOR if it starts with "Visual Studio xx yyyy", where xx is the major version and yyyy the product line. Use PRODUCT_LINE and MAJOR_VERSION to specify the variables that are used to store the results. ]] function(parse_visual_studio_generator) cmake_parse_arguments(VS "" "PRODUCT_LINE;MAJOR_VERSION" "" ${ARGN}) if(CTEST_CMAKE_GENERATOR MATCHES "^Visual Studio ([0-9]+) ([0-9]+)") if(VS_MAJOR_VERSION) set(${VS_MAJOR_VERSION} ${CMAKE_MATCH_1} PARENT_SCOPE) endif() if(VS_PRODUCT_LINE) set(${VS_PRODUCT_LINE} ${CMAKE_MATCH_2} PARENT_SCOPE) endif() endif() endfunction() function(get_os) cmake_parse_arguments(OS "" "NAME;VERSION" "" ${ARGN}) if(APPLE) if(OS_NAME) set(${OS_NAME} macOS PARENT_SCOPE) endif() if(OS_VERSION) execute_process(COMMAND sw_vers -productVersion RESULT_VARIABLE exit_code OUTPUT_VARIABLE version OUTPUT_STRIP_TRAILING_WHITESPACE) if(exit_code EQUAL 0 AND version) set(${OS_VERSION} ${version} PARENT_SCOPE) endif() endif() elseif(UNIX AND EXISTS /etc/os-release) # Linux with systemd file(READ /etc/os-release os_release) if(OS_NAME AND os_release MATCHES "NAME=\\\"?([^\\\"\\n]+)") set(${OS_NAME} ${CMAKE_MATCH_1} PARENT_SCOPE) endif() if(OS_VERSION AND os_release MATCHES "VERSION_ID=\\\"?([^\\\"\\n]+)") set(${OS_VERSION} ${CMAKE_MATCH_1} PARENT_SCOPE) endif() elseif(WIN32) if(OS_NAME) set(${OS_NAME} Windows PARENT_SCOPE) endif() if(OS_VERSION) execute_process(COMMAND wmic os get Version -value RESULT_VARIABLE exit_code OUTPUT_VARIABLE version OUTPUT_STRIP_TRAILING_WHITESPACE) if(exit_code EQUAL 0 AND version) if(version MATCHES "Version=([0-9]+)\\.([0-9]+)") set(${OS_VERSION} ${CMAKE_MATCH_1} PARENT_SCOPE) if(CMAKE_MATCH_2) set(${OS_VERSION} "${OS_VERSION}.${CMAKE_MATCH_2}" PARENT_SCOPE) endif() endif() endif() endif() endif() endfunction() #[[ Try to make up a descriptive build name (CTEST_BUILD_NAME) out of the operating system and the compiler. ]] function(set_default_build_name) unset(build_name) # Step 1/2: Determine operating system get_os(NAME os_name VERSION os_version) if(os_name AND os_version) set(build_name "${os_name} ${os_version}") else() # Fallback: use CMake variables that describe the system set(build_name ${CMAKE_SYSTEM_NAME}) if(CMAKE_SYSTEM_VERSION) # Not set in script mode. Give it a try, though. set(build_name "${build_name} ${CMAKE_SYSTEM_VERSION}") endif() endif() # Step 2/2: Determine compiler if(APPLE) # TODO elseif(UNIX) # TODO else() parse_visual_studio_generator(PRODUCT_LINE product_line MAJOR_VERSION version) if(product_line) set(build_name "${build_name} Visual Studio ${product_line}") vswhere(-version ${version} -property catalog_productDisplayVersion OUTPUT_VARIABLE exact_version) if(exact_version) set(build_name "${build_name} v${exact_version}") endif() endif() endif() set(CTEST_BUILD_NAME ${build_name} PARENT_SCOPE) endfunction() function(parse_mitk_extension) cmake_parse_arguments(EXTENSION "" "SOURCE_DIR;GIT_REPOSITORY;GIT_TAG" "" ${ARGN}) if(EXTENSION_UNPARSED_ARGUMENTS MATCHES "([^|]+)\\|([^|]+)\\|(.+)") if(EXTENSION_SOURCE_DIR) set(${EXTENSION_SOURCE_DIR} ${CMAKE_MATCH_1} PARENT_SCOPE) endif() if(EXTENSION_GIT_REPOSITORY) set(${EXTENSION_GIT_REPOSITORY} ${CMAKE_MATCH_2} PARENT_SCOPE) endif() if(EXTENSION_GIT_TAG) set(${EXTENSION_GIT_TAG} ${CMAKE_MATCH_3} PARENT_SCOPE) endif() endif() endfunction() #[===========================================================================[ Actual script ]===========================================================================] find_program(CTEST_GIT_COMMAND git) set(CTEST_CHECKOUT_COMMAND "\"${CTEST_GIT_COMMAND}\" clone") -set(checkout_command "${CTEST_GIT_COMMAND}" clone) +set(checkout_command "${CTEST_GIT_COMMAND}" clone --quiet) if(GIT_SHALLOW_CLONE) set(CTEST_CHECKOUT_COMMAND "${CTEST_CHECKOUT_COMMAND} --depth 1") list(APPEND checkout_command --depth 1) endif() set(CTEST_CHECKOUT_COMMAND "${CTEST_CHECKOUT_COMMAND} --branch ${MITK_TAG} ${MITK_REPOSITORY} MITK") set(CTEST_UPDATE_OPTIONS "--quiet") set(update_options --quiet) if(GIT_SHALLOW_CLONE) set(CTEST_UPDATE_OPTIONS "${CTEST_UPDATE_OPTIONS} --depth=1") list(APPEND update_options --depth=1) endif() set(CTEST_UPDATE_OPTIONS "${CTEST_UPDATE_OPTIONS} origin ${MITK_TAG}") list(APPEND update_options origin) set(CTEST_SOURCE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/src/MITK") set(CTEST_BINARY_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/build") -if(EXISTS "${CTEST_SOURCE_DIRECTORY}") - unset(CTEST_CHECKOUT_COMMAND) # Do not clone if source directory already exists -endif() - site_name(CTEST_SITE) if(NOT CTEST_BUILD_NAME) set_default_build_name() endif() +message("====== [ MITK ] ======") + +if(NOT EXISTS "${CTEST_SOURCE_DIRECTORY}") + ctest_start(${CTEST_DASHBOARD_MODEL}) +else() + unset(CTEST_CHECKOUT_COMMAND) # Do not clone if source directory already exists + + ctest_start(${CTEST_DASHBOARD_MODEL}) + ctest_update(RETURN_VALUE num_files_updated) + + if(num_files_updated EQUAL -1) + return() # Nothing to submit, error message already printed + endif() +endif() + +unset(MITK_EXTENSION_DIRS) set(up_to_date TRUE) foreach(extension ${MITK_EXTENSIONS}) parse_mitk_extension(${extension} SOURCE_DIR extension_dir GIT_REPOSITORY extension_repo GIT_TAG extension_tag) message("====== [ ${extension_dir} extension ] ======") set(absolute_extension_dir "${CMAKE_CURRENT_LIST_DIR}/src/${extension_dir}") + list(APPEND MITK_EXTENSION_DIRS "${absolute_extension_dir}") if(EXISTS "${absolute_extension_dir}") + execute_process(COMMAND "${CTEST_GIT_COMMAND}" rev-parse HEAD + WORKING_DIRECTORY "${absolute_extension_dir}" + OUTPUT_VARIABLE old_revision + OUTPUT_STRIP_TRAILING_WHITESPACE) + + message(" Updating the repository: ${absolute_extension_dir}\n Old revision of repository is: ${old_revision}") + execute_process(COMMAND "${CTEST_GIT_COMMAND}" fetch ${update_options} ${extension_tag} WORKING_DIRECTORY "${absolute_extension_dir}") execute_process(COMMAND "${CTEST_GIT_COMMAND}" diff --quiet HEAD FETCH_HEAD WORKING_DIRECTORY "${absolute_extension_dir}" RESULT_VARIABLE exit_code) if(NOT exit_code EQUAL 0) execute_process(COMMAND "${CTEST_GIT_COMMAND}" reset --hard FETCH_HEAD WORKING_DIRECTORY "${absolute_extension_dir}") + set(up_to_date FALSE) - else() - message("Up-to-date") endif() + + execute_process(COMMAND "${CTEST_GIT_COMMAND}" rev-parse HEAD + WORKING_DIRECTORY "${absolute_extension_dir}" + OUTPUT_VARIABLE new_revision + OUTPUT_STRIP_TRAILING_WHITESPACE) + + message(" New revision of repository is: ${new_revision}\n") else() + message(" First perform the initial checkout\n Source directory: ${absolute_extension_dir}\n") + execute_process(COMMAND ${checkout_command} --branch ${extension_tag} ${extension_repo} "src/${extension_dir}" WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") + + set(up_to_date FALSE) endif() endforeach() -message("====== [ MITK ] ======") - -ctest_start(${CTEST_DASHBOARD_MODEL}) -ctest_update(RETURN_VALUE num_files_updated) - -if(num_files_updated EQUAL -1) - return() # Nothing to submit, error message already printed -endif() - -return() - -ctest_submit(PARTS Update) +# ctest_submit(PARTS Update) set(cmake_options -D SUPERBUILD_EXCLUDE_MITKBUILD_TARGET:BOOL=TRUE -D MITK_CTEST_SCRIPT_MODE:STRING=${CTEST_DASHBOARD_MODEL} -D MITK_BUILD_CONFIGURATION:STRING=${MITK_BUILD_CONFIGURATION} ) +if(MITK_EXTENSION_DIRS) + string (REPLACE ";" "\\\;" MITK_EXTENSION_DIRS "${MITK_EXTENSION_DIRS}") + list(APPEND cmake_options -D MITK_EXTENSION_DIRS:STRING=${MITK_EXTENSION_DIRS}) +endif() + message("====== [ MITK SuperBuild - ${MITK_BUILD_CONFIGURATION} configuration ] ======") ctest_configure( OPTIONS "${cmake_options}" RETURN_VALUE config_return_value) -ctest_submit(PARTS Configure) + +# ctest_submit(PARTS Configure) if(NOT config_return_value EQUAL 0) - ctest_submit(PARTS Done) + # ctest_submit(PARTS Done) return() endif() include("${CTEST_BINARY_DIRECTORY}/SuperBuildTargets.cmake") if(SUPERBUILD_TARGETS) list(LENGTH SUPERBUILD_TARGETS n) set(i 1) set(build_options "") foreach(target ${SUPERBUILD_TARGETS}) - message("====== [ MITK SuperBuild - ${target} (${i}/${n}) ] ======") + message("\n====== [ MITK SuperBuild - ${target} (${i}/${n}) ] ======") ctest_build(TARGET ${target} NUMBER_ERRORS num_build_errors RETURN_VALUE build_return_value ${build_options}) - ctest_submit(PARTS Build) + # ctest_submit(PARTS Build) if(NOT (build_return_value EQUAL 0 AND num_build_errors EQUAL 0)) - ctest_submit(PARTS Done) + # ctest_submit(PARTS Done) return() endif() if(NOT build_options) set(build_options APPEND) endif() math(EXPR i "${i} + 1") endforeach() else() - ctest_submit(PARTS Done) + # ctest_submit(PARTS Done) message(FATAL_ERROR "SUPERBUILD_TARGETS variable not set in SuperBuildTargets.cmake") endif() -ctest_submit(PARTS Done) +# ctest_submit(PARTS Done) return() #[[ ctest_build(TARGET MITK-Data NUMBER_ERRORS NUMBER_OF_BUILD_ERRORS RETURN_VALUE BUILD_RETURN_VALUE) ctest_submit(PARTS Build) if(BUILD_RETURN_VALUE EQUAL 0 AND NUMBER_OF_BUILD_ERRORS EQUAL 0) ctest_build(TARGET MITK-Configure APPEND NUMBER_ERRORS NUMBER_OF_BUILD_ERRORS RETURN_VALUE BUILD_RETURN_VALUE) ctest_submit(PARTS Build) if(BUILD_RETURN_VALUE EQUAL 0 AND NUMBER_OF_BUILD_ERRORS EQUAL 0) ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}/MITK-build" APPEND NUMBER_ERRORS NUMBER_OF_BUILD_ERRORS RETURN_VALUE BUILD_RETURN_VALUE) ctest_submit(PARTS Build) if(BUILD_RETURN_VALUE EQUAL 0 AND NUMBER_OF_BUILD_ERRORS EQUAL 0) ctest_test(BUILD "${CTEST_BINARY_DIRECTORY}/MITK-build" EXCLUDE "(ProjectTemplate|Package)") ctest_submit(PARTS Test Done) else() ctest_submit(PARTS Done) # Error in Build Step (MITK) endif() else() ctest_submit(PARTS Done) # Error in Build step (Superbuild) endif() else() ctest_submit(PARTS Done) # Error in MITK-Data build step (Superbuild) endif() else() ctest_submit(PARTS Done) # Error in Configure step (Superbuild) endif() endif() ]]