CTest.cmake 9.3 KB

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