Skip to content

find_package ignores required exact package version

In my build of Ceph, where I added find_package(snappy 1.2.1 EXACT REQUIRED), the output is:

-- Found snappy: /nix/store/zpq19iaf3myr4p8m1vjb7yqq2lmk36a1-snappy-1.2.2/lib/libsnappy.so (Required is exact version "1.2.1")

I happily proceeds using the wrong version, despite pointing out Required is exact version ....

I can really write any version there, and it still proceeds.

This doesn't really make sense. CMake should print either why it ignored this exact-version request it correctly noticed, or which version it detected.

Apparently this is a problem already since 2018:

So I decided to file this as an issue now.


Details:

The pkg-config .pc file from which it (I believe) determined the version looks like this:

cat /nix/store/jpgs0qiwbj0p1kp2x7y355rbb88h77pf-snappy-1.2.2-dev/lib/pkgconfig/snappy.pc
  Name: snappy
  Description: Fast compressor/decompressor library.
  Version: 1.2.2
  Libs: -L/nix/store/zpq19iaf3myr4p8m1vjb7yqq2lmk36a1-snappy-1.2.2/lib -lsnappy
  Cflags: -I/nix/store/jpgs0qiwbj0p1kp2x7y355rbb88h77pf-snappy-1.2.2-dev/include

So that Version field looks reasonable.

The Findsnappy.cmake is here, just in case something is wrong with its contents: https://github.com/ceph/ceph/blob/v19.2.2/cmake/modules/Findsnappy.cmake

Using CMake 3.31.7 on linux-x86_64.

Thanks!

Edited by Niklas Hambüchen
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information