Skip to content

Proper support for static vs dynamic dependencies in find_package and (Find|configure)-scripts

When building a project, one sometime needs to declare dependencies on a shared/dynamically-loaded variant of some library, sometimes on its static variant, and sometimes - on both.

However:

  • find_package() does not accept a parameter saying which of the variants is necessary.
  • AFAICT, a single target doesn't have both a "static aspect" and a "dynamic aspect"; nor is there a default naming scheme for static vs dynamic target names (e.g.libfoo::libfoo_static vs libfoo::libfoo_dynamic or libfoo::static::libfoo vs libfoo::dynamic::libfoo or bikeshed this to your heart's content).
  • CMake-generation package configure scripts do not, by default, explicitly report/expose the staticness/dynamicness of the deployed package.

At the moment, some Find-scripts have a kind of jerry-rigged support for this, via pairs of targets, use of CMake options to control the Find-script behavior, etc. Otherwise, users can change CMAKE_FIND_LIBRARY_SUFFIXES - albeit in a platform-specific way - and have CMake only look for static variable files.

I request that:

  1. find_package() support a staticness/dynamicness parameter similarly to the version requirement: Find any variant, find a static variant, find a dynamic variant, find both a dynamic and a static variant. This will be supported both in module mode and in configure mode.
  2. Each find module / find script and each generated configure script be made able to handle the staticness requirement (with a minimal kind of handling being failing immediately saying "I don't know how to handle staticness".)

Bikeshedding:

  1. The exact parameter for find_package() could be DYANMIC=<value> with <value> being one of ANY, STATIC, SHARED, BOTH and aliases SHARED, YES, NO. Another possibility could be using SHARED or STATIC as the parameter name. A non-name-value option could be just any one or both of the keyword STATIC SHARED, and when none is specified - the search is for either static or shared.
  2. Up to you whether to expose different targets or a single target which has a static and dynamic aspect to it. The latter option would agree more with the second, related bug I'm about to open.

Related StackOverflow questions:

Edited by Eyal Rozenberg
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information