Doxygen problems with find_package()

I am experiencing significant difficulties with the find_package() command. I find it to be rather unreliable, as there are instances where it fails to locate dependencies even under ideal conditions. Below is the code snippet I utilized for finding the Doxygen package:

find_package(Doxygen REQUIRED)

set(DOXYGEN_GENERATE_HTML YES)
set(DOXYGEN_HTML_OUTPUT "${CMAKE_BINARY_DIR}/doxygen")
set(DOXYGEN_GENERATE_TREEVIEW YES)

doxygen_add_docs(documentation "${PROJECT_SOURCE_DIR}" ALL COMMENT "Generating documentation")

This command worked perfectly fine on my previous machine, but now that I’ve migrated to a new installation, it completely broke. I also made sure to check whether the package is installed on my new machine, and I can confirm that it is.

Now, I am considering migrating from find_package() to FetchContent. I was wondering if it is at all possible to utilize FetchContent instead of find_package() to avoid the frustrations associated with this command.

The find_package() command works reliably, but you are responsible for preparing the environment so it can find what you ask it to look for. The command’s documentation lists in detail the paths it searches, and in what order. It is rather involved, which is a reflection of the number of different conventions across platforms, vendors, and practices that became common enough they needed to be supported. You need to ensure that the package you expect to be found is in fact locatable in one of those locations.

The situation you describe isn’t what I would consider appropriate motivation to switch to using FetchContent. Using FetchContent would probably find things more reliably, but that’s only because you have to give it an unambiguous location for where to fetch the dependency from. There are other advantages and disadvantages to FetchContent, and it does have integration with the find_package() command as well since CMake 3.24. I suggest you read the docs for both find_package() and FetchContent fully and carefully before making a decision to switch from one strategy to another. You may find yourself just trading one set of problems for another, but you may also find details that matter to your specific case that make one a clear winner over the other.

If you are still undecided after that, you will win more friends in the open source community if you use find_package() to find your dependencies. It puts more onus on the developer to prepare their environment, but it is also much better supported by package managers like Conan and vcpkg.