BASIS  r3148
basistest.ctest
Go to the documentation of this file.
00001 ##############################################################################
00002 # @file  basistest.ctest
00003 # @brief CTest script used to test BASIS projects.
00004 #
00005 # To display the help of this CTest script, run:
00006 # @code
00007 # ctest -S basistest.ctest,help
00008 # @endcode
00009 #
00010 # Copyright (c) 2011, 2012 University of Pennsylvania. All rights reserved.<br />
00011 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00012 #
00013 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00014 #
00015 # @ingroup Tools
00016 ##############################################################################
00017 
00018 if (POLICY CMP0007)
00019   cmake_policy(SET CMP0007 NEW)
00020 endif ()
00021 if (POLICY CMP0009)
00022   cmake_policy(SET CMP0009 NEW)
00023 endif ()
00024 
00025 # ============================================================================
00026 # constants - define at first
00027 # ============================================================================
00028 
00029 # names of options whose name will be added to CTEST_TEST_OPTIONS
00030 # instead of CTEST_CMAKE_OPTIONS
00031 set (KNOWN_CTEST_TEST_OPTIONS
00032   START
00033   END
00034   STRIDE
00035   INCLUDE
00036   INCLUDE_LABEL
00037   EXCLUDE
00038   EXCLUDE_LABEL
00039   PARALLEL_LEVEL
00040 )
00041 
00042 # start time of Nightly test model
00043 #
00044 # All Nightly tests which are executed within a time window of 24 hours
00045 # starting at the specified start time, will replace previous submissions
00046 # made within the same time frame such that for each time frame of 24 hours
00047 # only one result of test executions is present on the dashboard.
00048 # The execution of the Nightly tests is usually triggered automatically
00049 # via a scheduled cron job that is run once every 24 hours.
00050 #
00051 # Use the Continuous or Experimental test models if you want to execute
00052 # tests manually.
00053 set (CTEST_NIGHTLY_START_TIME "01:00:00 EST")
00054 
00055 # ============================================================================
00056 # help
00057 # ============================================================================
00058 
00059 # ----------------------------------------------------------------------------
00060 ## @brief Print usage section of usage information and help screen.
00061 #
00062 # @param [in] ARGN Not used.
00063 #
00064 # @returns Nothing.
00065 
00066 function (print_usage)
00067   message ("Usage:
00068   ctest [ctest options] -S [,option[=value]]*
00069 
00070   Note: No commas or equality signs are allowed inside of option values even
00071         if the value is enclosed by quotation marks.")
00072 endfunction ()
00073 
00074 # ----------------------------------------------------------------------------
00075 ## @brief Print options section of usage information and help screen.
00076 #
00077 # @param [in] ARGN Not used.
00078 #
00079 # @returns Nothing.
00080 
00081 function (print_options)
00082   message (
00083 "  <variable>=<value>     Passes -D<variable>=<value> on to CMake for the
00084                          configuration of the build tree if the variable
00085                          name is not named in the following.
00086 
00087                          The values of the following variables are passed on
00088                          to the proper CTest scripting commands:")
00089   foreach (V IN LISTS KNOWN_CTEST_TEST_OPTIONS)
00090     message ("                           - ${V}")
00091   endforeach ()
00092   message ("
00093   project=<project>      Name of the BASIS project to test. If not given, this
00094                          script skips the update step. In this case, the srcdir
00095                          and bindir options have to be given, or the current
00096                          working directory must be the root of an already
00097                          configured build tree.
00098   basedir=<path>         Base path of both source and binary directory.
00099                          Default: \"${HOME}/comp_space/testing\".
00100   srcdir=<path>          Source directory. This option is required if this script
00101                          is executed in a build directory which has not been
00102                          configured yet and if the project option was not specified.
00103                          If it is run in the root directory of an already configured
00104                          build tree, however, the value of this option is read from
00105                          the CMakeCache.txt file. Otherwise, if the project option
00106                          was specified, it is set to
00107                          \"<basedir>/<model>/<project>-source/<branch>/\".
00108   bindir=<path>          Binary directory (i.e., root of build tree).
00109                          This option defaults to the current working directory
00110                          if the project option was not specified. Otherwise,
00111                          it defaults to
00112                          \"<basedir>/<model>/<site>/<project>-build/<branch>/\".
00113   url=<url>              Base URL of the project's SVN repository.
00114                          Only used if the project option was specified.
00115                          Default: \"https://sbia-svn.uphs.upenn.edu/projects/<project>\".
00116   branch=<name>          Name of the SVN branch to test, e.g., \"tags/1.0.0\".
00117                          Default: \"trunk\".
00118   model=<model>          Name of the dashboard model, i.e., one of
00119                          \"Nightly\", \"Continuous\", and \"Experimental\".
00120                          Default: \"Experimental\".
00121   memcheck               Perform memory check. Requires valgrind.
00122                          No memory checks are performed by default.
00123   coverage               Perform coverage analysis. Requires gcov.
00124                          No coverage analysis is performed by default.
00125   install                Perform installation after successful test execution.
00126                          Set CMAKE_INSTALL_PREFIX to change the default installation
00127                          prefix used by the project (or CMake). Moreover, the
00128                          DESTDIR environment variable can be set to change the
00129                          root directory used for installations.
00130                          Note: Currently this script just executes \"make install\",
00131                                i.e., it only works with the CMake Makefile generator.
00132   apidoc[=<path>]        If specified, the API documentation is build
00133                          and the built HTML documentation copied to the
00134                          specified directory if the install option is given as well.
00135                          If this option is given without argument, the default
00136                          installation directory is used.
00137   nosubmit               Do not submit test results to the dashboard.
00138   shared-source          Specify that each test site should use the same copy of
00139                          the sources. By default, each test site uses its own copy.
00140   shared-build           Specify that each test site should use the same binary
00141                          directories. By default, each test site uses its own copy.
00142   common-site=<prefix>   Do not distinguish between different sites with a common
00143                          prefix in the name. Useful when the test jobs are executed
00144                          on a commonly configured cluster.
00145   drop-site=<hostname>   CTest drop site, i.e., hostname of CDash server.
00146   site=<site>            Use given site name no matter on which actual machine
00147                          the test is executed.
00148   force-build            Force build even if no files were updated.
00149   force-test             Force test even if no files were updated.
00150   force                  Alias for options force-build, and force-test.
00151   tmpbin                 Delete binary directory on completion (also if not successful).
00152   help                   Prints help and exits without performing any test.
00153   helpshort              Prints short help and exits without performing any test.
00154   helpoptions            Prints help on options and exists without performing any test.
00155   version                Prints version information and exits.")
00156 endfunction ()
00157 
00158 # ----------------------------------------------------------------------------
00159 ## @brief Print contact section of usage information and help screen.
00160 #
00161 # @param [in] ARGN Not used.
00162 #
00163 # @returns Nothing.
00164 
00165 function (print_contact)
00166   message ("
00167 Contact:
00168   SBIA Group <sbia-software at uphs.upenn.edu>")
00169 endfunction ()
00170 
00171 # ----------------------------------------------------------------------------
00172 ## @brief Print help screen.
00173 #
00174 # @param [in] ARGN Not used.
00175 #
00176 # @returns Nothing.
00177 
00178 function (print_help)
00179   print_usage ()
00180   message ("
00181 Description:
00182   This CTest script is used at SBIA for nightly testing of software projects.
00183   Nightly tests are scheduled by a cron job, for example, every night once.
00184   Contrary to continous testing, does the nightly testing job not loop for
00185   a certain time of iterations and look for changes actively. The nightly
00186   testing job will only perform one test run and then exit.
00187 
00188   Note: Due to a bug in CTest 2.8.2, the first test will fail because of
00189         a missing CTestConfig.cmake file if the source tree is not checked
00190         out already. Therefore, the use of CTest 2.8.4 is recommened.
00191 
00192 Dashboard models:
00193   By default, the dashboard models \"Nightly\", \"Continuous\", and \"Experimental\"
00194   are configured as follows. These default configurations can be modified by
00195   supplying the available options listed below.
00196   
00197     Nightly        Performs all test stages even if the project has not been
00198                    updated since the last test run.
00199     Continuous     Performs an update of the project's working copy and
00200                    exits without submission of any test results if no files
00201                    were updated. Otherwise, it performs all test stages.
00202     Experimental   Performs all test stages even if the project has not been
00203                    updated since the last test run.
00204  
00205   Attention: For each model, only one test process may be running for each
00206              project on each site at one time.
00207              
00208 Build configurations:
00209   By default, the Release configuration is used. If the coverage option is
00210   given, the Coverage configuration is used. If the memcheck option is given
00211   instead, the MemCheck configuration is used. If both coverage and memcheck
00212   options are given, the Coverage configuration is chosen because it generally
00213   can also be used to perform memory checks, while the reported line numbers
00214   may be incorrect in this case, however. Use the CMAKE_BUILD_TYPE variable
00215   to explicitly specify a build configuration.")
00216   message ("
00217 Options:")
00218   print_options ()
00219   message ("
00220 Example:
00221   ctest -V -S basistest.ctest
00222 
00223     Run this command in the root directory of an already configured build tree
00224     to test this project.
00225 
00226   ctest -V -S basistest.ctest,coverage
00227 
00228     Run this command in the root directory of an already configured build tree
00229     to test this project and include coverage analysis results in the test report.
00230 
00231   ctest -V -S basistest.ctest,project=BASIS,model=Experimental,coverage,memcheck
00232 
00233     Performs an experimental nightly test of the main development branch of
00234     BASIS itself, including coverage analysis and memory checks.
00235     The -V option of ctest enables more verbose output of CTest.
00236     Even more verbose output can be requested using -VV.")
00237   print_contact ()
00238 endfunction ()
00239 
00240 # ----------------------------------------------------------------------------
00241 ## @brief Print usage information.
00242 #
00243 # @param [in] ARGN Not used.
00244 #
00245 # @returns Nothing.
00246 
00247 function (print_helpshort)
00248   print_usage ()
00249   message ("
00250 Options:")
00251   print_options ()
00252   print_contact ()
00253 endfunction ()
00254 
00255 # ----------------------------------------------------------------------------
00256 ## @brief Print version information.
00257 #
00258 # @param [in] ARGN Not used.
00259 #
00260 # @returns Nothing.
00261 
00262 function (print_version)
00263   set (VERSION_INFO "version 0.0.0")
00264   if (3148 GREATER 0) # project revision > 0
00265     set (VERSION_INFO "${VERSION_INFO} (revision 3148)")
00266   endif ()
00267   message ("CTest script  (BASIS) ${VERSION_INFO}")
00268   message ("Copyright (c) 2011 University of Pennsylvania. All rights reserved.")
00269   message ("See COPYING file or https://www.rad.upenn.edu/sbia/software/license.html.")
00270 endfunction ()
00271 
00272 # ============================================================================
00273 # helpers
00274 # ============================================================================
00275 
00276 # ----------------------------------------------------------------------------
00277 ## @brief Read value from CMake cache.
00278 #
00279 # @param [in, out] VAR  Name of CMake variable.
00280 # @param [in]      ARGN Not used.
00281 #
00282 # @returns Sets @p VAR to the value of the cached variable @p VAR.
00283 function (read_cmake_cache_value VAR)
00284   file (STRINGS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" ENTRY REGEX "${VAR}:.*=(.*)")
00285   string (REGEX REPLACE "${VAR}:.*=(.*)" "\\1" VALUE "${ENTRY}")
00286   set (${VAR} "${VALUE}" PARENT_SCOPE)
00287 endfunction ()
00288 
00289 # ----------------------------------------------------------------------------
00290 ## @brief Adjust information attached to test results using CMakeCache.txt.
00291 #
00292 # @param [in] ARGN List of XML test report files without directory path.
00293 #                  If omitted, this function globs for all XML files in
00294 #                  the <tt>Testing/&lt;tag&gt;/</tt> directory.
00295 function (update_metadata)
00296   # get compiler information from CMake cache
00297   if (EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
00298     if (WIN32)
00299       set (NAME_COMPONENT "NAME_WE")
00300     else ()
00301       set (NAME_COMPONENT "NAME")
00302     endif ()
00303     if (UNIX OR BORLAND)
00304       read_cmake_cache_value (CMAKE_CXX_COMPILER)
00305       set (COMPILER "${CMAKE_CXX_COMPILER}")
00306       get_filename_component (COMPILER_NAME "${CMAKE_CXX_COMPILER}" ${NAME_COMPONENT})
00307     else ()
00308       read_cmake_cache_value (CMAKE_BUILD_TOOL)
00309       set (COMPILER "${CMAKE_BUILD_TOOL}")
00310       get_filename_component (COMPILER_NAME "${CMAKE_BUILD_TOOL}" ${NAME_COMPONENT})
00311     endif ()
00312     if (COMPILER_NAME MATCHES "msdev")
00313       set (COMPILER_NAME "vs60")
00314     elseif (COMPILER_NAME MATCHES "devenv")
00315       read_cmake_cache_value (CMAKE_GENERATOR)
00316       string (REGEX REPLACE "Visual Studio ([0-9][0-9]?)($|.*)" "\\1" NUMBER "${CMAKE_GENERATOR}") 
00317       if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio 7 .NET 2003")
00318         set (COMPILER_NAME "vs71")
00319       else ()
00320         set (COMPILER_NAME "vs${NUMBER}")
00321       endif ()
00322     endif ()
00323   else ()
00324     set (COMPILER      "unknown")
00325     set (COMPILER_NAME "unknown")
00326   endif ()
00327   # replace COMPILER_NAME in build name
00328   string (CONFIGURE "${CTEST_BUILD_NAME}" BUILDNAME @ONLY)
00329   message ("Change build name to ${BUILDNAME}")
00330   # get tag, i.e., subdirectory name required by update_metadata()
00331   if (EXISTS "${CTEST_BINARY_DIRECTORY}/Testing/TAG")
00332     file (STRINGS "${CTEST_BINARY_DIRECTORY}/Testing/TAG" TAG LIMIT_COUNT 1)
00333   else ()
00334     set (TAG ".")
00335   endif ()
00336   # modify submission files
00337   if (NOT ARGV)
00338     file (
00339       GLOB_RECURSE
00340         ARGV
00341       RELATIVE
00342         "${CTEST_BINARY_DIRECTORY}/Testing/${TAG}"
00343       "${CTEST_BINARY_DIRECTORY}/Testing/${TAG}/*.xml"
00344     )
00345   endif ()
00346   foreach (SUBMISSION_FILE IN LISTS ARGV)
00347     set (SUBMISSION_FILE "${CTEST_BINARY_DIRECTORY}/Testing/${TAG}/${SUBMISSION_FILE}")
00348     # read submission file
00349     file (READ "${SUBMISSION_FILE}" XML)
00350     # set compiler name if necessary
00351     string (REPLACE "CompilerName=\"\"" "CompilerName=\"${COMPILER}\"" XML "${XML}")
00352     string (REPLACE "<CompilerName></CompilerName>" "<CompilerName>${COMPILER}</CompilerName>" XML "${XML}")
00353     # replace intermediate build name
00354     string (REPLACE "BuildName=\"\"" "BuildName=\"${BUILDNAME}\"" XML "${XML}")
00355     string (REPLACE "<BuildName></BuildName>" "<BuildName>${BUILDNAME}</BuildName>" XML "${XML}")
00356     string (REPLACE "BuildName=\"${CTEST_BUILD_NAME}\"" "BuildName=\"${BUILDNAME}\"" XML "${XML}")
00357     string (REPLACE "<BuildName>${CTEST_BUILD_NAME}</BuildName>" "<BuildName>${BUILDNAME}</BuildName>" XML "${XML}")
00358     # write modified submission file
00359     file (WRITE "${SUBMISSION_FILE}" "${XML}")
00360   endforeach ()
00361 endfunction ()
00362 
00363 # ============================================================================
00364 # settings
00365 # ============================================================================
00366 
00367 set (MANUAL_MODE FALSE) # whether this script is running in manual mode, i.e.,
00368                         # executed in the build tree of an existing project
00369                         # instead of run by a cron job
00370 
00371 # ----------------------------------------------------------------------------
00372 # general
00373 set (CTEST_BASE_DIRECTORY   "$ENV{HOME}/comp_space/testing")
00374 set (CTEST_SOURCE_DIRECTORY "")
00375 set (CTEST_BINARY_DIRECTORY "")
00376 set (CTEST_MODEL            "Experimental")
00377 set (SHARED_SOURCE          FALSE)
00378 set (SHARED_BUILD           FALSE)
00379 set (SUBMIT_RESULTS         TRUE)
00380 set (COMMON_SITE_PREFIXES)
00381 
00382 set (CTEST_EXTRA_SUBMIT_FILES) # additional files for submission to the dashboard
00383 
00384 # ----------------------------------------------------------------------------
00385 # project attributes
00386 set (CTEST_PROJECT_NAME "")
00387 set (CTEST_SVN_URL      "https://sbia-svn.uphs.upenn.edu/projects/\@CTEST_PROJECT_NAME\@")
00388 set (CTEST_SVN_BRANCH   "trunk")
00389 
00390 # ----------------------------------------------------------------------------
00391 # build configuration
00392 set (CTEST_CMAKE_GENERATOR "Unix Makefiles") # CMake generator
00393 set (CTEST_BUILD_TYPE      "")               # build type/configuration
00394 set (CTEST_COMPILER_FLAGS  "")               # additional compiler flags
00395 set (CTEST_LINKER_FLAGS    "")               # additional linker flags
00396 set (CTEST_CMAKE_OPTIONS)
00397 set (WITH_APIDOC           FALSE)            # enable/disable build of API documentation
00398 set (WITH_MEMCHECK         FALSE)            # enable/disable memory checks
00399 set (WITH_COVERAGE         FALSE)            # enable/disable coverage analysis
00400 set (CTEST_MEMORYCHECK_SUPPRESSIONS_FILE)    # memory checks suppressions
00401 
00402 # ----------------------------------------------------------------------------
00403 # test execution
00404 set (CTEST_TEST_OPTIONS)
00405 
00406 set (FORCE_BUILD    FALSE)
00407 set (FORCE_TEST     FALSE)
00408 
00409 # ----------------------------------------------------------------------------
00410 # installation directories
00411 
00412 # install project files after successful test execution
00413 set (WITH_INSTALL FALSE)
00414 # output directory for built Doxygen documentation
00415 set (INSTALL_APIDOC_DIR)
00416 
00417 # ============================================================================
00418 # options
00419 # ============================================================================
00420 
00421 macro (set_option VAR)
00422   if (${ARGC} EQUAL 1)
00423     if (VALUE)
00424       set (${VAR} "${VALUE}")
00425     else ()
00426       set (FAILURE TRUE)
00427     endif ()
00428   else ()
00429     if (VALUE)
00430       set (FAILURE TRUE)
00431     else ()
00432       set (${VAR} "${ARGN}")
00433     endif ()
00434   endif ()
00435 endmacro ()
00436 
00437 macro (append_option VAR)
00438   if (VALUE)
00439     list (APPEND ${VAR} "${VALUE}")
00440   else ()
00441     set (FAILURE TRUE)
00442   endif ()
00443 endmacro ()
00444 
00445 string (REPLACE "," ";" ARGV "${CTEST_SCRIPT_ARG}")
00446 foreach (ARG ${ARGV})
00447   set (FAILURE FALSE)
00448   set (OPTION "")
00449   set (VALUE  "")
00450 
00451   string (REPLACE "=" ";" PARTS "${ARG}")
00452   list (LENGTH PARTS LEN)
00453 
00454   if (LEN EQUAL 1)
00455     set (OPTION "${PARTS}")
00456   elseif (LEN EQUAL 2)
00457     list (GET PARTS 0 OPTION)
00458     list (GET PARTS 1 VALUE)
00459   endif ()
00460  
00461   if (OPTION)
00462     if (${OPTION} STREQUAL "project")
00463       set_option (CTEST_PROJECT_NAME)
00464     elseif (${OPTION} STREQUAL "model")
00465       set_option (CTEST_MODEL)
00466     elseif (${OPTION} STREQUAL "basedir")
00467       set_option (CTEST_BASE_DIRECTORY)
00468     elseif (${OPTION} STREQUAL "srcdir")
00469       set_option (CTEST_SOURCE_DIRECTORY)
00470     elseif (${OPTION} STREQUAL "bindir")
00471       set_option (CTEST_BINARY_DIRECTORY)
00472     elseif (${OPTION} STREQUAL "url")
00473       set_option (CTEST_SVN_URL)
00474     elseif (${OPTION} STREQUAL "branch")
00475       set_option (CTEST_SVN_BRANCH)
00476     elseif (${OPTION} STREQUAL "memcheck")
00477       set_option (WITH_MEMCHECK TRUE)
00478     elseif (${OPTION} STREQUAL "coverage")
00479       set_option (WITH_COVERAGE TRUE)
00480     elseif (${OPTION} STREQUAL "tmpbin")
00481       set_option (TMPBIN TRUE)
00482     elseif (${OPTION} STREQUAL "install")
00483       set_option (WITH_INSTALL TRUE)
00484     elseif (${OPTION} STREQUAL "apidoc")
00485       set (WITH_APIDOC TRUE)
00486       if (VALUE)
00487         set_option (INSTALL_APIDOC_DIR)
00488       endif ()
00489     elseif (${OPTION} STREQUAL "shared-source")
00490       set_option (SHARED_SOURCE TRUE)
00491     elseif (${OPTION} STREQUAL "shared-build")
00492       set_option (SHARED_BUILD TRUE)
00493     elseif (${OPTION} STREQUAL "submit")
00494       set_option (SUBMIT_RESULTS TRUE)
00495     elseif (${OPTION} STREQUAL "nosubmit")
00496       set_option (SUBMIT_RESULTS FALSE)
00497     elseif (${OPTION} STREQUAL "common-site")
00498       append_option (COMMON_SITE_PREFIXES)
00499     elseif (${OPTION} STREQUAL "site")
00500         set_option (CTEST_SITE)
00501     elseif (${OPTION} STREQUAL "force")
00502       set_option (FORCE_BUILD TRUE)
00503       set_option (FORCE_TEST  TRUE)
00504     elseif (${OPTION} STREQUAL "force-build")
00505       set_option (FORCE_BUILD TRUE)
00506     elseif (${OPTION} STREQUAL "force-test")
00507       set_option (FORCE_TEST TRUE)
00508     elseif (${OPTION} STREQUAL "version")
00509       print_version ()
00510       return ()
00511     elseif (${OPTION} STREQUAL "help")
00512       print_help ()
00513       return ()
00514     elseif (${OPTION} STREQUAL "helpshort")
00515       print_helpshort ()
00516       return ()
00517     elseif (${OPTION} STREQUAL "helpoptions")
00518       print_options ()
00519       return ()
00520     else ()
00521       if (NOT VALUE)
00522         set (FAILURE TRUE)
00523       else ()
00524         string (TOUPPER "${OPTION}" OPTION_UPPER)
00525         list (FIND KNOWN_CTEST_TEST_OPTIONS "${OPTION_UPPER}" IDX)
00526         if (IDX EQUAL -1)
00527           if (OPTION MATCHES "^CMAKE_BUILD_TYPE$")
00528             set (CTEST_BUILD_TYPE "${VALUE}")
00529           else ()
00530             set (CTEST_CMAKE_OPTIONS "${CTEST_CMAKE_OPTIONS} \"-D${OPTION}=${VALUE}\"")
00531           endif ()
00532         else ()
00533           list (APPEND CTEST_TEST_OPTIONS "${OPTION_UPPER}" "${VALUE}")
00534         endif ()
00535       endif ()
00536     endif ()
00537   else ()
00538     set (FAILURE TRUE)
00539   endif ()
00540 
00541   if (FAILURE)
00542     message (FATAL_ERROR "Invalid options: ${CTEST_SCRIPT_ARG}
00543 Failed to parse argument \"${ARG}\" (option: ${OPTION}, value: ${VALUE})")
00544   endif ()
00545 endforeach ()
00546 
00547 if (NOT CTEST_PROJECT_NAME)
00548   set (MANUAL_MODE TRUE)
00549   # automatically set binary directory if not specified
00550   if (NOT CTEST_BINARY_DIRECTORY)
00551     if (UNIX)
00552       find_program (PWD pwd)
00553     else ()
00554       find_program (PWD cd)
00555     endif ()
00556     execute_process (
00557       COMMAND "${PWD}"
00558       RESULT_VARIABLE RT
00559       OUTPUT_VARIABLE CWD
00560       OUTPUT_STRIP_TRAILING_WHITESPACE
00561     )
00562     if (RT EQUAL 0)
00563       set (CTEST_BINARY_DIRECTORY "${CWD}")
00564     else ()
00565       message (FATAL_ERROR "Failed to get current working directory! Try using the bindir option instead.")
00566     endif ()
00567   endif ()
00568   # set project name from CMake cache
00569   if (EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
00570     read_cmake_cache_value (CMAKE_PROJECT_NAME)
00571     if (NOT CMAKE_PROJECT_NAME)
00572       message (FATAL_ERROR "Failed to read project name from ${CTEST_BINARY_DIRECTORY}/CMakeCache.txt!")
00573     endif ()
00574     set (CTEST_PROJECT_NAME "${CMAKE_PROJECT_NAME}")
00575   endif ()
00576   # automatically set source directory if not specified
00577   if (NOT CTEST_SOURCE_DIRECTORY)
00578     if (NOT EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
00579       message (FATAL_ERROR "Missing CMakeCache.txt file! Either specify source directory using the srcdir option or initialize the build tree.")
00580     endif ()
00581     read_cmake_cache_value (${CTEST_PROJECT_NAME}_SOURCE_DIR)
00582     if (NOT ${CTEST_PROJECT_NAME}_SOURCE_DIR)
00583       message (FATAL_ERROR "Failed to read source directory from ${CTEST_BINARY_DIRECTORY}/CMakeCache.txt!")
00584     endif ()
00585     set (CTEST_SOURCE_DIRECTORY "${${CTEST_PROJECT_NAME}_SOURCE_DIR}")
00586   endif ()
00587 endif ()
00588 
00589 if (NOT CTEST_BINARY_DIRECTORY)
00590   set (CTEST_BINARY_DIRECTORY "${CTEST_SOURCE_DIRECTORY}")
00591 endif ()
00592 
00593 string (TOLOWER "${CTEST_PROJECT_NAME}" CTEST_PROJECT_NAME_LOWER)
00594 string (TOUPPER "${CTEST_PROJECT_NAME}" CTEST_PROJECT_NAME_UPPER)
00595 
00596 if (CTEST_MODEL MATCHES "Nightly|Experimental")
00597   set (FORCE_BUILD TRUE)
00598   set (FORCE_TEST  TRUE)
00599 endif ()
00600 
00601 # ============================================================================
00602 # drop site
00603 # ============================================================================
00604 
00605 # dashboard submission to SBIA CDash server
00606 #
00607 # Note: By default, CTest does not support HTTPS as submission method.
00608 #       In order to enable it, CTest (and hence CMake) has to be build
00609 #       manually with the option CMAKE_USE_OPENSSL enabled.
00610 set (CTEST_DROP_METHOD     "http")
00611 set (CTEST_DROP_SITE       "sbia-portal.uphs.upenn.edu")
00612 set (CTEST_DROP_LOCATION   "/cdash/submit.php?project=${CTEST_PROJECT_NAME}")
00613 set (CTEST_DROP_SITE_CDASH TRUE)
00614 
00615 # launchers
00616 #
00617 # See documentation of CTest.cmake module.
00618 set (CTEST_USE_LAUNCHERS 0)
00619 
00620 # ============================================================================
00621 # initialization
00622 # ============================================================================
00623 
00624 # ----------------------------------------------------------------------------
00625 # build type
00626 if (NOT CTEST_BUILD_TYPE)
00627   if (WITH_COVERAGE OR WITH_MEMCHECK)
00628     set (CTEST_BUILD_TYPE "Debug")
00629   else ()
00630     set (CTEST_BUILD_TYPE "Release")
00631   endif ()
00632 endif ()
00633 
00634 # ----------------------------------------------------------------------------
00635 # site information
00636 if (NOT CTEST_SITE)
00637   site_name (CTEST_SITE)
00638   # common site name
00639   if (COMMON_SITE_PREFIXES)
00640     foreach (P ${COMMON_SITE_PREFIXES})
00641       if (CTEST_SITE MATCHES "^${P}")
00642         set (CTEST_SITE "${P}")
00643         break ()
00644       endif ()
00645     endforeach ()
00646   endif ()
00647 endif ()
00648 
00649 # ----------------------------------------------------------------------------
00650 # build information
00651 
00652 # Note: The  pattern in the build name as written to the .xml files
00653 #       will be replaced by this script before the submission once the used
00654 #       compiler is known from the CMake cache.
00655 set (CTEST_BUILD_NAME   "${CMAKE_SYSTEM_NAME}-\@COMPILER_NAME\@")
00656 if (WITH_COVERAGE AND WITH_MEMCHECK)
00657   set (CTEST_BUILD_NAME "${CTEST_BUILD_NAME} (Coverage & MemCheck)")
00658 elseif (WITH_COVERAGE)
00659   set (CTEST_BUILD_NAME "${CTEST_BUILD_NAME} (Coverage)")
00660 elseif (WITH_MEMCHECK)
00661   set (CTEST_BUILD_NAME "${CTEST_BUILD_NAME} (MemCheck)")
00662 endif ()
00663 
00664 # ----------------------------------------------------------------------------
00665 # directories
00666 if (NOT MANUAL_MODE)
00667   set (CTEST_BUILD_SUBDIR)
00668   if (WITH_COVERAGE AND WITH_MEMCHECK)
00669     set (CTEST_PREFIX "CoverageAndMemCheck")
00670   elseif (WITH_COVERAGE)
00671     set (CTEST_PREFIX "Coverage")
00672   elseif (WITH_MEMCHECK)
00673     set (CTEST_PREFIX "MemCheck")
00674   else ()
00675     set (CTEST_PREFIX "${CTEST_MODEL}")
00676     if (CTEST_BUILD_TYPE)
00677       set (CTEST_BUILD_SUBDIR "${CTEST_BUILD_TYPE}")
00678     else ()
00679       set (CTEST_BUILD_SUBDIR "Default")
00680     endif ()
00681   endif ()
00682   if (NOT CTEST_SOURCE_DIRECTORY)
00683     if (SHARED_SOURCE)
00684       set (CTEST_SOURCE_DIRECTORY "${CTEST_BASE_DIRECTORY}/${CTEST_PREFIX}/${CTEST_PROJECT_NAME}-source/${CTEST_SVN_BRANCH}")
00685     else ()
00686       set (CTEST_SOURCE_DIRECTORY "${CTEST_BASE_DIRECTORY}/${CTEST_PREFIX}/${CTEST_SITE}/${CTEST_PROJECT_NAME}-source/${CTEST_SVN_BRANCH}")
00687     endif ()
00688   endif ()
00689   if (NOT CTEST_BINARY_DIRECTORY)
00690     if (SHARED_BUILD)
00691       set (CTEST_BINARY_DIRECTORY "${CTEST_BASE_DIRECTORY}/${CTEST_PREFIX}/${CTEST_PROJECT_NAME}-build/${CTEST_SVN_BRANCH}/${CTEST_BUILD_SUBDIR}")
00692     else ()
00693       set (CTEST_BINARY_DIRECTORY "${CTEST_BASE_DIRECTORY}/${CTEST_PREFIX}/${CTEST_SITE}/${CTEST_PROJECT_NAME}-build/${CTEST_SVN_BRANCH}/${CTEST_BUILD_SUBDIR}")
00694     endif ()
00695   endif ()
00696 endif ()
00697 string (REGEX REPLACE "/$" "" CTEST_BINARY_DIRECTORY "${CTEST_BINARY_DIRECTORY}")
00698 string (REGEX REPLACE "/$" "" CTEST_SOURCE_DIRECTORY "${CTEST_SOURCE_DIRECTORY}")
00699 
00700 string (CONFIGURE "${INSTALL_APIDOC_DIR}" INSTALL_APIDOC_DIR)
00701 
00702 if (MANUAL_MODE)
00703   set (CTEST_START_WITH_EMPTY_BINARY_DIRECTORY FALSE)
00704 else ()
00705   set (CTEST_START_WITH_EMPTY_BINARY_DIRECTORY TRUE)
00706 endif ()
00707 
00708 # ----------------------------------------------------------------------------
00709 # checkout / update
00710 find_program (
00711   CTEST_SVN_COMMAND
00712   NAMES basistest-svn
00713   HINTS "${CMAKE_CURRENT_LIST_DIR}/../../bin"
00714 )
00715 find_program (CTEST_SVN_COMMAND NAMES svn)
00716 
00717 if (NOT CTEST_SVN_COMMAND)
00718   message (FATAL_ERROR "Could not find \"basistest-svn\" or \"svn\" command!")
00719 endif ()
00720 
00721 string (CONFIGURE "${CTEST_SVN_URL}" CTEST_SVN_URL @ONLY)
00722 
00723 if (NOT MANUAL_MODE AND NOT EXISTS "${CTEST_SOURCE_DIRECTORY}/.svn")
00724   file (MAKE_DIRECTORY "${CTEST_SOURCE_DIRECTORY}") # in particular all missing parent directories
00725   set (CTEST_CHECKOUT_COMMAND "${CTEST_SVN_COMMAND} co \"${CTEST_SVN_URL}/${CTEST_SVN_BRANCH}\" ${CTEST_SOURCE_DIRECTORY}")
00726 endif ()
00727 set (CTEST_UPDATE_COMMAND "${CTEST_SVN_COMMAND}")
00728 
00729 # ----------------------------------------------------------------------------
00730 # coverage analysis
00731 if (WITH_COVERAGE)
00732   find_program (CTEST_COVERAGE_COMMAND NAMES gcov)
00733   if (NOT CTEST_COVERAGE_COMMAND)
00734     message (FATAL_ERROR "Could not find gcov! Only gcc and gcov supported to perform coverage analysis.")
00735   endif ()
00736   set (CTEST_COMPILER_FLAGS "${CTEST_COMPILER_FLAGS} -O0 -fprofile-arcs -ftest-coverage")
00737   set (CTEST_LINKER_FLAGS "${CTEST_LINKER_FLAGS} -fprofile-arcs")
00738 endif ()
00739 
00740 # ----------------------------------------------------------------------------
00741 # memory check
00742 if (WITH_MEMCHECK)
00743   # TODO Consider switching to AddressSanitizer instead, which requires the
00744   #      use of the clang compiler, however, with the compiler flag
00745   #      -faddress-sanitizer.
00746   find_program (CTEST_MEMORYCHECK_COMMAND NAMES valgrind)
00747   if (NOT CTEST_MEMORYCHECK_COMMAND)
00748     message (FATAL_ERROR "Could not find valgrind! Only valgrind supported as memory error detector.")
00749   endif ()
00750   if (NOT WITH_COVERAGE)
00751     set (CTEST_COMPILER_FLAGS "${CTEST_COMPILER_FLAGS} -O1")
00752   endif ()
00753   set (CTEST_COMPILER_FLAGS "${CTEST_COMPILER_FLAGS} -fno-omit-frame-pointer")
00754   if (CTEST_MEMORYCHECK_SUPPRESSIONS_FILE)
00755     if (NOT IS_ABSOLUTE "${CTEST_MEMORYCHECK_SUPPRESSIONS_FILE}")
00756       set (
00757         CTEST_MEMORYCHECK_SUPPRESSIONS_FILE
00758           "${CTEST_SOURCE_DIRECTORY}/${CTEST_MEMORYCHECK_SUPPRESSIONS_FILE}"
00759       )
00760     endif ()
00761     if (NOT EXISTS "${CTEST_MEMORYCHECK_SUPPRESSIONS_FILE}")
00762       message ("Memory check suppressions file ${CTEST_MEMORYCHECK_SUPPRESSIONS_FILE} not found!")
00763     endif ()
00764   endif ()
00765 endif ()
00766 
00767 # ----------------------------------------------------------------------------
00768 # configuration / build
00769 set (CTEST_CONFIGURE_COMMAND "\"${CMAKE_COMMAND}\"")
00770 if (CTEST_BUILD_TYPE)
00771   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=${CTEST_BUILD_TYPE}")
00772 endif ()
00773 if (CTEST_COMPILER_FLAGS)
00774   string (STRIP "${CTEST_COMPILER_FLAGS}" CTEST_COMPILER_FLAGS)
00775   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_C_FLAGS:STRING=${CTEST_COMPILER_FLAGS}\"")
00776   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_CXX_FLAGS:STRING=${CTEST_COMPILER_FLAGS}\"")
00777 endif ()
00778 if (CTEST_LINKER_FLAGS)
00779   string (STRIP "${CTEST_LINKER_FLAGS}" CTEST_LINKER_FLAGS)
00780   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_EXE_LINKER_FLAGS:STRING=${CTEST_LINKER_FLAGS}\"")
00781   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_MODULE_LINKER_FLAGS:STRING=${CTEST_LINKER_FLAGS}\"")
00782   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-DCMAKE_SHARED_LINKER_FLAGS:STRING=${CTEST_LINKER_FLAGS}\"")
00783 endif ()
00784 set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DBUILD_TESTING:BOOL=ON")
00785 if (WITH_APIDOC)
00786   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DBUILD_DOCUMENTATION:BOOL=ON -DBASIS_ALL_DOC:BOOL=ON")
00787   if (INSTALL_APIDOC_DIR)
00788     set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DBASIS_INSTALL_APIDOC_DIR:PATH=${INSTALL_APIDOC_DIR}")
00789   endif ()
00790 else ()
00791   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} -DBUILD_DOCUMENTATION:BOOL=OFF")
00792 endif ()
00793 if (CTEST_CMAKE_OPTIONS)
00794   set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} ${CTEST_CMAKE_OPTIONS}")
00795 endif ()
00796 set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-G${CTEST_CMAKE_GENERATOR}\"")
00797 set (CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"${CTEST_SOURCE_DIRECTORY}\"")
00798 
00799 # ============================================================================
00800 # testing
00801 # ============================================================================
00802 
00803 set (CONFIGURE_RESULT 1)   # whether configuration was successful (0 if it was)
00804 set (BUILD_RESULT     1)   # whether build was successful (0 if it was)
00805 
00806 # ----------------------------------------------------------------------------
00807 # in manual mode, preserve CMake cache to be able to restore it later
00808 if (MANUAL_MODE AND EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
00809   execute_process (
00810     COMMAND "${CMAKE_COMMAND}" -E copy
00811         "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt"
00812         "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak"
00813   )
00814 endif ()
00815 
00816 # ----------------------------------------------------------------------------
00817 # empty the binary directory
00818 if (CTEST_START_WITH_EMPTY_BINARY_DIRECTORY)
00819   ctest_empty_binary_directory ("${CTEST_BINARY_DIRECTORY}")
00820 endif ()
00821 
00822 # ----------------------------------------------------------------------------
00823 # start a new test run
00824 ctest_start ("${CTEST_MODEL}")
00825 
00826 # ----------------------------------------------------------------------------
00827 # update working copy
00828 set (UPDATED_FILES TRUE)
00829 
00830 if (NOT MANUAL_MODE)
00831   ctest_update (RETURN_VALUE NUM_FILES)
00832 
00833   if (NOT CTEST_CHECKOUT_COMMAND AND NUM_FILES EQUAL 0)
00834     set (UPDATED_FILES FALSE)
00835     if (NOT FORCE_BUILD)
00836       set (SUBMIT_RESULTS FALSE)
00837     endif ()
00838   endif ()
00839 endif ()
00840 
00841 # perform other test stages and submit results only if required
00842 if (FORCE_BUILD OR UPDATED_FILES)
00843 
00844   # --------------------------------------------------------------------------
00845   # configure build
00846 
00847   # Note: Also in manual mode to enforce the selected build configuration!
00848   ctest_configure (RETURN_VALUE CONFIGURE_RESULT)
00849 
00850   if (CONFIGURE_RESULT EQUAL 0)
00851     ctest_read_custom_files ("${CTEST_BINARY_DIRECTORY}")
00852   endif ()
00853 
00854   # --------------------------------------------------------------------------
00855   # build project
00856   if (CONFIGURE_RESULT EQUAL 0)
00857     ctest_build (NUMBER_ERRORS NUMBER_OF_ERRORS RETURN_VALUE BUILD_RESULT)
00858     if (NUMBER_OF_ERRORS GREATER 0)
00859       set (BUILD_RESULT "${NUMBER_OF_ERRORS}")
00860     endif ()
00861   endif ()
00862 
00863   # --------------------------------------------------------------------------
00864   # perform tests only if required
00865   if (BUILD_RESULT EQUAL 0 AND (FORCE_TEST OR UPDATED_FILES))
00866 
00867     # ------------------------------------------------------------------------
00868     # run tests
00869     if (WITH_COVERAGE OR NOT WITH_MEMCHECK)
00870       ctest_test (${CTEST_TEST_OPTIONS} RETURN_VALUE TEST_RESULT)
00871     endif ()
00872 
00873     # ---------------------------------------------------------------------------
00874     # perform installation
00875     if (WITH_INSTALL AND TEST_RESULT EQUAL 0)
00876       message ("Install project files")
00877       # First deinstall previously installed files to ensure that obsolete
00878       # files are removed. These obsolete files could otherwise be used by
00879       # other projects and the test would not reveal that the projects are
00880       # actually no longer compatible.
00881       read_cmake_cache_value (CMAKE_INSTALL_PREFIX)
00882       set (UNINSTALLER "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/uninstall-${CTEST_PROJECT_NAME_LOWER}")
00883       if (EXISTS "${UNINSTALLER}")
00884         execute_process (
00885           COMMAND           "${UNINSTALLER}"
00886           WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}"
00887           TIMEOUT           1800 # 30 minutes
00888           RESULT_VARIABLE   UNINSTALL_RESULT
00889           OUTPUT_FILE       "${CTEST_BINARY_DIRECTORY}/install.log"
00890           ERROR_FILE        "${CTEST_BINARY_DIRECTORY}/install.log"
00891         )
00892       else ()
00893         execute_process (
00894           COMMAND           make uninstall
00895           WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}"
00896           TIMEOUT           1800 # 30 minutes
00897           RESULT_VARIABLE   UNINSTALL_RESULT
00898           OUTPUT_FILE       "${CTEST_BINARY_DIRECTORY}/install.log"
00899           ERROR_FILE        "${CTEST_BINARY_DIRECTORY}/install.log"
00900         )
00901       endif ()
00902       # install new files
00903       execute_process (
00904         COMMAND           make install
00905         WORKING_DIRECTORY "${CTEST_BINARY_DIRECTORY}"
00906         TIMEOUT           1800 # 30 minutes
00907         RESULT_VARIABLE   INSTALL_RESULT
00908         OUTPUT_FILE       "${CTEST_BINARY_DIRECTORY}/install.log"
00909         ERROR_FILE        "${CTEST_BINARY_DIRECTORY}/install.log"
00910       )
00911       # submit log file in case of errors to dashboard
00912       if (NOT UNINSTALL_RESULT EQUAL 0 OR NOT INSTALL_RESULT EQUAL 0)
00913         list (APPEND CTEST_NOTES_FILES "${CTEST_BINARY_DIRECTORY}/install.log")
00914       endif ()
00915     endif ()
00916 
00917     # --------------------------------------------------------------------------
00918     # perform coverage analysis
00919     if (WITH_COVERAGE AND CTEST_COVERAGE_COMMAND)
00920       ctest_coverage ()
00921     endif ()
00922 
00923     # --------------------------------------------------------------------------
00924     # perform memory checks
00925     if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND)
00926       ctest_memcheck (${CTEST_TEST_OPTIONS})
00927     endif ()
00928 
00929   endif ()
00930 
00931 endif ()
00932 
00933 # -----------------------------------------------------------------------------
00934 # adjust test result meta-data - even if these will not be submitted yet
00935 update_metadata ()
00936 
00937 # -----------------------------------------------------------------------------
00938 # submit results
00939 if (SUBMIT_RESULTS)
00940   ctest_submit ()
00941 endif ()
00942 
00943 # -----------------------------------------------------------------------------
00944 # clean up
00945 if (TMPBIN)
00946   file (REMOVE_RECURSE "${CTEST_BINARY_DIRECTORY}")
00947 else ()
00948   if (MANUAL_MODE AND EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak")
00949     execute_process (
00950       COMMAND "${CMAKE_COMMAND}" -E compare_files 
00951           "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt"
00952           "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak"
00953       RESULT_VARIABLE RT
00954       OUTPUT_QUIET
00955       ERROR_QUIET
00956     )
00957     if (RT EQUAL 0)
00958       file (REMOVE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak")
00959     else ()
00960       message ("Restoring build system configuration...")
00961       file (
00962         RENAME "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt.bak"
00963                "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt"
00964       )
00965       execute_process (
00966         COMMAND "${CMAKE_COMMAND}" "${CTEST_BINARY_DIRECTORY}"
00967         OUTPUT_QUIET
00968         RESULT_VARIABLE RT
00969       )
00970       if (RT EQUAL 0)
00971         message ("Restoring build system configuration... - done")
00972       else ()
00973         message ("Restoring build system configuration... - failed")
00974       endif ()
00975     endif ()
00976   endif ()
00977 endif ()