FairFindPackage2

Added in version 0.1.0.

Requires CMake 3.12 or later.


On inclusion

Added in version 0.2.0.

Add this module as a PRIVATE package dependency if included from the FairCMakeModules package.


find_package2()

Wrapper around CMake’s native find_package() command to add some features and bookkeeping.

find_package2(PRIVATE|PUBLIC|INTERFACE|BUNDLED <pkgname>
              [VERSION <version>]
              [COMPONENTS <component> [<component>...]]
              [OPTIONAL_COMPONENTS <component> [<component>...]]
              [ADD_REQUIREMENTS_OF <dep_pkgname> [<dep_pkgname>...]]
              [<any other native `find_package` option>...])

The qualifier (PRIVATE|PUBLIC|INTERFACE|BUNDLED) is used to populate the variables PROJECT_[INTERFACE]_<pkgname>_([VERSION]|[COMPONENTS]|PACKAGE_DEPENDENCIES) accordingly. This bookkeeping information is used to print a dependencies found summary table and in the generation of a CMake package. BUNDLED decays to PUBLIC if the variable <pkgname>_BUNDLED is false and to PRIVATE otherwise.

When a dependending package is listed with ADD_REQUIREMENTS_OF the variables <dep_pkgname>_<pkgname>_VERSION|COMPONENTS are looked up and merged with VERSION (selected highest version) and COMPONENTS (deduplicated) requirements. COMPONENTS and VERSION args are then just passed to find_package().

Changed in version 0.2.0.

The ADD_REQUIREMENTS_OF argument is now a no-op and only remains for compatibility reasons. find_package2() now always merges all known requirements.

Added in version 1.0.0.

By default find_package2() tries to determine the install prefix if the package is found. The result is populated to the variable <pkgname>_PREFIX`. This behaviour can be disabled by setting the FAIR_NO_AUTO_DETECT_PREFIX to ON.

Support for OPTIONAL_COMPONENTS was added.


find_package2_implicit_dependencies()

Added in version 0.2.0.

Loop over all remaining implicit dependencies and find_package2() them.

find_package2_implicit_dependencies([EXCLUDE <pkg> [<pkg>...]])

Listed packages with EXCLUDE are filtered out.


fair_generate_package_dependencies()

Added in version 0.2.0.

fair_generate_package_dependencies()

Populates the variable PACKAGE_DEPENDENCIES with a CMake snippet from the public dependencies (read from PROJECT_INTERFACE_PACKAGE_DEPENDENCIES) that can be included in a CMake package config file to export its package dependencies.

These exported dependencies will be respected by find_package2().