Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-55465

Declare an imported target in cmake modules for windeployqt

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Done
    • Icon: P3: Somewhat important P3: Somewhat important
    • 6.2.7
    • None
    • None

      Cmake modules for Qt5 declare an imported target for qmake (Qt5::qmake). It can be helpful to have the same type of target declared for windeployqt.

      In my [cmake projet](https://github.com/wasthishelpful/softbloks/blob/master/CMakeLists.txt), I use the following snippet to declare the target:

      find_package(Qt5 COMPONENTS
      ...
      )
      
      if(Qt5_FOUND AND WIN32 AND TARGET Qt5::qmake AND NOT TARGET Qt5::windeployqt)
      
      get_target_property(_qt5_qmake_location Qt5::qmake IMPORTED_LOCATION)
      
      execute_process(
      COMMAND "${_qt5_qmake_location}" -query QT_INSTALL_PREFIX
      RESULT_VARIABLE return_code
      OUTPUT_VARIABLE qt5_install_prefix
      OUTPUT_STRIP_TRAILING_WHITESPACE
      )
      
      set(imported_location "${qt5_install_prefix}/bin/windeployqt.exe")
      
      if(EXISTS ${imported_location})
      
      add_executable(Qt5::windeployqt IMPORTED)
      
      set_target_properties(Qt5::windeployqt PROPERTIES
      IMPORTED_LOCATION ${imported_location}
      )
      
      endif()
      
      endif()
      
      Usage:
      
      add_executable(foo
      ...
      )
      
      if(TARGET Qt5::windeployqt)
      
      add_custom_command(TARGET foo POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/windeployqt"
      COMMAND set PATH=%PATH%$<SEMICOLON>${qt5_install_prefix}/bin
      COMMAND Qt5::windeployqt --dir "${CMAKE_CURRENT_BINARY_DIR}/windeployqt" "$<TARGET_FILE_DIR:foo>/$<TARGET_FILE_NAME:foo>"
      )
      
      install(
      DIRECTORY
      "${CMAKE_CURRENT_BINARY_DIR}/windeployqt/"
      DESTINATION ...
      )
      
      endif()
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Unassigned Unassigned
            wasthishelpful wasthishelpful
            Veli-Pekka Heinonen Veli-Pekka Heinonen
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes