When target_link_library(foo bar)
is called with bar
as a target of a SHARED
library, CMake will use a static lib libbar.dll.a
or bar.lib
as an input on Windows. However, MinGW, for example, is capable of linking to a binary file like on Ubuntu. Is it possible to tell cmake to use a dll directly when target_link_library
is called?
The obvious workaround is to use generator expressions:
target_link_libraries(foo PRIVATE $<TARGET_FILE:bar>)
Clearly, it has its shortcomings. When you link against a target
, you also add its PUBLIC
and INTERFACE
included directories and linked libraries.
So, in order to fully link in that manner one would have to write something like:
get_target_property(INCLUDE_DIRS bar INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(LINK_LIBS bar INTERFACE_LINK_LIBRARIES)
target_include_directories(foo PRIVATE ${INCLUDE_DIRS})
target_link_libraries(foo PRIVATE ${LINK_LIBS} $<TARGET_FILE:bar>)
So the question is about the possibility to override CMake's default target_link_libraries
behavior.