1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-09 17:46:29 +09:00
nixpkgs/doc/hooks/cmake.section.md
Sergei Zimmerman 00b1aef96b
ctestCheckHook: init
Motivation for this hook is simple: there's no single documented
way to do trivial things with ctest:

1. Pass additional flags to ctest invocation.
2. Selectively disable tests in a mechanism similar to python's
   `disabledTests` or rust's composable skips in `checkFlags`.
3. Disable parallel checking.

Current state of things has lead to several different solutions:

1. Completely overriding `checkPhase` [1] and invoking ctest manually
   with the necessary flags. This is most often coupled with `-E` for
   disabling test or setting parallel level.
2. Wrangling with weird double string/regex escaping and trying to stuff
   additional parameters and/or exclusion regex via `CMAKE_CTEST_ARGUMENTS`.
   This approach is especially painful when test names have spaces. This is
   the reason I originally decided to implement this hook after wrangling with
   failing darwin tests here [2].
3. Stuffing additional arguments into `checkFlagsArray` with the
   `ARGS` makefile parameter [3].

I don't see any reason to keep the status-quo. Doing something along these
lines has been suggested [4] for both `ctest` and `meson`. Meson setup-hook
has switched from `ninja` to `meson` in [5] with little friction. Doing
the same for cmake in a single sweep would prove problematic due to the
aforementioned zoo of workarounds and hacks for `ctest`. Doing it via
a separate hook would allow us to refactor things piecemeal and without
going through staging. The benefit of the hook is immediately clear and it
would allow to drive the refactor tractor at a comfortable pace.

[1]: pd/pdal/package.nix:117, cc/ccache/package.nix:108, gl/glog/package.nix:79
[2]: https://www.github.com/NixOS/nixpkgs/pull/375955
[3]: op/open62541/package.nix:114
[4]: https://www.github.com/NixOS/nixpkgs/issues/113829
[5]: https://www.github.com/NixOS/nixpkgs/pull/213845
2025-04-26 16:48:53 +00:00

2.3 KiB
Raw Blame History

cmake

Overrides the default configure phase to run the CMake command.

By default, we use the Make generator of CMake. But when Ninja is also available as a nativeBuildInput, this setup hook will detect that and use the ninja generator.

Dependencies are added automatically to CMAKE_PREFIX_PATH so that packages are correctly detected by CMake. Some additional flags are passed in to give similar behavior to configure-based packages.

By default, parallel building is enabled as CMake supports parallel building almost everywhere.

You can disable this hooks behavior by setting configurePhase to a custom value, or by setting dontUseCmakeConfigure.

Variables controlling CMake

CMake Exclusive Variables

cmakeFlags

Controls the flags passed to cmake setup during configure phase.

cmakeBuildDir

Directory where CMake will put intermediate files.

Setting this can be useful for debugging multiple CMake builds while in the same source directory, for example, when building for different platforms. Different values for each build will prevent build artefacts from interefering with each other. This setting has no tangible effect when running the build in a sandboxed derivation.

The default value is build.

dontUseCmakeConfigure

When set to true, don't use the predefined cmakeConfigurePhase.

Controlling CTest invocation

By default tests are run by make in checkPhase or by ninja if ninja is available in nativeBuildInputs. Makefile and Ninja generators produce the test target, which invokes ctest under the hood. This makes passing additional arguments to ctest difficult, so it's possible to invoke it directly in checkPhase by adding ctestCheckHook to nativeCheckInputs.

CTest Variables

disabledTests

Allows to disable running a list of tests. Note that regular expressions are not supported by disabledTests, but it can be combined with --exclude-regex option.

ctestFlags

Additional options passed to ctest together with checkFlags.