Skip to content

cmake,rpm,deb: disable WITH_CATCH2 when building packages - #69379

Closed
tchaikov wants to merge 2 commits into
ceph:mainfrom
tchaikov:wip-cmake-catch2
Closed

tchaikov wants to merge 2 commits into
ceph:mainfrom
tchaikov:wip-cmake-catch2

Conversation

@tchaikov

@tchaikov tchaikov commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

in this changeset:

  1. disable WITH_CATCH2 explicitly when building packages
  2. replace CPM in favor for builtin FetchContent

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@tchaikov
tchaikov requested a review from a team as a code owner June 10, 2026 06:06
tchaikov added 2 commits June 10, 2026 14:07
neither debian nor rpm prepares libcatch2-dev or catch2-devel
respectively. so after 66a775a ("cmake/AddCephTest: use namespaced
Catch2 imported targets"), we fail to generate the build system, because
the Catch2 library is not found, as FETCHCONTENT_FULLY_DISCONNECTED is
set when configuring CMake. this setting prevents FetchContent from
fetching the library from github, and we don't check whether
FetchContent_MakeAvailable() populates the library or not, so even if it
fails, it leaves us with undefined Catch2 CMake targets without any
warning.

before 66a775a, we were linking against Catch2 with the library's
name, as target_link_libraries() considers it a plain library name if no
target with the same name is defined. so this "works" when building
debian/rpm packages, as we don't build tests, hence we don't hit link
failures. and in CI the build has internet access, hence
FetchContent_MakeAvailable() works.

so, to make it more correct, disable WITH_CATCH2 explicitly when building
packages.

Signed-off-by: Kefu Chai <[email protected]>
CPM is only used for pulling in Catch2, and it is just a wrapper around
FetchContent. so let's use FetchContent directly: find_package() when
WITH_SYSTEM_CATCH2 is set, otherwise fetch v3.8.1 and add it.

if Catch2 cannot be made available, for instance with
FETCHCONTENT_FULLY_DISCONNECTED=ON and no populated source,
FetchContent_MakeAvailable() leaves the target undefined instead of
failing. CMP0170 would make it fail by itself, but that policy is only
available since CMake 3.30 while our minimum is 3.22, so we check the
target ourselves and bail out with a fatal error rather than silently
skipping the tests.

the previous CPM block also had a bug: in CMake the arguments to a
command are separated with space, not comma. so `set(VAR, ${x})` is
parsed as setting a variable named "VAR," (with the trailing comma) and
leaves "VAR" unset. since we remove the whole block, this bug is gone too.

also drop cmake/modules/CPM.cmake since nothing uses it anymore.

Signed-off-by: Kefu Chai <[email protected]>
@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@tchaikov

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@cbodley
cbodley requested a review from chardan June 10, 2026 12:30
Comment thread CMakeLists.txt
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.8.1
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(Catch2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a git submodule?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@batrick it's not in the scope of this change. in this changeset, i want to respect user's configuration instead of ignoring it with a warning message. and make sure we do it in a correct and explicit way. if we want to always enable Catch2 with a git submodule, we should do it in a different pull request. IMHO, we should not, as we are not migrating to Catch2 as the testing framework. as i believe we should only use a single C++ unit test framework in this project. anyway, this discussion is out of scope of this pull request.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tchaikov I admit I haven't tried out CATCH2 yet, but there seems to be genuine upstream interest in exploring it, I'd like to not block that process

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CPM is a wrapper for FetchContent. It avoids a lot of the complication (and time sink) of using git submodules, making the task of adding external tooling much more straightforward. You can think of it as essentially a sort of package manager for cmake.

https://github.com/cpm-cmake/cpm.cmake

@chardan

chardan commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

We've had both CPM and Catch2 support for some time now, and I think there's generally been a positive reception. Perhaps it's best to focus on fixing any bugs or issues?

  1. CPM vs. FetchContent or using a git submodule is that CPM is much easier to deal with than git submodules and is a more flexible improvement to FetchContent;
  2. Catch2 is widely used and has a lot of improvements vis-a-vis gtest. Making it easier to write tests means that more people write tests. I added support for Catch2 in PR 62873 (which you and I had some discussion in the comments on) and some tooling to make it easier to integrate with Ceph's tests in PR 63529.

@adamemerson

Copy link
Copy Markdown
Contributor

I actually think Catch2 is perfectly reasonable to have and use. I'd prefer keeping it enabled and switching to submodules if the CPM is breaking things.

@chardan

chardan commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

I mean, CPM has been running since May 2025 (I added it along with Catch2); we even addressed local vs. remote and all that, there's prior case and patches for it. I don't think these are new issues, other than that probably a bug (likely in one of my own scripts) was exposed by @sunyuechi in 69165. I don't think we need to toss either, they're both very useful and are even being used (and a number of open PRs use both).

@chardan chardan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As both CPM and Catch2 have been deployed over a year and have PRs in active use of them, I suggest that we not disable or remove them but instead fix related bugs and get them to work harmoniously in ceph.

@tchaikov

tchaikov commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor Author

i think the title may be the source of the confusion here: this PR doesn't remove or disable Catch2 in general. the "disable WITH_CATCH2" applies only to deb/rpm package builds, and the two commit messages spell out the why. let me summarize what each does:

  1. (a7eeff1) switch the Catch2 fetch from CPM to builtin FetchContent. i know CPM is handy as a cmake-level package manager; the reasoning here is narrower: Catch2 is its only consumer in our tree today, so the builtin command does the same job without carrying the ~1300-line CPM.cmake we copied verbatim and don't maintain. if we later want CPM for more dependencies, bringing it back is easy.
  2. (cada24a) set WITH_CATCH2=OFF in the deb/rpm package builds only. those builds produce the distributable packages and don't run the unit tests (in debian/rules, dh_auto_test is a no-op), so they never needed Catch2; before this they fetched it at configure time for nothing, and after 66a775a it broke them.

to be clear, this does not touch the unit-test path. make check still runs with WITH_CATCH2=ON in the ubuntu:jammy container (and now the optional ubuntu:noble one), and since Catch2 isn't a system dep, not in debian/control, it keeps fetching Catch2 from the internet and building and running the Catch2 tests exactly as before. no coverage changes.

on behavior in the package builds: this preserves it. the warn-and-silently-disable path was only ever reached there, since that's the only place FETCHCONTENT_FULLY_DISCONNECTED is set; those now set WITH_CATCH2=OFF directly, with the same outcome. the fatal error just keeps that old silent-disable, which is what hid the issue @sunyuechi ran into in #69165, from quietly coming back.

so nothing here walks back Catch2 or blocks exploring it, and credit to @chardan for adding it in the first place. if it helps the discussion, i'm happy to split this into the packaging fix (which addresses the el9 build break) and the CPM/FetchContent cleanup, so each can be weighed on its own.

@chardan

chardan commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Hi @tchaikov, thanks for your thoughtful and thorough explanation-- the motivation and purpose are both greatly clarified, I appreciate it! I think your suggestion to split the PR makes the most sense, although to be honest I have multiple pending PRs and projects which use CPM and it would be redundant effort to remove it only to reintroduce it in short order. I wasn't clear on the side effect of 66a775a, I now see the trouble; your patch would address it in the way you describe, and I'm ok with it. Would an alternative also be to disable fetching Catch2 if tests aren't enabled? Thanks again for the clarification!

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions Bot added the stale label Aug 11, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

@github-actions github-actions Bot closed this Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants