Skip to content

[bug] CMakeDeps: issues when import library (.lib) and DLL (.dll) have a different filename #16926

@jcar87

Description

@jcar87

Describe the bug

CMakeDeps uses the library name passed to cpp_info.libs to locate both the import library (.lib) and the DLL (.dll):

if(is_host_windows AND library_type STREQUAL "SHARED")
# Store and reset the variable, so it doesn't leak
set(_OLD_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_FIND_LIBRARY_SUFFIXES .dll ${CMAKE_FIND_LIBRARY_SUFFIXES})
find_library(CONAN_SHARED_FOUND_LIBRARY NAMES ${_LIBRARY_NAME} PATHS ${package_bindir}
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_OLD_CMAKE_FIND_LIBRARY_SUFFIXES})
if(NOT CONAN_SHARED_FOUND_LIBRARY)

While it is common, it is not a hard requirement for both files to have the same leaf name but a different extension. We can link against a foo.lib that will introduce a dependency on bar.dll (instead of foo.dll), and it is perfectly valid - the name of the corresponding dll is encoded in the import library. According to a comment here: https://stackoverflow.com/questions/52821978/get-a-dll-name-from-import-library, a single .lib may require multiple DLLs (although we need to find a more authoritative source for this)

However, the cpp_info.libs model does not have a facility to express cases where the filenames are different. Conan will display a warning, as in most cases, CMake does "nothing" with the DLL and only the .lib file is required to link. However, some consumer projects may perform target introspection to derive the name of the DLL.

Details here conan-io/conan-center-index#25076 (comment)

Related to: #12654

How to reproduce it

No response

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions