Provide an option to prefer config packages to module packages
At the moment find_package
if none of MODULE
, NO_MODULE
, or CONFIG
flags are provided, will try to find a module package, and then a config package.
Module packages are more or less guess packages which will try to find out headers, and libraries in the file system, and create CMake targets based on that information.
Config packages are the proper CMake packages, which contain the CMake targets directly.
Given then example:
find_package(FreeType)
.
On Linux it will use the module package FindFreeType, which will have an imported target with the shared object, which will link to a ZLIB and PNG shared objects.
On Windows with vcpkg and hunter, the same module package will be used, and it will have a static library as imported target. Then the application using find_package will give linking errors because of ZLIB and PNG unresolved references.
The FreeType config module provided by vcpkg and hunter contains the reference to the ZLIB and PNG static library targets, and it works as expected.
Unfortunately one cannot simply use find_package(FreeType)
to satisfy both cases.
For the Qt WIP/CMake branch we ended up having something like:
# Probe to see if a config package exists
find_package(FreeType CONFIG QUIET)
if (NOT FreeType_FOUND)
# Now search the module package
find_package(FreeType MODULE)
endif()
The config packages should take precedence, since they also support the NAMES
parameter, which can help in cases like conan which doesn't want to name ZLIB package all uppercase, but have it lowercase as zlib.