-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmake: Controlling Abseil's tests with BUILD_TESTING is inconvenient #1056
Comments
Abseil's own tests now are disabled if either BUILD_TESTING or a new option called ABSL_BUILD_TESTING is false. Additionally, Abseil's CMakeLists.txt no longer re-declares the BUILD_TESTING option with a value of false. Abseil had been using just the BUILD_TESTING option, since the fix for abseil#901. Because setting BUILD_TESTING false still works to disable Abseil's tests, this change preserves the behavior asked for in that issue. Previous to that, Abseil had a project specific flag for this, as is the typical idiom used in other projects. The issue BUILD_TESTING is that it is an all-or-nothing policy. When Abseil is incorporated as a subproject, the encompasing project has no convenient way to enable its own tests while disabling Abseil's. Fixes abseil#1056
Abseil's own tests now are disabled if either BUILD_TESTING or a new option called ABSL_BUILD_TESTING is false. Additionally, Abseil's CMakeLists.txt no longer re-declares the BUILD_TESTING option with a value of false. Abseil had been using just the BUILD_TESTING option, since the fix for abseil#901. Because setting BUILD_TESTING false still works to disable Abseil's tests, this change preserves the behavior asked for in that issue. Previous to that, Abseil had a project specific flag for this, as is the typical idiom used in other projects. The issue with BUILD_TESTING is that it is an all-or-nothing policy. When Abseil is incorporated as a subproject, the encompasing project has no convenient way to enable its own tests while disabling Abseil's. Fixes abseil#1056
I'm curious to learn if there is something I'm missing on the technical level here. From https://discourse.cmake.org/t/how-to-use-fetchcontent-correctly-for-building-external-dependencies/3686, Craig Scott, one of the cmake maintainers, says:
|
There was a doc written that says "Prefer using standard CMake flags" but doesn't give any rationale. If I recall correctly, when asked, the author of the doc said that not using It seems like we have examples of projects using a project specific flag, so it can't be that surprising. Unless I hear otherwise, I'm inclined to accept #1057. |
I can see the appeal of using BUILD_TESTING directly when Abseil is built as a top level project. Derek, I'm asking about this at https://discourse.cmake.org/t/fetchcontent-vs-build-testing/4477 so you might wait for a resolution there before accepting my PR. |
Hi Matt, Did anything change your mind on this one? An example of using project structure (as suggested in one of the comments in your cmake.org question) can be found here: I think I'm still inclined to accept your PR though. |
Hi Derek, thanks for following up. I still think this PR is an improvement and could be merged as-is, but I think the PR could be better, and I'll explain why below. As I've switched back to bazel, and am not doing anything serious with Abseil anyway, I'm not personally motivated to work on this any longer. One reason I think this PR is an improvement as-is because I think not providing a project specific variable to turn tests on or off is inconvenient. Unlike bazel, there is no consistently applied convention for running tests in "your" project vs those of your dependencies. Where bazel forces a path prefix based convention, CMake projects aren't always set up well to conveniently build a subset of tests. The way to do it often relies on certain naming conventions for test targets, which I found were not consistent across projects, and nothing concrete about this is suggested in CMake documentation. So providing a way to easily configure tests on/off for individual project dependencies might be convenient. Imagine having 10 dependent projects and you normally want to run tests for none of them. But you suspect a bug in Abseil. If all 10 used The example you gave from the the https://github.com/google/or-tools project requires a particular project structure. It requires having a subdirectory for all dependencies and in the
Then to use it you must call
I see This is consistent with what I found looking at this problem. The only ways to have a scope in CMake are functions and separate This, of course, has the drawback of forcing that kind of directory structure on the user. One can no longer conveniently have a simple project that uses a single In #1056 (comment) above I quoted some advice from an active CMake maintainer:
A member on the CMake form suggested GLFW as an example of this best practice (https://discourse.cmake.org/t/fetchcontent-vs-build-testing/4477/5). In GLFW it is done like this:
So You could get fancier and default So, this approach seen in GLFW seems to be best practice. This PR moves things in that direction but doesn't quite get there. |
Abseil's own tests now are disabled if either BUILD_TESTING or a new option called ABSL_BUILD_TESTING is false. Additionally, Abseil's CMakeLists.txt no longer re-declares the BUILD_TESTING option with a value of false. Abseil had been using just the BUILD_TESTING option, since the fix for #901. Because setting BUILD_TESTING false still works to disable Abseil's tests, this change preserves the behavior asked for in that issue. Previous to that, Abseil had a project specific flag for this, as is the typical idiom used in other projects. The issue with BUILD_TESTING is that it is an all-or-nothing policy. When Abseil is incorporated as a subproject, the encompasing project has no convenient way to enable its own tests while disabling Abseil's. Fixes #1056
Describe the bug
Abseil arranges for its own tests to be built and run whenever BUILD_TESTING is set, and then Abseil turns it off by default. This has been the case since the fix for #901.
If an enclosing project enables testing and then incorporates Abseil as a subproject, Abseil's tests will be built and configured to run. There is no convenient way for an enclosing project to both turn on testing but also disable Abseil's tests.
Steps to reproduce the bug
CMakeLists.txt
of my project:Expected: my project's tests are run
Actual: both my project's tests and Abseil's tests are run
What version of Abseil are you using?
https://youtu.be/tISy7EJQPzI
What operating system and version are you using
n/a
What compiler and version are you using?
n/a
What build system are you using?
cmake version 3.21.4
Additional context
Other projects (grpc, googletest, etc.) expose an option named like `${PROJECT_NAME}_BUILD_TESTING that allows the project's tests to be turned on. They typically default off. That's what I'd suggest here.
The text was updated successfully, but these errors were encountered: