The find_file(), find_path(), find_library(), find_program() and find_package() commands will save the result of a successful search in a cache variable. The docs for the find_library() command explain it this way:
A cache entry named by
<VAR>is created to store the result of this command. If the library is found the result is stored in the variable and the search will not be repeated unless the variable is cleared. If nothing is found, the result will be<VAR>-NOTFOUND, and the search will be attempted again the next time find_library is invoked with the same variable.
Regarding how to better understand what’s going on for find_jar(), perhaps you can satisfy your own questions by looking at the way it is implemented. It’s actually not all that complex, consisting mostly just of a series of if-else conditions before calling find_file(). You can see the relevant logic here:
https://gitlab.kitware.com/cmake/cmake/-/blob/v3.17.2/Modules/UseJava.cmake#L829-919
With find_library I see sometime it requires to add prefix lib to the library name in NAMES argument
The main case I’m aware of where you may want to explicitly include lib in the library name with find_library() is if you want to force it to prefer finding a static library. This can be done in a platform-dependent way on unix-based systems by listing the full filename of the library, like libsomething.a, but this won’t work on Windows (static and shared libraries use the same something.lib file name, so you can’t tell them apart). It may not work on other less common systems too (e.g. I think AIX uses .a even for shared libraries, at least in some cases). Ordinarily, apart from this particular scenario, you’d let CMake add a lib prefix by itself, which is probably what you are seeing it doing in the debug output.