Jepessen
Jepessen

Reputation: 12415

How to copy qwindows.dll into platforms target subfolder?

I am trying to copy qwindows.dll from qt library folder to target one. At the moment I am using the following code:

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::QWindowsIntegrationPlugin> $<TARGET_FILE_DIR:${PROJECT_NAME}>)

It works, but it copies the file in the target directory. I need to copy the file inside a platforms subfolder, and I don't know what to do. I've tried

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::QWindowsIntegrationPlugin> $<TARGET_FILE_DIR:${PROJECT_NAME}>/platforms/qwindows.dll)

But the problem is that the .dll has another name in debug mode (qwindowsd.dll) so I need to insert the command two times.

Is there a way to use the Qt5::QWindowsIntegrationPlugin to retrieve the file name and use it as destination file in the second command?

Upvotes: 0

Views: 678

Answers (1)

Ben
Ben

Reputation: 21

add_custom_command(
    TARGET demo POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:demo>/platforms/
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        $<TARGET_FILE:Qt5::QWindowsIntegrationPlugin>
        $<TARGET_FILE_DIR:demo>/platforms/
)

Upvotes: 2

Related Questions