1

When we initially configure using CMake, we get some messages about some of our find_package() instructions, e.g.:

-- Found CUDAToolkit: /usr/local/cuda/include (found suitable version "12.0.140", minimum required is "10.1") 

or:

-- Found Python: /usr/bin/python3.11 (found version "3.11.2") found components: Interpreter 

but for other packages we find_package() - nothing is printed by default.

Other than printing such a message myself - is there a way I can tell CMake to print some message along those lines for every package it finds?

Note: In this related question, the command-line option -D CMAKE_FIND_DEBUG_MODE=ON is mentioned; but that prints a ton of debug information which I don't want.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • I don't know about any functionality that would provide this info. You probably could narrow down the output down to a smaller size by running it through `grep` or similar... – fabian May 23 '23 at 18:05
  • @fabian: Do you personally not know, or do you know CMake well enough to say this authoritatively? – einpoklum May 23 '23 at 18:14
  • I'd say I know cmake rather well, but new stuff gets added every few months and sometimes I discover new stuff that has been added a few minor versions ago... However at least for the documentation of the command line parameters there doesn't seem any occurance of `find` that indicates a possibility and searching for `info` in the `find_package` docs doesn't result in anything promising either. Also no luck with searching though the documented cmake variables including `FIND`in the variable name...Of course you could look at the implementation of the command, but I don't have the time for this – fabian May 23 '23 at 18:24
  • would it solve your problem to just grep from the cache file for package-related variables? – starball May 23 '23 at 19:38
  • @user: No, it would not. Obviously the information printed to the console is reflected in the cache and other generated files, that's not what I'm asking for. – einpoklum May 23 '23 at 19:50

2 Answers2

0

tl;dr: As of CMake 3.26 - not without a custom Find script.

The packages you gave as examples have custom Find scripts, e.g. FindCUDAToolkit.cmake, as part of the CMake distribution, which implement this behavior. If you write such a script for your own package, it could do this; but - chicken and egg problem: You need your package before you can use a find script, or at least someone to independently download and use your Find script.

For now, and trusting @fabian's comment and the CMake documentation not saying anything about this, I have filed issue 24936 against CMake to add this functionality.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • If a package is found via **Config** script, then CMake always prints a line about found package and print the directory which contains that config script. If a package is found via **Find** script, then such script usually uses helper [find_package_handle_standard_args](https://cmake.org/cmake/help/latest/module/FindPackageHandleStandardArgs.html#command:find_package_handle_standard_args) which determines whether the package is found and prints appropriate message. If some (old) Find script doesn't use that helper, then you could fill a bugreport for that script. – Tsyvarev May 23 '23 at 21:20
  • In your issue you ask CMake to output "location (a-la-CUDAToolkit)". This is impossible because CMake itself doesn't know what a specific package treats as location: only Find script and its authors know what directory is treated as a location of the package. Similarly, the version of the found package is known only for a Find script, not for CMake itself. – Tsyvarev May 23 '23 at 21:35
  • @Tsyvarev: 1. The most important case is that of packages without specific find scripts. 2. CMake could treat a variable with a certain name template as the location, and if the package sets it - that's the location. 3. CMake controls the find scripts it distributes... – einpoklum May 23 '23 at 21:40
  • "The most important case is that of packages without specific find scripts." - I don't understand that. `find_package` works either via Config script or via Find script, there is no other ways. "CMake controls the find scripts it distributes..." - So you may fill a bugreport to CMake that its **particular** Find script doesn't use `find_package_handle_standard_args`. – Tsyvarev May 23 '23 at 21:51
  • 1
    "If a package is found via Config script, then CMake always prints a line about found package and print the directory which contains that config script" - I don't think so. Not in my experience anyway. – einpoklum May 23 '23 at 21:53
-1

You can use the message command to print what is found, here is an example:

find_package(Boost 1.78)
if (Boost_FOUND)
  message("Found Boost!" "  Version:" ${Boost_VERSION})
elseif (NOT Boost_FOUND)
  message("Not found Boost!")
endif ()

For more about message command, please refer to CMake Docunmetation.

Tom
  • 177
  • 7