find_library: Require static libraries (.a) from toolchain file
I have a cross-compilation toolchain file where I would like to enforce static linking (even if a .so exist).
I tried adding
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a"), but this is overwritten by the
project() command, in https://gitlab.kitware.com/cmake/cmake/-/blob/v3.19.7/Modules/CMakeGenericSystem.cmake#L25
This causes problems later on when the project uses
find_package(ZLIB) because the linker flags contain "-static"
ld.lld: error: attempted static link of dynamic object /Users/alex/cheri/output/rootfs-riscv64-purecap/usr/lib/libz.so
The same directory contains a libz.a that I would like to use instead.
I can obviously add another
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") after the
project() command to work around this, but then I need to patch every project instead of being able to rely on the toolchain file.