You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[CMake and CTest tips for AliceO2](#cmake-and-ctest-tips-for-aliceo2)
6
+
-[CMake](#cmake)
7
+
-[Instructions for contributors (aka developers' documentation)](#instructions-for-contributors-aka-developers-documentation)
8
+
-[Typical CMakeLists.txt](#typical-cmakeliststxt)
9
+
-[Examples](#examples)
10
+
-[Ex1 Adding a basic library](#ex1-adding-a-basic-library)
11
+
-[Ex2 Adding a basic library with a Root dictionary](#ex2-adding-a-basic-library-with-a-root-dictionary)
12
+
-[Ex3 Adding an executable](#ex3-adding-an-executable)
13
+
-[Ex4 Adding a couple of tests](#ex4-adding-a-couple-of-tests)
14
+
-[Ex5 Adding a man page](#ex5-adding-a-man-page)
15
+
-[CTest](#ctest)
16
+
-[Selecting/excluding by test name (-R/-E)](#selectingexcluding-by-test-name--r-e)
17
+
-[Selecting/excluding by label (-L/-LE)](#selectingexcluding-by-label--l-le)
18
+
-[Speeding up ctest execution](#speeding-up-ctest-execution)
19
+
20
+
<!-- vim-markdown-toc -->
21
+
22
+
# CMake and CTest tips for AliceO2
23
+
24
+
## CMake
4
25
5
26
> Note that this document describe the [new CMake system](CMakeMigration.md) : the one based on buckets has been discontinued.
6
27
7
-
## Instructions for contributors (aka developers' documentation)
28
+
###Instructions for contributors (aka developers' documentation)
8
29
9
30
A sub-module `CMakeLists.txt` defines one or more _targets_.
10
31
A target generally corresponds to an actual build artifact like a (static or shared) library or an executable. Targets are the cornerstone of any modern cmake build system.
11
32
12
-
## Typical CMakeLists.txt
33
+
###Typical CMakeLists.txt
13
34
14
35
A typical module's `CMakeLists.txt` contains
15
36
16
-
-a call to [o2_add_library](../cmake/O2AddLibrary.cmake) to define a library (and its dependencies)
17
-
-call(s) to [o2_add_executable](../cmake/O2AddExecutable.cmake) to define one or more executables (and their dependencies)
18
-
-call(s) to [o2_add_test](../cmake/O2AddTest.cmake) to define one or more tests (and their dependencies)
37
+
- a call to [o2_add_library](../cmake/O2AddLibrary.cmake) to define a library (and its dependencies)
38
+
- call(s) to [o2_add_executable](../cmake/O2AddExecutable.cmake) to define one or more executables (and their dependencies)
39
+
- call(s) to [o2_add_test](../cmake/O2AddTest.cmake) to define one or more tests (and their dependencies)
19
40
20
41
Optionally it might contain a call to [o2_target_root_dictionary](../cmake/O2TargetRootDictionary.cmake) if the module's library requires a Root dictionary.
21
42
@@ -25,11 +46,11 @@ Note that despite the parameter name, the `PUBLIC_LINK_LIBRARIES` should refer t
25
46
26
47
Note also CMakeLists.txt should be considered as code and so the same care you put into writing code (e.g. do not repeat yourself, comments, etc...) should be applied to CMakeLists.txt. Also, like the rest of our code, we can take of the formatting using the [cmake-format](https://github.com/cheshirekow/cmake_format) tool (that tool is certainly not as robust as `clang-format` but it can get most of the job done easily).
27
48
28
-
## Examples
49
+
###Examples
29
50
30
51
The example outputs below are from a Mac, so the shared library extension is `dylib`. On Linux it would be `so`.
31
52
32
-
### [Ex1](../Examples/Ex1) Adding a basic library
53
+
####[Ex1](../Examples/Ex1) Adding a basic library
33
54
34
55
Using the following source dir :
35
56
@@ -80,7 +101,7 @@ And upon install `cmake --build . -- install` (the lonely `--` is not a typo) th
80
101
├── lib
81
102
│ ├── libO2Ex1.dylib
82
103
83
-
### [Ex2](../Examples/Ex2) Adding a basic library with a Root dictionary
104
+
####[Ex2](../Examples/Ex2) Adding a basic library with a Root dictionary
84
105
85
106
Using a slightly modified version of the previous example (the [A.h](../Examples/Ex2/include/Ex2/A.h) now uses ClassDef for instance), we'll now add a Root dictionary :
86
107
@@ -138,7 +159,7 @@ The include installation will be similar to Ex1 : the `LinkDef.h` file is _not_
138
159
│ ├── libO2Ex2.dylib
139
160
│ ├── libO2Ex2.rootmap
140
161
141
-
### [Ex3](../Examples/Ex3) Adding an executable
162
+
####[Ex3](../Examples/Ex3) Adding an executable
142
163
143
164
Adding an executable to previous example :
144
165
@@ -201,7 +222,7 @@ Third, the created executable can be launched "as is" from the build tree, witho
201
222
202
223
That is because the [RPATH](https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling) was correctly set by CMake for the build tree. It should be set correctly also when installing.
203
224
204
-
### [Ex4](../Examples/Ex4) Adding a couple of tests
225
+
####[Ex4](../Examples/Ex4) Adding a couple of tests
205
226
206
227
Let's add two basic test2 to our previous example.
207
228
@@ -232,7 +253,7 @@ Those two test executables will be under `stage/bin` with a name starting with `
232
253
├── libO2Ex3.dylib
233
254
└── libO2Ex4.dylib
234
255
235
-
By default tests are not be installed, unless the `INSTALL` option is given to `o2_add_test`. So in the installation zone only the first test will be available, under the `tests` subdirectory. So the full installation of our 4 examples would give :
256
+
By default tests are _not_ installed, unless the `INSTALL` option is given to `o2_add_test`. So in the installation zone only the first test will be available, under the `tests` subdirectory. So the full installation of our 4 examples would give :
236
257
237
258
../install-Debug/
238
259
├── bin
@@ -311,7 +332,7 @@ Tests can also be _excluded_ based on label (`-LE`) or name (`-RE`).
311
332
dummy = 0.07 sec*proc (1 test)
312
333
fast = 0.07 sec*proc (1 test)
313
334
314
-
### [Ex5](../Examples/Ex5) Adding a man page
335
+
####[Ex5](../Examples/Ex5) Adding a man page
315
336
316
337
If a module provides one or more executables, it might be of interest for the users of those executables to have access to a man page for them. Ex5 illustates that use case.
317
338
@@ -328,3 +349,111 @@ The [man page](ManPages.md) is created using :
328
349
o2_target_man_page([targetName] NAME ex5 SECTION 7)
329
350
330
351
where `NAME xx` refers to a file `doc/xx.[SECTION].in`, and the actual `targetName` can be found from the base target name (ex5 in that case) using the [o2_name_target](../cmake/O2NameTarget.cmake) function.
352
+
353
+
## CTest
354
+
355
+
In the build directory of O2, if you launch the `ctest` command, all the O2 tests will be ran, which is not always what you want/need, in particular during development.
356
+
357
+
As shown above in [Ex4](#ex4-adding-a-couple-of-tests), there are fortunately various ways to narrow the set of tests which are ran by `ctest`.
358
+
359
+
Note that in all the commands below, the `-N` option is used to show the list of test that would be selected, without running them. Remove that option to actually run the tests.
360
+
361
+
### Selecting/excluding by test name (-R/-E)
362
+
363
+
Probably the simplest is to select the test name, using the `-R` (regexp) option :
364
+
365
+
```shell
366
+
> ctest -N -R test/Contour
367
+
Test #269: Detectors/MUON/MCH/Contour/test/Contour.cxx
368
+
Test #270: Detectors/MUON/MCH/Contour/test/ContourCreator.cxx
369
+
370
+
> ctest -N -R "test/Contour\.(.)"
371
+
Test #269: Detectors/MUON/MCH/Contour/test/Contour.cxx
372
+
373
+
```
374
+
375
+
Instead of selecting the tests to run, you can invert the logic and exclude tests matching a regular expression using `-E` instead of `-R`.
376
+
377
+
### Selecting/excluding by label (-L/-LE)
378
+
379
+
Assuming the tests have been labelled, you can use `-L` (to include) or `-LE` (to exclude) tests based on their labels. The full list of defined labels can be shown using the `--print-labels` option.
380
+
381
+
```shell
382
+
> ctest -N -L mch
383
+
Test #268: Detectors/MUON/MCH/Contour/test/BBox.cxx
384
+
Test #269: Detectors/MUON/MCH/Contour/test/Contour.cxx
385
+
Test #270: Detectors/MUON/MCH/Contour/test/ContourCreator.cxx
386
+
Test #271: Detectors/MUON/MCH/Contour/test/Edge.cxx
387
+
Test #272: Detectors/MUON/MCH/Contour/test/Interval.cxx
388
+
Test #273: Detectors/MUON/MCH/Contour/test/Polygon.cxx
389
+
Test #274: Detectors/MUON/MCH/Contour/test/SegmentTree.cxx
390
+
Test #275: Detectors/MUON/MCH/Contour/test/Vertex.cxx
391
+
Test #276: Detectors/MUON/MCH/Simulation/macros/drawMCHGeometry.C
392
+
Test #277: Detectors/MUON/MCH/Simulation/macros/drawMCHGeometry.C_compiled
393
+
```
394
+
395
+
### Speeding up ctest execution
396
+
397
+
Finally, note that `ctest` can run tests in parallel (unless those that are explicitely marked as not safe to run in parallel) using the `-j n` option, where `n` is the max number of tests to run in parallel.
0 commit comments