Home > Blockchain >  Bypass `find_package` in CMake for specific targets?
Bypass `find_package` in CMake for specific targets?

Time:03-04

Is there a way to have a specific target that is still able to build even if find_package fails? For instance, I have a target that just compiles the code documentation and naturally has no hard requirements/dependencies, but cmake won't even finish configuration in case there is a missing dependency.

CodePudding user response:

Did you read this part of documentation:

find_package — CMake 3.23.0-rc2 Documentation

Regardless of the mode used, a <PackageName>_FOUND variable will be set to indicate whether the package was found. When the package is found, package-specific information may be provided through other variables and Imported Targets documented by the package itself. The QUIET option disables informational messages, including those indicating that the package cannot be found if it is not REQUIRED. The REQUIRED option stops processing with an error message if the package cannot be found.

A package-specific list of required components may be listed after the COMPONENTS keyword. If any of these components are not able to be satisfied, the package overall is considered to be not found. If the REQUIRED option is also present, this is treated as a fatal error, otherwise execution still continues. As a form of shorthand, if the REQUIRED option is present, the COMPONENTS keyword can be omitted and the required components can be listed directly after REQUIRED.

Additional optional components may be listed after OPTIONAL_COMPONENTS. If these cannot be satisfied, the package overall can still be considered found, as long as all required components are satisfied.

Note keywords: QUIET REQUIRED OPTIONAL_COMPONENTS

You can alter behavior of you cmake code by using <PackageName>_FOUND to handle failure.

  • Related