I am trying to use pkg_check_modules to locate the sndfile library module on Linux. The library has an entry in the pkg-config database and the log shows that the sndfile module has been found.
Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
Checking for module 'sndfile'
Found sndfile, version 1.0.31
However the sndfile_FOUND property is not set. The cache does contain some sndfile related entries.
From what I know about pkg-config and CMake, in the case of absent CMake configs, one should be able to find the package with pkg_check_modules(), which is what you did (although with a bit different syntax, as it seems?). So I am not sure why sndfile_FOUND ends up not being set, especially that all the other variables seem to be set.
Moreover, you should get an error if pkg_check_modules() doesn’t find the package, as you’ve provided REQUIRED argument, but you don’t get an error, do you?
Are there any other *_FOUND variables set after your project configuration is done? Maybe it sets some other variable for some reason? And also if you are not using the latest CMake version, I would try the latest one, just for the sake of experiment.
I have go to the original libsndfile source and do something with CMake build files
That would be my recommendation, but that’s because I’m used to CMake configs and I have never used pkg-config. So yes, if those CMake configs aren’t provided in the package that you get, then the only(?) way to get them would be for you to build that package yourself from sources (and probably patch its project to add a proper installation procedure, which would create those configs). Or you can probably just write your own Findsndfile.cmakemodule. Here’s actually one example, which seemingly uses pkg_check_modules() underneath (with some strange _pc_SNDFILE variable?).
However, again, like I said, my understanding is that pkg_check_modules() should be able to do the job of discovering the package, so you should be able to rely on that one instead of CMake configs. Just need to find out why it is failing in this particular case.
The package name passed to find_package_handle_standard_args (Sndfile)
does not match the name of the calling package (sndfile).
This can lead to
problems in calling code that expects find_package result variables
(e.g., _FOUND) to follow a certain pattern.
Call Stack (most recent call first):
/usr/share/cmake-3.25/Modules/Findsndfile.cmake:33
(FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:5 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
Configuring done
The following variable are set in CMakeCache.txt, same as before.
I linked that file just as an example of how you could make your own module. I didn’t really expect that particular one to actually work
But the warning you got might be still useful, so perhaps you could try different variants of the package name casing with your original project file too.
Anyway, so there are no *_FOUND variables set after the project is configured? Perhaps you can try to check them explicitly, like so: