forcing FIND_LIBRARY to find static libs on Unix (linux and macOS)

I am wondering if there is a cmake variable to force FIND_LIBRARY to use static libraries instead of shared ones. I know this might not be possible on Windows with MSVC where both the static libraries and the DLL stubs have a .lib extension, but it should be possible on Unix systems.

Does anyone know?

This comes up from time to time, and you’ve identified why there is currently no way to ask for static libraries to be preferred at the moment. On Windows, you can’t distinguish between a static library and an import library for a DLL based on the filename alone. Some kind of file parser that looked at the file contents to work out which type of library it is would be required. While you could potentially tell the difference from the file extension on other platforms (there are some that are weird - like AIX), a solution that doesn’t support Windows is unlikely to fly. The potential for confusion, frustration and misuse is just too high, in my opinion.

For Unix-like platforms, the workaround is to provide the file name of the static library in the NAMES argument. That can be used to tell find_library() to prefer libblah.a over other names. This at least has the advantage that the developer has to explicitly acknowledge that they are making an assumption about the platform.