CTest.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. # - Configure a project for testing with CTest/CDash
  2. # Include this module in the top CMakeLists.txt file of a project to
  3. # enable testing with CTest and dashboard submissions to CDash:
  4. # project(MyProject)
  5. # ...
  6. # include(CTest)
  7. # The module automatically creates a BUILD_TESTING option that selects
  8. # whether to enable testing support (ON by default). After including
  9. # the module, use code like
  10. # if(BUILD_TESTING)
  11. # # ... CMake code to create tests ...
  12. # endif()
  13. # to creating tests when testing is enabled.
  14. #
  15. # To enable submissions to a CDash server, create a CTestConfig.cmake
  16. # file at the top of the project with content such as
  17. # set(CTEST_PROJECT_NAME "MyProject")
  18. # set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
  19. # set(CTEST_DROP_METHOD "http")
  20. # set(CTEST_DROP_SITE "my.cdash.org")
  21. # set(CTEST_DROP_LOCATION "/submit.php?project=MyProject")
  22. # set(CTEST_DROP_SITE_CDASH TRUE)
  23. # (the CDash server can provide the file to a project administrator
  24. # who configures 'MyProject').
  25. # Settings in the config file are shared by both this CTest module and
  26. # the CTest command-line tool's dashboard script mode (ctest -S).
  27. #
  28. # While building a project for submission to CDash, CTest scans the
  29. # build output for errors and warnings and reports them with
  30. # surrounding context from the build log. This generic approach works
  31. # for all build tools, but does not give details about the command
  32. # invocation that produced a given problem. One may get more detailed
  33. # reports by adding
  34. # set(CTEST_USE_LAUNCHERS 1)
  35. # to the CTestConfig.cmake file. When this option is enabled, the
  36. # CTest module tells CMake's Makefile generators to invoke every
  37. # command in the generated build system through a CTest launcher
  38. # program. (Currently the CTEST_USE_LAUNCHERS option is ignored on
  39. # non-Makefile generators.) During a manual build each launcher
  40. # transparently runs the command it wraps. During a CTest-driven
  41. # build for submission to CDash each launcher reports detailed
  42. # information when its command fails or warns.
  43. # (Setting CTEST_USE_LAUNCHERS in CTestConfig.cmake is convenient, but
  44. # also adds the launcher overhead even for manual builds. One may
  45. # instead set it in a CTest dashboard script and add it to the CMake
  46. # cache for the build tree.)
  47. #=============================================================================
  48. # Copyright 2005-2009 Kitware, Inc.
  49. #
  50. # Distributed under the OSI-approved BSD License (the "License");
  51. # see accompanying file Copyright.txt for details.
  52. #
  53. # This software is distributed WITHOUT ANY WARRANTY; without even the
  54. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  55. # See the License for more information.
  56. #=============================================================================
  57. # (To distribute this file outside of CMake, substitute the full
  58. # License text for the above reference.)
  59. OPTION(BUILD_TESTING "Build the testing tree." ON)
  60. # function to turn generator name into a version string
  61. # like vs7 vs71 vs8 vs9
  62. FUNCTION(GET_VS_VERSION_STRING generator var)
  63. STRING(REGEX REPLACE "Visual Studio ([0-9][0-9]?)($|.*)" "\\1" NUMBER "${generator}")
  64. IF("${generator}" MATCHES "Visual Studio 7 .NET 2003")
  65. SET(ver_string "vs71")
  66. ELSE("${generator}" MATCHES "Visual Studio 7 .NET 2003")
  67. SET(ver_string "vs${NUMBER}")
  68. ENDIF("${generator}" MATCHES "Visual Studio 7 .NET 2003")
  69. SET(${var} ${ver_string} PARENT_SCOPE)
  70. ENDFUNCTION(GET_VS_VERSION_STRING)
  71. IF(BUILD_TESTING)
  72. # Setup some auxilary macros
  73. MACRO(SET_IF_NOT_SET var val)
  74. IF(NOT DEFINED "${var}")
  75. SET("${var}" "${val}")
  76. ENDIF(NOT DEFINED "${var}")
  77. ENDMACRO(SET_IF_NOT_SET)
  78. MACRO(SET_IF_SET var val)
  79. IF(NOT "${val}" MATCHES "^$")
  80. SET("${var}" "${val}")
  81. ENDIF(NOT "${val}" MATCHES "^$")
  82. ENDMACRO(SET_IF_SET)
  83. MACRO(SET_IF_SET_AND_NOT_SET var val)
  84. IF(NOT "${val}" MATCHES "^$")
  85. SET_IF_NOT_SET("${var}" "${val}")
  86. ENDIF(NOT "${val}" MATCHES "^$")
  87. ENDMACRO(SET_IF_SET_AND_NOT_SET)
  88. # Make sure testing is enabled
  89. ENABLE_TESTING()
  90. IF(EXISTS "${PROJECT_SOURCE_DIR}/CTestConfig.cmake")
  91. INCLUDE("${PROJECT_SOURCE_DIR}/CTestConfig.cmake")
  92. SET_IF_SET_AND_NOT_SET(NIGHTLY_START_TIME "${CTEST_NIGHTLY_START_TIME}")
  93. SET_IF_SET_AND_NOT_SET(DROP_METHOD "${CTEST_DROP_METHOD}")
  94. SET_IF_SET_AND_NOT_SET(DROP_SITE "${CTEST_DROP_SITE}")
  95. SET_IF_SET_AND_NOT_SET(DROP_SITE_USER "${CTEST_DROP_SITE_USER}")
  96. SET_IF_SET_AND_NOT_SET(DROP_SITE_PASSWORD "${CTEST_DROP_SITE_PASWORD}")
  97. SET_IF_SET_AND_NOT_SET(DROP_SITE_MODE "${CTEST_DROP_SITE_MODE}")
  98. SET_IF_SET_AND_NOT_SET(DROP_LOCATION "${CTEST_DROP_LOCATION}")
  99. SET_IF_SET_AND_NOT_SET(TRIGGER_SITE "${CTEST_TRIGGER_SITE}")
  100. SET_IF_SET_AND_NOT_SET(UPDATE_TYPE "${CTEST_UPDATE_TYPE}")
  101. ENDIF(EXISTS "${PROJECT_SOURCE_DIR}/CTestConfig.cmake")
  102. # the project can have a DartConfig.cmake file
  103. IF(EXISTS "${PROJECT_SOURCE_DIR}/DartConfig.cmake")
  104. INCLUDE("${PROJECT_SOURCE_DIR}/DartConfig.cmake")
  105. ELSE(EXISTS "${PROJECT_SOURCE_DIR}/DartConfig.cmake")
  106. # Dashboard is opened for submissions for a 24 hour period starting at
  107. # the specified NIGHTLY_START_TIME. Time is specified in 24 hour format.
  108. SET_IF_NOT_SET (NIGHTLY_START_TIME "00:00:00 EDT")
  109. SET_IF_NOT_SET(DROP_METHOD "http")
  110. SET_IF_NOT_SET (COMPRESS_SUBMISSION ON)
  111. ENDIF(EXISTS "${PROJECT_SOURCE_DIR}/DartConfig.cmake")
  112. SET_IF_NOT_SET (NIGHTLY_START_TIME "00:00:00 EDT")
  113. FIND_PROGRAM(CVSCOMMAND cvs )
  114. SET(CVS_UPDATE_OPTIONS "-d -A -P" CACHE STRING
  115. "Options passed to the cvs update command.")
  116. FIND_PROGRAM(SVNCOMMAND svn)
  117. FIND_PROGRAM(BZRCOMMAND bzr)
  118. FIND_PROGRAM(HGCOMMAND hg)
  119. FIND_PROGRAM(GITCOMMAND git)
  120. IF(NOT UPDATE_TYPE)
  121. IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CVS")
  122. SET(UPDATE_TYPE cvs)
  123. ELSEIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn")
  124. SET(UPDATE_TYPE svn)
  125. ELSEIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.bzr")
  126. SET(UPDATE_TYPE bzr)
  127. ELSEIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.hg")
  128. SET(UPDATE_TYPE hg)
  129. ELSEIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
  130. SET(UPDATE_TYPE git)
  131. ENDIF()
  132. ENDIF(NOT UPDATE_TYPE)
  133. STRING(TOLOWER "${UPDATE_TYPE}" _update_type)
  134. IF("${_update_type}" STREQUAL "cvs")
  135. SET(UPDATE_COMMAND "${CVSCOMMAND}")
  136. SET(UPDATE_OPTIONS "${CVS_UPDATE_OPTIONS}")
  137. ELSEIF("${_update_type}" STREQUAL "svn")
  138. SET(UPDATE_COMMAND "${SVNCOMMAND}")
  139. SET(UPDATE_OPTIONS "${SVN_UPDATE_OPTIONS}")
  140. ELSEIF("${_update_type}" STREQUAL "bzr")
  141. SET(UPDATE_COMMAND "${BZRCOMMAND}")
  142. SET(UPDATE_OPTIONS "${BZR_UPDATE_OPTIONS}")
  143. ELSEIF("${_update_type}" STREQUAL "hg")
  144. SET(UPDATE_COMMAND "${HGCOMMAND}")
  145. SET(UPDATE_OPTIONS "${HG_UPDATE_OPTIONS}")
  146. ELSEIF("${_update_type}" STREQUAL "git")
  147. SET(UPDATE_COMMAND "${GITCOMMAND}")
  148. SET(UPDATE_OPTIONS "${GIT_UPDATE_OPTIONS}")
  149. ENDIF()
  150. SET(DART_TESTING_TIMEOUT 1500 CACHE STRING
  151. "Maximum time allowed before CTest will kill the test.")
  152. SET(CTEST_SUBMIT_RETRY_DELAY 5 CACHE STRING
  153. "How long to wait between timed-out CTest submissions.")
  154. SET(CTEST_SUBMIT_RETRY_COUNT 3 CACHE STRING
  155. "How many times to retry timed-out CTest submissions.")
  156. FIND_PROGRAM(MEMORYCHECK_COMMAND
  157. NAMES purify valgrind boundscheck
  158. PATHS
  159. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Rational Software\\Purify\\Setup;InstallFolder]"
  160. DOC "Path to the memory checking command, used for memory error detection."
  161. )
  162. FIND_PROGRAM(SLURM_SBATCH_COMMAND sbatch DOC
  163. "Path to the SLURM sbatch executable"
  164. )
  165. FIND_PROGRAM(SLURM_SRUN_COMMAND srun DOC
  166. "Path to the SLURM srun executable"
  167. )
  168. SET(MEMORYCHECK_SUPPRESSIONS_FILE "" CACHE FILEPATH
  169. "File that contains suppressions for the memory checker")
  170. FIND_PROGRAM(SCPCOMMAND scp DOC
  171. "Path to scp command, used by CTest for submitting results to a Dart server"
  172. )
  173. FIND_PROGRAM(COVERAGE_COMMAND gcov DOC
  174. "Path to the coverage program that CTest uses for performing coverage inspection"
  175. )
  176. # set the site name
  177. SITE_NAME(SITE)
  178. # set the build name
  179. IF(NOT BUILDNAME)
  180. SET(DART_COMPILER "${CMAKE_CXX_COMPILER}")
  181. IF(NOT DART_COMPILER)
  182. SET(DART_COMPILER "${CMAKE_C_COMPILER}")
  183. ENDIF(NOT DART_COMPILER)
  184. IF(NOT DART_COMPILER)
  185. SET(DART_COMPILER "unknown")
  186. ENDIF(NOT DART_COMPILER)
  187. IF(WIN32)
  188. SET(DART_NAME_COMPONENT "NAME_WE")
  189. ELSE(WIN32)
  190. SET(DART_NAME_COMPONENT "NAME")
  191. ENDIF(WIN32)
  192. IF(NOT BUILD_NAME_SYSTEM_NAME)
  193. SET(BUILD_NAME_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
  194. ENDIF(NOT BUILD_NAME_SYSTEM_NAME)
  195. IF(WIN32)
  196. SET(BUILD_NAME_SYSTEM_NAME "Win32")
  197. ENDIF(WIN32)
  198. IF(UNIX OR BORLAND)
  199. GET_FILENAME_COMPONENT(DART_CXX_NAME
  200. "${CMAKE_CXX_COMPILER}" ${DART_NAME_COMPONENT})
  201. ELSE(UNIX OR BORLAND)
  202. GET_FILENAME_COMPONENT(DART_CXX_NAME
  203. "${CMAKE_BUILD_TOOL}" ${DART_NAME_COMPONENT})
  204. ENDIF(UNIX OR BORLAND)
  205. IF(DART_CXX_NAME MATCHES "msdev")
  206. SET(DART_CXX_NAME "vs60")
  207. ENDIF(DART_CXX_NAME MATCHES "msdev")
  208. IF(DART_CXX_NAME MATCHES "devenv")
  209. GET_VS_VERSION_STRING("${CMAKE_GENERATOR}" DART_CXX_NAME)
  210. ENDIF(DART_CXX_NAME MATCHES "devenv")
  211. SET(BUILDNAME "${BUILD_NAME_SYSTEM_NAME}-${DART_CXX_NAME}")
  212. ENDIF(NOT BUILDNAME)
  213. # the build command
  214. BUILD_COMMAND(MAKECOMMAND_DEFAULT_VALUE
  215. CONFIGURATION "\${CTEST_CONFIGURATION_TYPE}")
  216. SET(MAKECOMMAND ${MAKECOMMAND_DEFAULT_VALUE}
  217. CACHE STRING "Command to build the project")
  218. # the default build configuration the ctest build handler will use
  219. # if there is no -C arg given to ctest:
  220. SET(DEFAULT_CTEST_CONFIGURATION_TYPE "$ENV{CMAKE_CONFIG_TYPE}")
  221. IF(DEFAULT_CTEST_CONFIGURATION_TYPE STREQUAL "")
  222. SET(DEFAULT_CTEST_CONFIGURATION_TYPE "Release")
  223. ENDIF(DEFAULT_CTEST_CONFIGURATION_TYPE STREQUAL "")
  224. IF(NOT "${CMAKE_GENERATOR}" MATCHES "Make")
  225. SET(CTEST_USE_LAUNCHERS 0)
  226. ENDIF(NOT "${CMAKE_GENERATOR}" MATCHES "Make")
  227. IF(CTEST_USE_LAUNCHERS)
  228. SET(CTEST_LAUNCH_COMPILE "\"${CMAKE_CTEST_COMMAND}\" --launch --target-name <TARGET_NAME> --build-dir <CMAKE_CURRENT_BINARY_DIR> --output <OBJECT> --source <SOURCE> --language <LANGUAGE> --")
  229. SET(CTEST_LAUNCH_LINK "\"${CMAKE_CTEST_COMMAND}\" --launch --target-name <TARGET_NAME> --build-dir <CMAKE_CURRENT_BINARY_DIR> --output <TARGET> --target-type <TARGET_TYPE> --language <LANGUAGE> --")
  230. SET(CTEST_LAUNCH_CUSTOM "\"${CMAKE_CTEST_COMMAND}\" --launch --target-name <TARGET_NAME> --build-dir <CMAKE_CURRENT_BINARY_DIR> --output <OUTPUT> --")
  231. SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CTEST_LAUNCH_COMPILE}")
  232. SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CTEST_LAUNCH_LINK}")
  233. SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_CUSTOM "${CTEST_LAUNCH_CUSTOM}")
  234. ENDIF(CTEST_USE_LAUNCHERS)
  235. MARK_AS_ADVANCED(
  236. COVERAGE_COMMAND
  237. CVSCOMMAND
  238. SVNCOMMAND
  239. BZRCOMMAND
  240. HGCOMMAND
  241. GITCOMMAND
  242. CVS_UPDATE_OPTIONS
  243. SVN_UPDATE_OPTIONS
  244. BZR_UPDATE_OPTIONS
  245. MAKECOMMAND
  246. MEMORYCHECK_COMMAND
  247. MEMORYCHECK_SUPPRESSIONS_FILE
  248. PURIFYCOMMAND
  249. SCPCOMMAND
  250. SLURM_SBATCH_COMMAND
  251. SLURM_SRUN_COMMAND
  252. SITE
  253. CTEST_SUBMIT_RETRY_DELAY
  254. CTEST_SUBMIT_RETRY_COUNT
  255. )
  256. # BUILDNAME
  257. IF(NOT RUN_FROM_DART)
  258. SET(RUN_FROM_CTEST_OR_DART 1)
  259. INCLUDE(CTestTargets)
  260. SET(RUN_FROM_CTEST_OR_DART)
  261. ENDIF(NOT RUN_FROM_DART)
  262. ENDIF(BUILD_TESTING)