cmake/Modules/CTest.cmake

268 lines
9.0 KiB
CMake
Raw Normal View History

2016-10-30 18:24:19 +01:00
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
2015-08-17 11:37:30 +02:00
#[=======================================================================[.rst:
CTest
-----
Configure a project for testing with CTest/CDash
Include this module in the top CMakeLists.txt file of a project to
enable testing with CTest and dashboard submissions to CDash::
project(MyProject)
...
include(CTest)
The module automatically creates a ``BUILD_TESTING`` option that selects
whether to enable testing support (``ON`` by default). After including
the module, use code like::
if(BUILD_TESTING)
# ... CMake code to create tests ...
endif()
to creating tests when testing is enabled.
To enable submissions to a CDash server, create a ``CTestConfig.cmake``
file at the top of the project with content such as::
set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
2019-11-11 23:01:05 +01:00
set(CTEST_SUBMIT_URL "http://my.cdash.org/submit.php?project=MyProject")
2015-08-17 11:37:30 +02:00
(the CDash server can provide the file to a project administrator who
configures ``MyProject``). Settings in the config file are shared by
both this ``CTest`` module and the :manual:`ctest(1)` command-line
2022-11-16 20:14:03 +01:00
:ref:`Dashboard Client` mode (:option:`ctest -S`).
2015-08-17 11:37:30 +02:00
While building a project for submission to CDash, CTest scans the
build output for errors and warnings and reports them with surrounding
context from the build log. This generic approach works for all build
tools, but does not give details about the command invocation that
produced a given problem. One may get more detailed reports by setting
the :variable:`CTEST_USE_LAUNCHERS` variable::
set(CTEST_USE_LAUNCHERS 1)
in the ``CTestConfig.cmake`` file.
#]=======================================================================]
2013-03-16 19:13:01 +02:00
option(BUILD_TESTING "Build the testing tree." ON)
# function to turn generator name into a version string
2018-08-09 18:06:22 +02:00
# like vs9 or vs10
2013-03-16 19:13:01 +02:00
function(GET_VS_VERSION_STRING generator var)
string(REGEX REPLACE "Visual Studio ([0-9][0-9]?)($|.*)" "\\1"
2011-06-19 15:41:06 +03:00
NUMBER "${generator}")
2013-03-16 19:13:01 +02:00
set(ver_string "vs${NUMBER}")
set(${var} ${ver_string} PARENT_SCOPE)
endfunction()
2013-03-16 19:13:01 +02:00
include(CTestUseLaunchers)
if(BUILD_TESTING)
2018-04-23 21:13:27 +02:00
# Setup some auxiliary macros
2013-03-16 19:13:01 +02:00
macro(SET_IF_NOT_SET var val)
if(NOT DEFINED "${var}")
set("${var}" "${val}")
endif()
endmacro()
2013-03-16 19:13:01 +02:00
macro(SET_IF_SET var val)
2013-11-03 12:27:13 +02:00
if(NOT "${val}" STREQUAL "")
2013-03-16 19:13:01 +02:00
set("${var}" "${val}")
endif()
endmacro()
2013-03-16 19:13:01 +02:00
macro(SET_IF_SET_AND_NOT_SET var val)
2013-11-03 12:27:13 +02:00
if(NOT "${val}" STREQUAL "")
SET_IF_NOT_SET("${var}" "${val}")
2013-03-16 19:13:01 +02:00
endif()
endmacro()
# Make sure testing is enabled
2013-03-16 19:13:01 +02:00
enable_testing()
2013-03-16 19:13:01 +02:00
if(EXISTS "${PROJECT_SOURCE_DIR}/CTestConfig.cmake")
include("${PROJECT_SOURCE_DIR}/CTestConfig.cmake")
SET_IF_SET_AND_NOT_SET(NIGHTLY_START_TIME "${CTEST_NIGHTLY_START_TIME}")
2019-11-11 23:01:05 +01:00
SET_IF_SET_AND_NOT_SET(SUBMIT_URL "${CTEST_SUBMIT_URL}")
SET_IF_SET_AND_NOT_SET(DROP_METHOD "${CTEST_DROP_METHOD}")
SET_IF_SET_AND_NOT_SET(DROP_SITE "${CTEST_DROP_SITE}")
SET_IF_SET_AND_NOT_SET(DROP_SITE_USER "${CTEST_DROP_SITE_USER}")
SET_IF_SET_AND_NOT_SET(DROP_SITE_PASSWORD "${CTEST_DROP_SITE_PASWORD}")
SET_IF_SET_AND_NOT_SET(DROP_SITE_MODE "${CTEST_DROP_SITE_MODE}")
SET_IF_SET_AND_NOT_SET(DROP_LOCATION "${CTEST_DROP_LOCATION}")
SET_IF_SET_AND_NOT_SET(TRIGGER_SITE "${CTEST_TRIGGER_SITE}")
SET_IF_SET_AND_NOT_SET(UPDATE_TYPE "${CTEST_UPDATE_TYPE}")
2013-03-16 19:13:01 +02:00
endif()
# the project can have a DartConfig.cmake file
2013-03-16 19:13:01 +02:00
if(EXISTS "${PROJECT_SOURCE_DIR}/DartConfig.cmake")
include("${PROJECT_SOURCE_DIR}/DartConfig.cmake")
else()
# Dashboard is opened for submissions for a 24 hour period starting at
# the specified NIGHTLY_START_TIME. Time is specified in 24 hour format.
SET_IF_NOT_SET (NIGHTLY_START_TIME "00:00:00 EDT")
SET_IF_NOT_SET(DROP_METHOD "http")
SET_IF_NOT_SET (COMPRESS_SUBMISSION ON)
2013-03-16 19:13:01 +02:00
endif()
SET_IF_NOT_SET (NIGHTLY_START_TIME "00:00:00 EDT")
2019-11-11 23:01:05 +01:00
if(NOT SUBMIT_URL)
set(SUBMIT_URL "${DROP_METHOD}://")
if(DROP_SITE_USER)
string(APPEND SUBMIT_URL "${DROP_SITE_USER}")
if(DROP_SITE_PASSWORD)
string(APPEND SUBMIT_URL ":${DROP_SITE_PASSWORD}")
endif()
string(APPEND SUBMIT_URL "@")
endif()
string(APPEND SUBMIT_URL "${DROP_SITE}${DROP_LOCATION}")
endif()
2013-03-16 19:13:01 +02:00
if(NOT UPDATE_TYPE)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CVS")
set(UPDATE_TYPE cvs)
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn")
set(UPDATE_TYPE svn)
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.bzr")
set(UPDATE_TYPE bzr)
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.hg")
set(UPDATE_TYPE hg)
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
set(UPDATE_TYPE git)
endif()
endif()
2013-03-16 19:13:01 +02:00
string(TOLOWER "${UPDATE_TYPE}" _update_type)
if("${_update_type}" STREQUAL "cvs")
2021-09-14 00:13:48 +02:00
find_program(CVSCOMMAND cvs )
set(CVS_UPDATE_OPTIONS "-d -A -P" CACHE STRING
"Options passed to the cvs update command.")
2013-03-16 19:13:01 +02:00
set(UPDATE_COMMAND "${CVSCOMMAND}")
set(UPDATE_OPTIONS "${CVS_UPDATE_OPTIONS}")
elseif("${_update_type}" STREQUAL "svn")
2021-09-14 00:13:48 +02:00
find_program(SVNCOMMAND svn)
2013-03-16 19:13:01 +02:00
set(UPDATE_COMMAND "${SVNCOMMAND}")
set(UPDATE_OPTIONS "${SVN_UPDATE_OPTIONS}")
elseif("${_update_type}" STREQUAL "bzr")
2021-09-14 00:13:48 +02:00
find_program(BZRCOMMAND bzr)
2013-03-16 19:13:01 +02:00
set(UPDATE_COMMAND "${BZRCOMMAND}")
set(UPDATE_OPTIONS "${BZR_UPDATE_OPTIONS}")
elseif("${_update_type}" STREQUAL "hg")
2021-09-14 00:13:48 +02:00
find_program(HGCOMMAND hg)
2013-03-16 19:13:01 +02:00
set(UPDATE_COMMAND "${HGCOMMAND}")
set(UPDATE_OPTIONS "${HG_UPDATE_OPTIONS}")
elseif("${_update_type}" STREQUAL "git")
2021-09-14 00:13:48 +02:00
find_program(GITCOMMAND git)
2013-03-16 19:13:01 +02:00
set(UPDATE_COMMAND "${GITCOMMAND}")
set(UPDATE_OPTIONS "${GIT_UPDATE_OPTIONS}")
2014-08-03 19:52:23 +02:00
elseif("${_update_type}" STREQUAL "p4")
2021-09-14 00:13:48 +02:00
find_program(P4COMMAND p4)
2014-08-03 19:52:23 +02:00
set(UPDATE_COMMAND "${P4COMMAND}")
set(UPDATE_OPTIONS "${P4_UPDATE_OPTIONS}")
2013-03-16 19:13:01 +02:00
endif()
2013-03-16 19:13:01 +02:00
set(DART_TESTING_TIMEOUT 1500 CACHE STRING
"Maximum time allowed before CTest will kill the test.")
2013-03-16 19:13:01 +02:00
set(CTEST_SUBMIT_RETRY_DELAY 5 CACHE STRING
2010-11-13 01:00:53 +02:00
"How long to wait between timed-out CTest submissions.")
2013-03-16 19:13:01 +02:00
set(CTEST_SUBMIT_RETRY_COUNT 3 CACHE STRING
2010-11-13 01:00:53 +02:00
"How many times to retry timed-out CTest submissions.")
2013-03-16 19:13:01 +02:00
find_program(MEMORYCHECK_COMMAND
2021-09-14 00:13:48 +02:00
NAMES purify valgrind boundscheck drmemory cuda-memcheck compute-sanitizer
PATHS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Rational Software\\Purify\\Setup;InstallFolder]"
DOC "Path to the memory checking command, used for memory error detection."
)
2013-03-16 19:13:01 +02:00
set(MEMORYCHECK_SUPPRESSIONS_FILE "" CACHE FILEPATH
"File that contains suppressions for the memory checker")
2013-03-16 19:13:01 +02:00
find_program(COVERAGE_COMMAND gcov DOC
"Path to the coverage program that CTest uses for performing coverage inspection"
)
2013-03-16 19:13:01 +02:00
set(COVERAGE_EXTRA_FLAGS "-l" CACHE STRING
2012-02-18 12:40:36 +02:00
"Extra command line flags to pass to the coverage tool")
# set the site name
2021-09-14 00:13:48 +02:00
if(COMMAND cmake_host_system_information)
cmake_host_system_information(RESULT _ctest_hostname QUERY HOSTNAME)
set(SITE "${_ctest_hostname}" CACHE STRING "Name of the computer/site where compile is being run")
unset(_ctest_hostname)
else()
# This code path is needed for CMake itself during bootstrap.
site_name(SITE)
endif()
# set the build name
2013-03-16 19:13:01 +02:00
if(NOT BUILDNAME)
set(DART_COMPILER "${CMAKE_CXX_COMPILER}")
if(NOT DART_COMPILER)
set(DART_COMPILER "${CMAKE_C_COMPILER}")
endif()
if(NOT DART_COMPILER)
set(DART_COMPILER "unknown")
endif()
if(WIN32)
set(DART_NAME_COMPONENT "NAME_WE")
else()
set(DART_NAME_COMPONENT "NAME")
endif()
if(NOT BUILD_NAME_SYSTEM_NAME)
set(BUILD_NAME_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
endif()
if(WIN32)
set(BUILD_NAME_SYSTEM_NAME "Win32")
endif()
if(UNIX OR BORLAND)
2016-10-30 18:24:19 +01:00
get_filename_component(DART_COMPILER_NAME
"${DART_COMPILER}" ${DART_NAME_COMPONENT})
2013-03-16 19:13:01 +02:00
else()
2016-10-30 18:24:19 +01:00
get_filename_component(DART_COMPILER_NAME
2014-08-03 19:52:23 +02:00
"${CMAKE_MAKE_PROGRAM}" ${DART_NAME_COMPONENT})
2013-03-16 19:13:01 +02:00
endif()
2016-10-30 18:24:19 +01:00
if(DART_COMPILER_NAME MATCHES "devenv")
GET_VS_VERSION_STRING("${CMAKE_GENERATOR}" DART_COMPILER_NAME)
2013-03-16 19:13:01 +02:00
endif()
2016-10-30 18:24:19 +01:00
set(BUILDNAME "${BUILD_NAME_SYSTEM_NAME}-${DART_COMPILER_NAME}")
2013-03-16 19:13:01 +02:00
endif()
2010-03-17 14:00:29 +02:00
# the build command
2013-03-16 19:13:01 +02:00
build_command(MAKECOMMAND_DEFAULT_VALUE
2010-11-13 01:00:53 +02:00
CONFIGURATION "\${CTEST_CONFIGURATION_TYPE}")
2013-03-16 19:13:01 +02:00
set(MAKECOMMAND ${MAKECOMMAND_DEFAULT_VALUE}
2010-11-13 01:00:53 +02:00
CACHE STRING "Command to build the project")
2010-03-17 14:00:29 +02:00
# the default build configuration the ctest build handler will use
# if there is no -C arg given to ctest:
2013-03-16 19:13:01 +02:00
set(DEFAULT_CTEST_CONFIGURATION_TYPE "$ENV{CMAKE_CONFIG_TYPE}")
if(DEFAULT_CTEST_CONFIGURATION_TYPE STREQUAL "")
set(DEFAULT_CTEST_CONFIGURATION_TYPE "Release")
endif()
2009-10-04 10:30:41 +03:00
2013-03-16 19:13:01 +02:00
mark_as_advanced(
2011-06-19 15:41:06 +03:00
BZRCOMMAND
COVERAGE_COMMAND
2012-02-18 12:40:36 +02:00
COVERAGE_EXTRA_FLAGS
2011-06-19 15:41:06 +03:00
CTEST_SUBMIT_RETRY_DELAY
CTEST_SUBMIT_RETRY_COUNT
CVSCOMMAND
CVS_UPDATE_OPTIONS
2011-06-19 15:41:06 +03:00
DART_TESTING_TIMEOUT
GITCOMMAND
2014-08-03 19:52:23 +02:00
P4COMMAND
2011-06-19 15:41:06 +03:00
HGCOMMAND
2013-03-16 19:13:01 +02:00
MAKECOMMAND
MEMORYCHECK_COMMAND
MEMORYCHECK_SUPPRESSIONS_FILE
2010-11-13 01:00:53 +02:00
SITE
2011-06-19 15:41:06 +03:00
SVNCOMMAND
)
2013-03-16 19:13:01 +02:00
if(NOT RUN_FROM_DART)
set(RUN_FROM_CTEST_OR_DART 1)
include(CTestTargets)
set(RUN_FROM_CTEST_OR_DART)
endif()
endif()