CTest.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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"
  64. NUMBER "${generator}")
  65. IF("${generator}" MATCHES "Visual Studio 7 .NET 2003")
  66. SET(ver_string "vs71")
  67. ELSE("${generator}" MATCHES "Visual Studio 7 .NET 2003")
  68. SET(ver_string "vs${NUMBER}")
  69. ENDIF("${generator}" MATCHES "Visual Studio 7 .NET 2003")
  70. SET(${var} ${ver_string} PARENT_SCOPE)
  71. ENDFUNCTION(GET_VS_VERSION_STRING)
  72. IF(BUILD_TESTING)
  73. # Setup some auxilary macros
  74. MACRO(SET_IF_NOT_SET var val)
  75. IF(NOT DEFINED "${var}")
  76. SET("${var}" "${val}")
  77. ENDIF(NOT DEFINED "${var}")
  78. ENDMACRO(SET_IF_NOT_SET)
  79. MACRO(SET_IF_SET var val)
  80. IF(NOT "${val}" MATCHES "^$")
  81. SET("${var}" "${val}")
  82. ENDIF(NOT "${val}" MATCHES "^$")
  83. ENDMACRO(SET_IF_SET)
  84. MACRO(SET_IF_SET_AND_NOT_SET var val)
  85. IF(NOT "${val}" MATCHES "^$")
  86. SET_IF_NOT_SET("${var}" "${val}")
  87. ENDIF(NOT "${val}" MATCHES "^$")
  88. ENDMACRO(SET_IF_SET_AND_NOT_SET)
  89. # Make sure testing is enabled
  90. ENABLE_TESTING()
  91. IF(EXISTS "${PROJECT_SOURCE_DIR}/CTestConfig.cmake")
  92. INCLUDE("${PROJECT_SOURCE_DIR}/CTestConfig.cmake")
  93. SET_IF_SET_AND_NOT_SET(NIGHTLY_START_TIME "${CTEST_NIGHTLY_START_TIME}")
  94. SET_IF_SET_AND_NOT_SET(DROP_METHOD "${CTEST_DROP_METHOD}")
  95. SET_IF_SET_AND_NOT_SET(DROP_SITE "${CTEST_DROP_SITE}")
  96. SET_IF_SET_AND_NOT_SET(DROP_SITE_USER "${CTEST_DROP_SITE_USER}")
  97. SET_IF_SET_AND_NOT_SET(DROP_SITE_PASSWORD "${CTEST_DROP_SITE_PASWORD}")
  98. SET_IF_SET_AND_NOT_SET(DROP_SITE_MODE "${CTEST_DROP_SITE_MODE}")
  99. SET_IF_SET_AND_NOT_SET(DROP_LOCATION "${CTEST_DROP_LOCATION}")
  100. SET_IF_SET_AND_NOT_SET(TRIGGER_SITE "${CTEST_TRIGGER_SITE}")
  101. SET_IF_SET_AND_NOT_SET(UPDATE_TYPE "${CTEST_UPDATE_TYPE}")
  102. ENDIF(EXISTS "${PROJECT_SOURCE_DIR}/CTestConfig.cmake")
  103. # the project can have a DartConfig.cmake file
  104. IF(EXISTS "${PROJECT_SOURCE_DIR}/DartConfig.cmake")
  105. INCLUDE("${PROJECT_SOURCE_DIR}/DartConfig.cmake")
  106. ELSE(EXISTS "${PROJECT_SOURCE_DIR}/DartConfig.cmake")
  107. # Dashboard is opened for submissions for a 24 hour period starting at
  108. # the specified NIGHTLY_START_TIME. Time is specified in 24 hour format.
  109. SET_IF_NOT_SET (NIGHTLY_START_TIME "00:00:00 EDT")
  110. SET_IF_NOT_SET(DROP_METHOD "http")
  111. SET_IF_NOT_SET (COMPRESS_SUBMISSION ON)
  112. ENDIF(EXISTS "${PROJECT_SOURCE_DIR}/DartConfig.cmake")
  113. SET_IF_NOT_SET (NIGHTLY_START_TIME "00:00:00 EDT")
  114. FIND_PROGRAM(CVSCOMMAND cvs )
  115. SET(CVS_UPDATE_OPTIONS "-d -A -P" CACHE STRING
  116. "Options passed to the cvs update command.")
  117. FIND_PROGRAM(SVNCOMMAND svn)
  118. FIND_PROGRAM(BZRCOMMAND bzr)
  119. FIND_PROGRAM(HGCOMMAND hg)
  120. FIND_PROGRAM(GITCOMMAND git)
  121. IF(NOT UPDATE_TYPE)
  122. IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CVS")
  123. SET(UPDATE_TYPE cvs)
  124. ELSEIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn")
  125. SET(UPDATE_TYPE svn)
  126. ELSEIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.bzr")
  127. SET(UPDATE_TYPE bzr)
  128. ELSEIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.hg")
  129. SET(UPDATE_TYPE hg)
  130. ELSEIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
  131. SET(UPDATE_TYPE git)
  132. ENDIF()
  133. ENDIF(NOT UPDATE_TYPE)
  134. STRING(TOLOWER "${UPDATE_TYPE}" _update_type)
  135. IF("${_update_type}" STREQUAL "cvs")
  136. SET(UPDATE_COMMAND "${CVSCOMMAND}")
  137. SET(UPDATE_OPTIONS "${CVS_UPDATE_OPTIONS}")
  138. ELSEIF("${_update_type}" STREQUAL "svn")
  139. SET(UPDATE_COMMAND "${SVNCOMMAND}")
  140. SET(UPDATE_OPTIONS "${SVN_UPDATE_OPTIONS}")
  141. ELSEIF("${_update_type}" STREQUAL "bzr")
  142. SET(UPDATE_COMMAND "${BZRCOMMAND}")
  143. SET(UPDATE_OPTIONS "${BZR_UPDATE_OPTIONS}")
  144. ELSEIF("${_update_type}" STREQUAL "hg")
  145. SET(UPDATE_COMMAND "${HGCOMMAND}")
  146. SET(UPDATE_OPTIONS "${HG_UPDATE_OPTIONS}")
  147. ELSEIF("${_update_type}" STREQUAL "git")
  148. SET(UPDATE_COMMAND "${GITCOMMAND}")
  149. SET(UPDATE_OPTIONS "${GIT_UPDATE_OPTIONS}")
  150. ENDIF()
  151. SET(DART_TESTING_TIMEOUT 1500 CACHE STRING
  152. "Maximum time allowed before CTest will kill the test.")
  153. SET(CTEST_SUBMIT_RETRY_DELAY 5 CACHE STRING
  154. "How long to wait between timed-out CTest submissions.")
  155. SET(CTEST_SUBMIT_RETRY_COUNT 3 CACHE STRING
  156. "How many times to retry timed-out CTest submissions.")
  157. FIND_PROGRAM(MEMORYCHECK_COMMAND
  158. NAMES purify valgrind boundscheck
  159. PATHS
  160. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Rational Software\\Purify\\Setup;InstallFolder]"
  161. DOC "Path to the memory checking command, used for memory error detection."
  162. )
  163. FIND_PROGRAM(SLURM_SBATCH_COMMAND sbatch DOC
  164. "Path to the SLURM sbatch executable"
  165. )
  166. FIND_PROGRAM(SLURM_SRUN_COMMAND srun DOC
  167. "Path to the SLURM srun executable"
  168. )
  169. SET(MEMORYCHECK_SUPPRESSIONS_FILE "" CACHE FILEPATH
  170. "File that contains suppressions for the memory checker")
  171. FIND_PROGRAM(SCPCOMMAND scp DOC
  172. "Path to scp command, used by CTest for submitting results to a Dart server"
  173. )
  174. FIND_PROGRAM(COVERAGE_COMMAND gcov DOC
  175. "Path to the coverage program that CTest uses for performing coverage inspection"
  176. )
  177. SET(COVERAGE_EXTRA_FLAGS "-l" CACHE STRING
  178. "Extra command line flags to pass to the coverage tool")
  179. # set the site name
  180. SITE_NAME(SITE)
  181. # set the build name
  182. IF(NOT BUILDNAME)
  183. SET(DART_COMPILER "${CMAKE_CXX_COMPILER}")
  184. IF(NOT DART_COMPILER)
  185. SET(DART_COMPILER "${CMAKE_C_COMPILER}")
  186. ENDIF(NOT DART_COMPILER)
  187. IF(NOT DART_COMPILER)
  188. SET(DART_COMPILER "unknown")
  189. ENDIF(NOT DART_COMPILER)
  190. IF(WIN32)
  191. SET(DART_NAME_COMPONENT "NAME_WE")
  192. ELSE(WIN32)
  193. SET(DART_NAME_COMPONENT "NAME")
  194. ENDIF(WIN32)
  195. IF(NOT BUILD_NAME_SYSTEM_NAME)
  196. SET(BUILD_NAME_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
  197. ENDIF(NOT BUILD_NAME_SYSTEM_NAME)
  198. IF(WIN32)
  199. SET(BUILD_NAME_SYSTEM_NAME "Win32")
  200. ENDIF(WIN32)
  201. IF(UNIX OR BORLAND)
  202. GET_FILENAME_COMPONENT(DART_CXX_NAME
  203. "${CMAKE_CXX_COMPILER}" ${DART_NAME_COMPONENT})
  204. ELSE(UNIX OR BORLAND)
  205. GET_FILENAME_COMPONENT(DART_CXX_NAME
  206. "${CMAKE_BUILD_TOOL}" ${DART_NAME_COMPONENT})
  207. ENDIF(UNIX OR BORLAND)
  208. IF(DART_CXX_NAME MATCHES "msdev")
  209. SET(DART_CXX_NAME "vs60")
  210. ENDIF(DART_CXX_NAME MATCHES "msdev")
  211. IF(DART_CXX_NAME MATCHES "devenv")
  212. GET_VS_VERSION_STRING("${CMAKE_GENERATOR}" DART_CXX_NAME)
  213. ENDIF(DART_CXX_NAME MATCHES "devenv")
  214. SET(BUILDNAME "${BUILD_NAME_SYSTEM_NAME}-${DART_CXX_NAME}")
  215. ENDIF(NOT BUILDNAME)
  216. # the build command
  217. BUILD_COMMAND(MAKECOMMAND_DEFAULT_VALUE
  218. CONFIGURATION "\${CTEST_CONFIGURATION_TYPE}")
  219. SET(MAKECOMMAND ${MAKECOMMAND_DEFAULT_VALUE}
  220. CACHE STRING "Command to build the project")
  221. # the default build configuration the ctest build handler will use
  222. # if there is no -C arg given to ctest:
  223. SET(DEFAULT_CTEST_CONFIGURATION_TYPE "$ENV{CMAKE_CONFIG_TYPE}")
  224. IF(DEFAULT_CTEST_CONFIGURATION_TYPE STREQUAL "")
  225. SET(DEFAULT_CTEST_CONFIGURATION_TYPE "Release")
  226. ENDIF(DEFAULT_CTEST_CONFIGURATION_TYPE STREQUAL "")
  227. IF(NOT "${CMAKE_GENERATOR}" MATCHES "Make")
  228. SET(CTEST_USE_LAUNCHERS 0)
  229. ENDIF(NOT "${CMAKE_GENERATOR}" MATCHES "Make")
  230. IF(CTEST_USE_LAUNCHERS)
  231. SET(CTEST_LAUNCH_COMPILE "\"${CMAKE_CTEST_COMMAND}\" --launch --target-name <TARGET_NAME> --build-dir <CMAKE_CURRENT_BINARY_DIR> --output <OBJECT> --source <SOURCE> --language <LANGUAGE> --")
  232. 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> --")
  233. SET(CTEST_LAUNCH_CUSTOM "\"${CMAKE_CTEST_COMMAND}\" --launch --target-name <TARGET_NAME> --build-dir <CMAKE_CURRENT_BINARY_DIR> --output <OUTPUT> --")
  234. SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CTEST_LAUNCH_COMPILE}")
  235. SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CTEST_LAUNCH_LINK}")
  236. SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_CUSTOM "${CTEST_LAUNCH_CUSTOM}")
  237. ENDIF(CTEST_USE_LAUNCHERS)
  238. MARK_AS_ADVANCED(
  239. BZRCOMMAND
  240. BZR_UPDATE_OPTIONS
  241. COVERAGE_COMMAND
  242. COVERAGE_EXTRA_FLAGS
  243. CTEST_SUBMIT_RETRY_DELAY
  244. CTEST_SUBMIT_RETRY_COUNT
  245. CVSCOMMAND
  246. CVS_UPDATE_OPTIONS
  247. DART_TESTING_TIMEOUT
  248. GITCOMMAND
  249. HGCOMMAND
  250. MAKECOMMAND
  251. MEMORYCHECK_COMMAND
  252. MEMORYCHECK_SUPPRESSIONS_FILE
  253. PURIFYCOMMAND
  254. SCPCOMMAND
  255. SLURM_SBATCH_COMMAND
  256. SLURM_SRUN_COMMAND
  257. SITE
  258. SVNCOMMAND
  259. SVN_UPDATE_OPTIONS
  260. )
  261. IF(NOT RUN_FROM_DART)
  262. SET(RUN_FROM_CTEST_OR_DART 1)
  263. INCLUDE(CTestTargets)
  264. SET(RUN_FROM_CTEST_OR_DART)
  265. ENDIF(NOT RUN_FROM_DART)
  266. ENDIF(BUILD_TESTING)