It’s surprising that the content name is “googletest” instead of “GTest”. The latter would transparently make it work with FETCHCONTENT_TRY_FIND_PACKAGE_MODE.
Further complicating matters, the version of GoogleTest referenced (1.10.0) has a bug that breaks using “GTest” as the content name. It’s since been fixed.
A lot of people will copy/paste documentation and use it in their projects and it is unfortunate that doing so in this case may inadvertently break expectations of FETCHCONTENT_TRY_FIND_PACKAGE_MODE for GTest. We ran into this in the Beman project and it sucked a lot of developer time.
I see three options for moving forward:
Do nothing. People will continue to run into this problem.
Bump the googletest version used in the example. This is low risk and people won’t hit the issue we did when they try to change the content name to GTest. People still may be surprised when FETCHCONTENT_TRY_FIND_PACKAGE_MODE doesn’t work out of the box.
Change all the examples (aside from the one illustrating FIND_PACKAGE_ARGS NAMES) to use GTest as the content name. Newer code will work with FETCHCONTENT_TRY_FIND_PACKAGE_MODE. The drawback is that there may be an issue when people mix old copy/pasted code with new copy/pasted code and end up with both GTest and googletest as content names.
The official name of that project is in fact googletest, not gtest (the top level CMakeLists.txt in the GitHub project actually uses project(googletest-distribution), and the GitHub repo name is also googletest). It is unfortunate that CMake’s own previous Find module used FindGTest rather than Findgoogletest as its name. The googletest project is also inconsistent with what name it uses for itself, using googletest, gtest, and GTest in different places. There’s also the complication of googlemock/gmock, which is also contained in the same repository.
Change all the examples (aside from the one illustrating FIND_PACKAGE_ARGS NAMES) to use GTest as the content name.
I’d be willing to consider a merge request that made this change. As you hinted at, it would be important to also update the whole “Integrating With find_package()” example, not just the one code block mentioning FIND_PACKAGE_ARGS. One of the goals of that section is to highlight how to handle dependencies that have more than one commonly used name. There are also a couple of similar example code blocks in the Using Dependencies Guide in the Downloading And Building From Source With FetchContent and FetchContent And find_package() Integration sections that should be updated for consistency.
You’d also need to check that after making such changes, there’s still some examples showing use of FIND_PACKAGE_ARGS with some non-empty args after that keyword. The googletest example is so far providing that precisely because of the historical naming mess. You are proposing to clean that up, so you’d have to find some other example that demonstrates that capability and update places where that’s needed.
The naming problem is historical. gtest, and gmock were two separate projects (where gmock depended on gtest), but Google decided to make googletest out of those two. CMake find module’s name is older than this merge.