File: enable_testing.rst

package info (click to toggle)
cmake 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 158,704 kB
  • sloc: ansic: 406,077; cpp: 309,512; sh: 4,233; python: 3,696; yacc: 3,109; lex: 1,279; f90: 538; asm: 471; lisp: 375; java: 310; cs: 270; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 110; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22; sed: 2
file content (51 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
enable_testing
--------------

Enables testing for the current directory and below:

.. code-block:: cmake

  enable_testing()

This command should be invoked in the top-level source directory because
:manual:`ctest(1)` expects to find a test file in the top-level
build directory.

This command is also automatically invoked when the :module:`CTest`
module is included, except if the :variable:`BUILD_TESTING`
option is turned off.

The following restrictions apply to where ``enable_testing()`` may be called:

* It must be called in file scope, not in a :command:`function` call nor inside
  a :command:`block`.

Examples
^^^^^^^^

In the following example, this command is conditionally called depending on how
the project is used.  For instance, when the Example project is added via the
:module:`FetchContent` module as a subdirectory of a parent project that defines
its own tests, testing for the Example project is disabled.

.. code-block:: cmake
  :caption: ``CMakeLists.txt``

  project(Example)

  option(Example_ENABLE_TESTING "Enable testing" ${PROJECT_IS_TOP_LEVEL})

  if(Example_ENABLE_TESTING)
    enable_testing()
  endif()

  # ...

  if(Example_ENABLE_TESTING)
    add_test(...)
  endif()

See Also
^^^^^^^^

* The :command:`add_test` command.