CTest.cmake 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 distributed 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. IF(NOT UPDATE_TYPE)
  120. IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CVS")
  121. SET(UPDATE_TYPE cvs)
  122. ELSE(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CVS")
  123. IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn")
  124. SET(UPDATE_TYPE svn)
  125. ELSE(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn")
  126. IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.bzr")
  127. SET(UPDATE_TYPE bzr)
  128. ELSE(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.bzr")
  129. IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.hg")
  130. SET(UPDATE_TYPE hg)
  131. ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.hg")
  132. ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.bzr")
  133. ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn")
  134. ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CVS")
  135. ENDIF(NOT UPDATE_TYPE)
  136. IF(NOT UPDATE_TYPE)
  137. IF(NOT __CTEST_UPDATE_TYPE_COMPLAINED)
  138. SET(__CTEST_UPDATE_TYPE_COMPLAINED 1 CACHE INTERNAL "Already complained about update type.")
  139. MESSAGE(STATUS "CTest cannot determine repository type. Please set UPDATE_TYPE to 'cvs' or 'svn'. CTest update will not work.")
  140. ENDIF(NOT __CTEST_UPDATE_TYPE_COMPLAINED)
  141. ENDIF(NOT UPDATE_TYPE)
  142. STRING(TOLOWER "${UPDATE_TYPE}" _update_type)
  143. IF("${_update_type}" STREQUAL "cvs")
  144. SET(UPDATE_COMMAND "${CVSCOMMAND}")
  145. SET(UPDATE_OPTIONS "${CVS_UPDATE_OPTIONS}")
  146. ELSE("${_update_type}" STREQUAL "cvs")
  147. IF("${_update_type}" STREQUAL "svn")
  148. SET(UPDATE_COMMAND "${SVNCOMMAND}")
  149. SET(UPDATE_OPTIONS "${SVN_UPDATE_OPTIONS}")
  150. ELSE("${_update_type}" STREQUAL "svn")
  151. IF("${_update_type}" STREQUAL "bzr")
  152. SET(UPDATE_COMMAND "${BZRCOMMAND}")
  153. SET(UPDATE_OPTIONS "${BZR_UPDATE_OPTIONS}")
  154. ELSE("${_update_type}" STREQUAL "bzr")
  155. IF("${_update_type}" STREQUAL "hg")
  156. SET(UPDATE_COMMAND "${HGCOMMAND}")
  157. SET(UPDATE_OPTIONS "${HG_UPDATE_OPTIONS}")
  158. ENDIF("${_update_type}" STREQUAL "hg")
  159. ENDIF("${_update_type}" STREQUAL "bzr")
  160. ENDIF("${_update_type}" STREQUAL "svn")
  161. ENDIF("${_update_type}" STREQUAL "cvs")
  162. SET(DART_TESTING_TIMEOUT 1500 CACHE STRING
  163. "Maximum time allowed before CTest will kill the test.")
  164. FIND_PROGRAM(MEMORYCHECK_COMMAND
  165. NAMES purify valgrind boundscheck
  166. PATHS
  167. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Rational Software\\Purify\\Setup;InstallFolder]"
  168. DOC "Path to the memory checking command, used for memory error detection."
  169. )
  170. FIND_PROGRAM(SLURM_SBATCH_COMMAND sbatch DOC
  171. "Path to the SLURM sbatch executable"
  172. )
  173. FIND_PROGRAM(SLURM_SRUN_COMMAND srun DOC
  174. "Path to the SLURM srun executable"
  175. )
  176. SET(MEMORYCHECK_SUPPRESSIONS_FILE "" CACHE FILEPATH
  177. "File that contains suppressions for the memory checker")
  178. FIND_PROGRAM(SCPCOMMAND scp DOC
  179. "Path to scp command, used by CTest for submitting results to a Dart server"
  180. )
  181. FIND_PROGRAM(COVERAGE_COMMAND gcov DOC
  182. "Path to the coverage program that CTest uses for performing coverage inspection"
  183. )
  184. # set the site name
  185. SITE_NAME(SITE)
  186. # set the build name
  187. IF(NOT BUILDNAME)
  188. SET(DART_COMPILER "${CMAKE_CXX_COMPILER}")
  189. IF(NOT DART_COMPILER)
  190. SET(DART_COMPILER "${CMAKE_C_COMPILER}")
  191. ENDIF(NOT DART_COMPILER)
  192. IF(NOT DART_COMPILER)
  193. SET(DART_COMPILER "unknown")
  194. ENDIF(NOT DART_COMPILER)
  195. IF(WIN32)
  196. SET(DART_NAME_COMPONENT "NAME_WE")
  197. ELSE(WIN32)
  198. SET(DART_NAME_COMPONENT "NAME")
  199. ENDIF(WIN32)
  200. IF(NOT BUILD_NAME_SYSTEM_NAME)
  201. SET(BUILD_NAME_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
  202. ENDIF(NOT BUILD_NAME_SYSTEM_NAME)
  203. IF(WIN32)
  204. SET(BUILD_NAME_SYSTEM_NAME "Win32")
  205. ENDIF(WIN32)
  206. IF(UNIX OR BORLAND)
  207. GET_FILENAME_COMPONENT(DART_CXX_NAME
  208. "${CMAKE_CXX_COMPILER}" ${DART_NAME_COMPONENT})
  209. ELSE(UNIX OR BORLAND)
  210. GET_FILENAME_COMPONENT(DART_CXX_NAME
  211. "${CMAKE_BUILD_TOOL}" ${DART_NAME_COMPONENT})
  212. ENDIF(UNIX OR BORLAND)
  213. IF(DART_CXX_NAME MATCHES "msdev")
  214. SET(DART_CXX_NAME "vs60")
  215. ENDIF(DART_CXX_NAME MATCHES "msdev")
  216. IF(DART_CXX_NAME MATCHES "devenv")
  217. GET_VS_VERSION_STRING("${CMAKE_GENERATOR}" DART_CXX_NAME)
  218. ENDIF(DART_CXX_NAME MATCHES "devenv")
  219. SET(BUILDNAME "${BUILD_NAME_SYSTEM_NAME}-${DART_CXX_NAME}")
  220. ENDIF(NOT BUILDNAME)
  221. # the build command
  222. BUILD_COMMAND(MAKECOMMAND CONFIGURATION "\${CTEST_CONFIGURATION_TYPE}")
  223. SET(MAKECOMMAND ${MAKECOMMAND} CACHE STRING "Command to build the project")
  224. # the default build configuration the ctest build handler will use
  225. # if there is no -C arg given to ctest:
  226. SET(DEFAULT_CTEST_CONFIGURATION_TYPE "$ENV{CMAKE_CONFIG_TYPE}")
  227. IF(DEFAULT_CTEST_CONFIGURATION_TYPE STREQUAL "")
  228. SET(DEFAULT_CTEST_CONFIGURATION_TYPE "Release")
  229. ENDIF(DEFAULT_CTEST_CONFIGURATION_TYPE STREQUAL "")
  230. IF(NOT "${CMAKE_GENERATOR}" MATCHES "Make")
  231. SET(CTEST_USE_LAUNCHERS 0)
  232. ENDIF(NOT "${CMAKE_GENERATOR}" MATCHES "Make")
  233. IF(CTEST_USE_LAUNCHERS)
  234. SET(CTEST_LAUNCH_COMPILE "\"${CMAKE_CTEST_COMMAND}\" --launch --target-name <TARGET_NAME> --build-dir <CMAKE_CURRENT_BINARY_DIR> --output <OBJECT> --source <SOURCE> --language <LANGUAGE> --")
  235. 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> --")
  236. SET(CTEST_LAUNCH_CUSTOM "\"${CMAKE_CTEST_COMMAND}\" --launch --target-name <TARGET_NAME> --build-dir <CMAKE_CURRENT_BINARY_DIR> --output <OUTPUT> --")
  237. SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CTEST_LAUNCH_COMPILE}")
  238. SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CTEST_LAUNCH_LINK}")
  239. SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_CUSTOM "${CTEST_LAUNCH_CUSTOM}")
  240. ENDIF(CTEST_USE_LAUNCHERS)
  241. MARK_AS_ADVANCED(
  242. COVERAGE_COMMAND
  243. CVSCOMMAND
  244. SVNCOMMAND
  245. BZRCOMMAND
  246. HGCOMMAND
  247. CVS_UPDATE_OPTIONS
  248. SVN_UPDATE_OPTIONS
  249. BZR_UPDATE_OPTIONS
  250. MAKECOMMAND
  251. MEMORYCHECK_COMMAND
  252. MEMORYCHECK_SUPPRESSIONS_FILE
  253. PURIFYCOMMAND
  254. SCPCOMMAND
  255. SLURM_SBATCH_COMMAND
  256. SLURM_SRUN_COMMAND
  257. SITE
  258. )
  259. # BUILDNAME
  260. IF(NOT RUN_FROM_DART)
  261. SET(RUN_FROM_CTEST_OR_DART 1)
  262. INCLUDE(CTestTargets)
  263. SET(RUN_FROM_CTEST_OR_DART)
  264. ENDIF(NOT RUN_FROM_DART)
  265. ENDIF(BUILD_TESTING)