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:
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
11 # # ... CMake code to create tests ...
13 # to creating tests when testing is enabled.
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).
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
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.)
48 #=============================================================================
49 # Copyright 2005-2009 Kitware, Inc.
51 # Distributed under the OSI-approved BSD License (the "License");
52 # see accompanying file Copyright.txt for details.
54 # This software is distributed WITHOUT ANY WARRANTY; without even the
55 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
56 # See the License for more information.
57 #=============================================================================
58 # (To distribute this file outside of CMake, substitute the full
59 # License text for the above reference.)
61 option(BUILD_TESTING "Build the testing tree." ON)
63 # function to turn generator name into a version string
64 # like vs7 vs71 vs8 vs9
65 function(GET_VS_VERSION_STRING generator var)
66 string(REGEX REPLACE "Visual Studio ([0-9][0-9]?)($|.*)" "\\1"
67 NUMBER "${generator}")
68 if("${generator}" MATCHES "Visual Studio 7 .NET 2003")
69 set(ver_string "vs71")
71 set(ver_string "vs${NUMBER}")
73 set(${var} ${ver_string} PARENT_SCOPE)
76 include(CTestUseLaunchers)
79 # Setup some auxilary macros
80 macro(SET_IF_NOT_SET var val)
81 if(NOT DEFINED "${var}")
82 set("${var}" "${val}")
86 macro(SET_IF_SET var val)
87 if(NOT "${val}" MATCHES "^$")
88 set("${var}" "${val}")
92 macro(SET_IF_SET_AND_NOT_SET var val)
93 if(NOT "${val}" MATCHES "^$")
94 SET_IF_NOT_SET("${var}" "${val}")
98 # Make sure testing is enabled
101 if(EXISTS "${PROJECT_SOURCE_DIR}/CTestConfig.cmake")
102 include("${PROJECT_SOURCE_DIR}/CTestConfig.cmake")
103 SET_IF_SET_AND_NOT_SET(NIGHTLY_START_TIME "${CTEST_NIGHTLY_START_TIME}")
104 SET_IF_SET_AND_NOT_SET(DROP_METHOD "${CTEST_DROP_METHOD}")
105 SET_IF_SET_AND_NOT_SET(DROP_SITE "${CTEST_DROP_SITE}")
106 SET_IF_SET_AND_NOT_SET(DROP_SITE_USER "${CTEST_DROP_SITE_USER}")
107 SET_IF_SET_AND_NOT_SET(DROP_SITE_PASSWORD "${CTEST_DROP_SITE_PASWORD}")
108 SET_IF_SET_AND_NOT_SET(DROP_SITE_MODE "${CTEST_DROP_SITE_MODE}")
109 SET_IF_SET_AND_NOT_SET(DROP_LOCATION "${CTEST_DROP_LOCATION}")
110 SET_IF_SET_AND_NOT_SET(TRIGGER_SITE "${CTEST_TRIGGER_SITE}")
111 SET_IF_SET_AND_NOT_SET(UPDATE_TYPE "${CTEST_UPDATE_TYPE}")
114 # the project can have a DartConfig.cmake file
115 if(EXISTS "${PROJECT_SOURCE_DIR}/DartConfig.cmake")
116 include("${PROJECT_SOURCE_DIR}/DartConfig.cmake")
118 # Dashboard is opened for submissions for a 24 hour period starting at
119 # the specified NIGHTLY_START_TIME. Time is specified in 24 hour format.
120 SET_IF_NOT_SET (NIGHTLY_START_TIME "00:00:00 EDT")
121 SET_IF_NOT_SET(DROP_METHOD "http")
122 SET_IF_NOT_SET (COMPRESS_SUBMISSION ON)
124 SET_IF_NOT_SET (NIGHTLY_START_TIME "00:00:00 EDT")
126 find_program(CVSCOMMAND cvs )
127 set(CVS_UPDATE_OPTIONS "-d -A -P" CACHE STRING
128 "Options passed to the cvs update command.")
129 find_program(SVNCOMMAND svn)
130 find_program(BZRCOMMAND bzr)
131 find_program(HGCOMMAND hg)
132 find_program(GITCOMMAND git)
135 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CVS")
137 elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn")
139 elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.bzr")
141 elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.hg")
143 elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
148 string(TOLOWER "${UPDATE_TYPE}" _update_type)
149 if("${_update_type}" STREQUAL "cvs")
150 set(UPDATE_COMMAND "${CVSCOMMAND}")
151 set(UPDATE_OPTIONS "${CVS_UPDATE_OPTIONS}")
152 elseif("${_update_type}" STREQUAL "svn")
153 set(UPDATE_COMMAND "${SVNCOMMAND}")
154 set(UPDATE_OPTIONS "${SVN_UPDATE_OPTIONS}")
155 elseif("${_update_type}" STREQUAL "bzr")
156 set(UPDATE_COMMAND "${BZRCOMMAND}")
157 set(UPDATE_OPTIONS "${BZR_UPDATE_OPTIONS}")
158 elseif("${_update_type}" STREQUAL "hg")
159 set(UPDATE_COMMAND "${HGCOMMAND}")
160 set(UPDATE_OPTIONS "${HG_UPDATE_OPTIONS}")
161 elseif("${_update_type}" STREQUAL "git")
162 set(UPDATE_COMMAND "${GITCOMMAND}")
163 set(UPDATE_OPTIONS "${GIT_UPDATE_OPTIONS}")
166 set(DART_TESTING_TIMEOUT 1500 CACHE STRING
167 "Maximum time allowed before CTest will kill the test.")
169 set(CTEST_SUBMIT_RETRY_DELAY 5 CACHE STRING
170 "How long to wait between timed-out CTest submissions.")
171 set(CTEST_SUBMIT_RETRY_COUNT 3 CACHE STRING
172 "How many times to retry timed-out CTest submissions.")
174 find_program(MEMORYCHECK_COMMAND
175 NAMES purify valgrind boundscheck
177 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Rational Software\\Purify\\Setup;InstallFolder]"
178 DOC "Path to the memory checking command, used for memory error detection."
180 find_program(SLURM_SBATCH_COMMAND sbatch DOC
181 "Path to the SLURM sbatch executable"
183 find_program(SLURM_SRUN_COMMAND srun DOC
184 "Path to the SLURM srun executable"
186 set(MEMORYCHECK_SUPPRESSIONS_FILE "" CACHE FILEPATH
187 "File that contains suppressions for the memory checker")
188 find_program(SCPCOMMAND scp DOC
189 "Path to scp command, used by CTest for submitting results to a Dart server"
191 find_program(COVERAGE_COMMAND gcov DOC
192 "Path to the coverage program that CTest uses for performing coverage inspection"
194 set(COVERAGE_EXTRA_FLAGS "-l" CACHE STRING
195 "Extra command line flags to pass to the coverage tool")
201 set(DART_COMPILER "${CMAKE_CXX_COMPILER}")
202 if(NOT DART_COMPILER)
203 set(DART_COMPILER "${CMAKE_C_COMPILER}")
205 if(NOT DART_COMPILER)
206 set(DART_COMPILER "unknown")
209 set(DART_NAME_COMPONENT "NAME_WE")
211 set(DART_NAME_COMPONENT "NAME")
213 if(NOT BUILD_NAME_SYSTEM_NAME)
214 set(BUILD_NAME_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
217 set(BUILD_NAME_SYSTEM_NAME "Win32")
220 get_filename_component(DART_CXX_NAME
221 "${CMAKE_CXX_COMPILER}" ${DART_NAME_COMPONENT})
223 get_filename_component(DART_CXX_NAME
224 "${CMAKE_BUILD_TOOL}" ${DART_NAME_COMPONENT})
226 if(DART_CXX_NAME MATCHES "msdev")
227 set(DART_CXX_NAME "vs60")
229 if(DART_CXX_NAME MATCHES "devenv")
230 GET_VS_VERSION_STRING("${CMAKE_GENERATOR}" DART_CXX_NAME)
232 set(BUILDNAME "${BUILD_NAME_SYSTEM_NAME}-${DART_CXX_NAME}")
236 build_command(MAKECOMMAND_DEFAULT_VALUE
237 CONFIGURATION "\${CTEST_CONFIGURATION_TYPE}")
238 set(MAKECOMMAND ${MAKECOMMAND_DEFAULT_VALUE}
239 CACHE STRING "Command to build the project")
241 # the default build configuration the ctest build handler will use
242 # if there is no -C arg given to ctest:
243 set(DEFAULT_CTEST_CONFIGURATION_TYPE "$ENV{CMAKE_CONFIG_TYPE}")
244 if(DEFAULT_CTEST_CONFIGURATION_TYPE STREQUAL "")
245 set(DEFAULT_CTEST_CONFIGURATION_TYPE "Release")
253 CTEST_SUBMIT_RETRY_DELAY
254 CTEST_SUBMIT_RETRY_COUNT
262 MEMORYCHECK_SUPPRESSIONS_FILE
271 if(NOT RUN_FROM_DART)
272 set(RUN_FROM_CTEST_OR_DART 1)
273 include(CTestTargets)
274 set(RUN_FROM_CTEST_OR_DART)