[CMake] Shared, static and header-only versions of library side by side.
Dmitry Igrishin
dmitigr at gmail.com
Wed Jul 3 17:25:49 EDT 2019
Hello,
The libraries I developing can be used as a shared libraries, static
libraries or header-only libraries.
I want to let the users to:
- install all three variants side by side;
- choice what variant of library to use for linkage.
I see 2 options here:
1. use different config files. For example, foo-config.cmake
(corresponds to shared library "foo"), foo_static-config.cmake
(corresponds to static library "foo"), foo_interface-config.cmake
(corresponds to header-only library "foo"). In this case users can
consume appropriate variant of "foo" by using find_package(foo CONFIGS
<config>) and then target_link_libraries(bar foo) or
target_link_libraries(bar foo_static) or target_link_libraries(bar
INTERFACE foo_interface);
2. use different packages. For example, "foo", "foo_static",
"for_interface". In this case users can consume libraries by using
find_package(foo) or find_package(foo_static) or
find_package(foo_interface) and then target_link_libraries(bar foo) or
target_link_libraries(bar INTERFACE foo).
What option is preferable? Or is there are any other options available?
More information about the CMake
mailing list