We have a product that creates a few libraries that are in turn combined with more code to make a super library.
For example, we have static libraries lib-A and lib-B that are combined with even more source code to make static lib-C.
When creating lib-C
it integrates with lib-A
and lib-B
using
target_link_libraries(...PRIVATE...)
We also have extra custom logic that causes the objects from lib-A
and lib-B
to be embedded in lib-C
. So in the end lib-C
has all of it’s object files as well as all of the object files from lib-A
and lib-B
.
We then export lib-C
using the instructions from the “Importing and Exporting Guide”.
However, we’re hitting an unexpected problem. Our executables that link with lib-C
are raising an error that they cannot find lib-A
or lib-B
.
For example:
LINK : fatal error LNK1181: cannot open input file 'lib-A_64.lib' [C:\...\foo_64.vcxproj]
When I dug into this I found that this is most likely because of the exported library for lib-C
. The generated lib-C_64Targets.cmake
has logic such as the following:
set_target_properties(lib-C_64 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "OpenMP::OpenMP_CXX;\$<LINK_ONLY:lib-A_64>;\$<LINK_ONLY:lib-B_64>"
)
I believe it’s the presense of these LINK_ONLY
entries in the INTERFACE_LINK_LIBRARIES
properties.
I know that, I can manually remove these values from the INTERFACE_LINK_LIBRARIES
after embedding the libraries. I can do so first reading the property, adjusting it and then writing it back. However, I would like to learn if there is a more elegant “CMake” way of achieving my goal.
Can you teach me of a different or better way?
Thank you.