diff --git a/CMake/MITKDashboardScript.NEWTEMPLATE.cmake b/CMake/MITKDashboardScript.NEWTEMPLATE.cmake new file mode 100644 index 0000000000..30c6fb472d --- /dev/null +++ b/CMake/MITKDashboardScript.NEWTEMPLATE.cmake @@ -0,0 +1,331 @@ +#[===========================================================================[ + + 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(CTEST_BUILD_NAME "") # Automatically set but can be overridden here + +set(GIT_REPOSITORY https://phabricator.mitk.org/source/mitk.git) + +set(GIT_TAG T25882-CDash-v2.6) # Git branch name, tag, or commit hash + +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() + +#[===========================================================================[ + + Actual script + + ]===========================================================================] + +find_program(CTEST_GIT_COMMAND git) + +#[[ Set source and binary directories to *relative* paths which is important + to create the Git commands below. The directories are converted to + absolute paths afterwards.]] + +set(CTEST_SOURCE_DIRECTORY src/MITK) +set(CTEST_BINARY_DIRECTORY build) + +set(CTEST_CHECKOUT_COMMAND "\"${CTEST_GIT_COMMAND}\" clone") + +if(GIT_SHALLOW_CLONE) + set(CTEST_CHECKOUT_COMMAND "${CTEST_CHECKOUT_COMMAND} --depth 1") +endif() + +set(CTEST_CHECKOUT_COMMAND "${CTEST_CHECKOUT_COMMAND} -b ${GIT_TAG} ${GIT_REPOSITORY} ${CTEST_SOURCE_DIRECTORY}") + +set(CTEST_UPDATE_OPTIONS "origin ${GIT_TAG}") + +if(GIT_SHALLOW_CLONE) + set(CTEST_UPDATE_OPTIONS "--depth=1 ${CTEST_UPDATE_OPTIONS}") +endif() + +get_filename_component(CTEST_SOURCE_DIRECTORY ${CTEST_SOURCE_DIRECTORY} ABSOLUTE) +get_filename_component(CTEST_BINARY_DIRECTORY ${CTEST_BINARY_DIRECTORY} ABSOLUTE) + +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() + +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() + +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} +) + +message("====== [ MITK SuperBuild - ${MITK_BUILD_CONFIGURATION} configuration ] ======") + +ctest_configure( + OPTIONS "${cmake_options}" + RETURN_VALUE config_return_value) +ctest_submit(PARTS Configure) + +if(NOT config_return_value EQUAL 0) + 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}) ] ======") + ctest_build(TARGET ${target} + NUMBER_ERRORS num_build_errors + RETURN_VALUE build_return_value + ${build_options}) + ctest_submit(PARTS Build) + + if(NOT (build_return_value EQUAL 0 AND num_build_errors EQUAL 0)) + 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) + message(FATAL_ERROR "SUPERBUILD_TARGETS variable not set in SuperBuildTargets.cmake") +endif() + +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() ]]