FirefoxMetzger
FirefoxMetzger

Reputation: 3260

What is the difference between PACKAGE_VERSION_COMPATIBLE and PACKAGE_VERSION_UNSUITABLE in CMake?

When loading packages using find_package(...) in cmake the version file has to declare 5 variables. Two of them are

according to the documentation they are used for

PACKAGE_VERSION_COMPATIBLE

True if version is compatible

PACKAGE_VERSION_UNSUITABLE

True if unsuitable as any version

Which leaves me puzzled. PACKAGE_VERSION_UNSUITABLE has been introduced in CMake 2.6.2 . However it seems mutually exclusive to PACKAGE_VERSION_COMPATIBLE. So why does it exist?

Can somebody enlighten me about the difference between being compatible and (un)suitable and maybe give an example, where both values are either true or false?

Upvotes: 5

Views: 267

Answers (1)

binarman
binarman

Reputation: 141

Probably too late, but for the sake of great justice: There are three variables checking version: PACKAGE_VERSION_EXACT, PACKAGE_VERSION_COMPATIBLE and PACKAGE_VERSION_UNSUITABLE.

You can find logic behind this variables here: https://github.com/Kitware/CMake/blob/0ae545ebad1b6b2a6c851205854b887d19c8da59/Source/cmFindPackageCommand.cxx#L1270

I'll try to reword. Note that I cut variable names for readability. Let's boil it down to four cases:

  • If UNSUITABLE set: discard package regardless other variables
  • If UNSUITABLE not set, EXACT not set, COMPATIBLE not set: package is good if find_package did not request version (it doesn't matter with or without EXACT)
  • If UNSUITABLE not set, EXACT not set, COMPATIBLE set: package is good if find_package did not require EXACT version
  • If UNSUITABLE not set, EXACT set: package is good

So, PACKAGE_VERSION_COMPATIBLE and PACKAGE_VERSION_UNSUITABLE are not exclusive:

  • PACKAGE_VERSION_UNSUITABLE discards package unconditionally
  • PACKAGE_VERSION_COMPATIBLE permits package only if EXACT not set and has no effect if find_package did not request version

Hope that helped =)

Upvotes: 3

Related Questions