CTest.cmake 9.9 KB

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