What is the recommended/correct value of `IMPORTED_LOCATION` for IMPORTED library targets?
Descriptions
According to the Documentation of CMake, there is a generator expression called TARGET_RUNTIME_DLLS
, which is introduced in CMake version 3.21. The value of $<TARGET_RUNTIME_DLLS:tgt>
is determined by the target property IMPORTED_LOCATION
of tgt
.
With the help of this TARGET_RUNTIME_DLLS
, we can easily copy those RUNTIME dependencies to the output directory with add_custom_command()
on Windows platform. For example: (Theoretically)
Click to expand
find_package(OpenCV CONFIG REQUIRED)
find_package(Qt6 CONFIG REQUIRED
COMPONENTS Core Widgets Gui)
add_executable(exe main.cpp)
target_link_libraries(exe
PRIVATE
opencv_core
opencv_imgproc
Qt6::Core
Qt6::Widgets
Qt6::Gui)
add_custom_command(TARGET exe POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_RUNTIME_DLLS:exe>
$<TARGET_FILE_DIR:exe>
COMMAND_EXPAND_LISTS)
However, lots of third-party libraries don't add this property to their IMPORTED library targets. Even if they do, it seems that they only provide one value of specific configuration for IMPORTED_LOCATION
. For example:
-
opencv_core:
<variable>-NOTFOUND
-
Qt6::Core:
C:/Qt/6.2.0/msvc2019_64/bin/Qt6Core.dll
(Release version)
My Question
I want to know what is the recommended or correct value of IMPORETED_LOCATION
when there exist MULTIPLE configurations (e.g. Debug
and Release
)?
- One value of a specific configuration.
- A list of multiple values corresponding to each configuration with
$<CONFIG:cfg>
.
In my opinion, I prefer the 2nd way. The value of it would be like:
$<$<CONFIG:Debug>:C:/Qt/6.2.0/msvc2019_64/bin/Qt6Cored.dll>;
$<$<CONFIG:Release>:C:/Qt/6.2.0/msvc2019_64/bin/Qt6Core.dll>
What is the opinion of CMake official?