How it works

Find-modules typically follow a specific pattern:

  1. Check whether the user provided a custom location for the desired package.
  2. Use commands from the find_ family to search for known required components of the required package, that is, header files, libraries, executables, and so forth. We have used find_path to find the full path to a header file and find_library to find a library. CMake also offers find_file, find_program, and find_package. These commands have the following general signature:
find_path(<VAR> NAMES name PATHS paths)
  1. Here, <VAR> will hold the result of the search, if successful, or <VAR>-NOTFOUND if unsuccessful. NAMES and PATHS are names for the file CMake should look for and paths where the search should be directed, respectively.
  2. From the results of this preliminary search, a version number is extracted. In our example, the ZeroMQ header file contains the library version, which can be extracted with string operations and regular expressions.
  3. Finally, the find_package_handle_standard_args command is invoked. This will handle the standard REQUIRED, QUIET, and version arguments to the find_package command, additionally setting the ZeroMQ_FOUND variable.
The full documentation for any CMake command can be obtained from the command line. For example,  cmake --help-command find_file will output the manual page for the find_file command. For the manual page of CMake standard modules, use the --help-module CLI switch. For example,  cmake --help-module FindPackageHandleStandardArgs will output to screen the manual page for the FindPackageHandleStandardArgs.cmake module.