check_symbol_exists incompatible with using FetchContent to build dependencies from source
Recently, CMake has introduced the FetchContent
module that allows dependencies to be built as part of the overall build, and to override find_package
calls if the OVERRIDE_FIND_PACKAGE
option is specified to FetchContent_Declare
.
This is very useful for creating projects that automatically pull in all of their dependencies.
For example, a project that depends on libtiff may wish to use FetchContent
calls to pull in both libtiff and zstd.
However, cmake/ZSTDCodec.cmake
relies on check_symbol_exists
to decide of zstd is sufficiently recent, which requires that zstd is already built at configure time, and is therefore incompatible with using FetchContent
(where the zstd will be provided as a regular CMake target that is not available at configure time).
A possible solution would be to rely on version information rather than check_symbol_exists
. The version check will be much faster than check_symbol_exists
as well, since that requires invoking the compiler.