FindBoost: Provide simultaneous targets for both static and dynamic and for dynamic targets add BOOST_<Component>_DYN_LINK"
FindBoost states:
https://cmake.org/cmake/help/v3.9/module/FindBoost.html?highlight=findboost#
Boost_USE_STATIC_LIBS - Set to ON to force the use of the static
libraries. Default is OFF.
also:
Boost::<C> - Target for specific component dependency
(shared or static library); <C> is lower-
case
So either static or dynamic, but both of the two. Recall boost will build both allowing either or both (ok well not on same target... that's just silly) to be used in the same project.
Why would a programmer say want to link statically and dynamically in the same project? Lets say you have a client and server application where the server is fully controlled, but the client is given to a third-party. Now when an as to be unnamed NASA Research Center copies your client application which talks to your spaceflight hardware without copying the necessary dlls and your then told to build them all statically into one large app, but still need to build the dynamic dlls for the server what do you do?... Sigh... yes this happend.
I could do:
set_target_properties(Boost::system PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "BOOST_SYSTEM_DYN_LINK")
set_target_properties(Boost::date_time PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "BOOST_DATE_TIME_DYN_LINK")
set_target_properties(Boost::filesystem PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "BOOST_FILESYSTEM_DYN_LINK")
set_target_properties(Boost::serialization PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "BOOST_SERIALIZATION_DYN_LINK")
Where C/C++->Preprocessor->Preprocessor Definitions is now:
BOOST_SYSTEM_DYN_LINK
BOOST_DATE_TIME_DYN_LINK
BOOST_FILESYSTEM_DYN_LINK
BOOST_SERIALIZATION_DYN_LINK
Then I though why in the age of automation is this not automatic?
Well then you submit a bug report to CMake and hope for a change of say:
Remove:
Boost_USE_STATIC_LIBS - Set to ON to force the use of the static
libraries. Default is OFF.
as an option and add lib specific BOOST_WHATEVER_DYN_LINK as specified here:
http://www.boost.org/doc/libs/1_58_0/libs/config/doc/html/index.html
by setting target properties.
set_target_properties(Boost::${COMPONENT} PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "BOOST_${UPPERCOMPONENT}_DYN_LINK"
)
as
Boost::dynamic_linking - interface target to enable dynamic linking
linking with MSVC (adds BOOST_ALL_DYN_LINK)
is an all or none option.
Also find/build static lib and create target (this bit I don't have fully working as almost 2k lines FindBoost.cmake is a gooptastic mess). Here prefixed with "lib".
#if(Boost_USE_STATIC_LIBS)
add_library(Boost::${COMPONENT} UNKNOWN IMPORTED)
# bjd - add both lib (static) and shared.
add_library(Boost::lib${COMPONENT} STATIC IMPORTED)
#else()
# Even if Boost_USE_STATIC_LIBS is OFF, we might have static
# libraries as a result.
# bjd - so at least it is documented that this might be possible. If only it handled the case
#add_library(Boost::${COMPONENT} UNKNOWN IMPORTED)
#endif()
The current version I have: