CTest.cmake 9.7 KB

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