Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between PACKAGE_VERSION_COMPATIBLE and PACKAGE_VERSION_UNSUITABLE in CMake?

Tags:

cmake

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

  • PACKAGE_VERSION_COMPATIBLE
  • PACKAGE_VERSION_UNSUITABLE

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?

like image 738
FirefoxMetzger Avatar asked Oct 29 '22 21:10

FirefoxMetzger


1 Answers

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 =)

like image 57
binarman Avatar answered Jan 02 '23 19:01

binarman