static and shared builds of the same library
When trying to build an all-static (Windows) application, i’m currently (mis)using setting
BUILD_SHARED_LIBS=FALSE to be able to implicitly (via
UNKNOWN) or explicitly try to influence which flavor of a library, that has both static as well as shared flavors available, is used.
This got more complicated recently (#19804 (comment 688121)), requiring:
if(NOT BUILD_SHARED_LIBS) # try to force search for static libraries if BUILD_SHARED_LIBS was disabled list(PREPEND CMAKE_FIND_LIBRARY_SUFFIXES .a .lib) # prefer static (*.a) over import (*.dll.a) libraries endif()
This is all just a hacky workaround for the fact that i can’t tell
CMake globally) conceptually that i want to link to static versions of libraries, and even if individual packages provide mechanisms for selecting that, that there is no consensus on how to do that.
I plan on contributing generated
CMake package configs to at least 2 additional projects now, and it pains me that i have to »design« mechanisms for the above.
And it is intended that for every different flavor (also debug/release) the build needs to be redone?
I would prefer if the it was as easy as defining 1 global (or target specific) variable to either build both flavors or handle generating differently named export sets and include them automatically in the generated package config. Or at least provide all the necessary boilerplate in the docs.