-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IMPORTED_IMPLIB property to each CMake Module #2425
Conversation
@@ -51,6 +51,6 @@ if(AOM_LIBRARY) | |||
else() | |||
add_library(aom SHARED IMPORTED GLOBAL) | |||
endif() | |||
set_target_properties(aom PROPERTIES IMPORTED_LOCATION "${AOM_LIBRARY}") | |||
set_target_properties(aom PROPERTIES IMPORTED_LOCATION "${AOM_LIBRARY}" IMPORTED_IMPLIB "${AOM_LIBRARY}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yannis: Thank you for writing a fix. Note that this comment is just a comment, not a request for change.
According to CMake documentation, IMPORTED_LOCATION
is the pathname of the DLL and IMPORTED_IMPLIB
is the pathname of the import library. So the file names are different (.dll vs. .lib) and the files may be installed in different subdirectories (bin vs. lib, as @vtorri noted in #2423 (comment)).
Perhaps the CMake documentation about this is incomplete and setting IMPORTED_LOCATION
and IMPORTED_IMPLIB
to the same value also works. Perhaps setting IMPORTED_IMPLIB
to the pathname of some file is better than not setting it. I don't know. I am just reporting what I found in the CMake documentation.
Here are the relevant excerpts:
https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_LOCATION.html
IMPORTED_LOCATION
Full path to the main file on disk for an IMPORTED target.
Set this to the location of an IMPORTED target file on disk. [...] For DLLs this is the location of the .dll part of the library. [...]
https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_IMPLIB.html
IMPORTED_IMPLIB
Full path to the import library for an IMPORTED target.
This property may be set:
- On DLL platforms, to the location of the .lib part of the DLL.
https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#importing-libraries
On Windows, a .dll and its .lib import library may be imported together:
add_library(bar SHARED IMPORTED) set_property(TARGET bar PROPERTY IMPORTED_LOCATION "c:/path/to/bar.dll") set_property(TARGET bar PROPERTY IMPORTED_IMPLIB "c:/path/to/bar.lib") add_executable(myexe src1.c src2.c) target_link_libraries(myexe PRIVATE bar)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a comment in a CMake issue that apparently matches what @vtorri reported in #2423 (comment) and explains why this pull request works:
https://gitlab.kitware.com/cmake/cmake/-/issues/22446#note_1444129
On a related note, MinGW can directly link with DLLs, without the need for an import library. It would be great if, when building with a MinGW toolchain,
IMPORTED_IMPLIB
were optional andIMPORTED_LOCATION
were used if it is absent. (As a workaround, specifying the path to the DLL asIMPORTED_IMPLIB
seems to work, but only by accident.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for investigating.
Apply cmake-format.
Fixes #2423.