title: How can I package a Qt program built with CMake on Windows?
body: <p>I'm writing a cross-platform program which I'd like to package on Windows. I got it to run by putting three DLLs (Qt5Core, Qt5Widgets, Qt5Gui) in the build directory, then made a tarball and gave it to someone else with a Windows box, but it would not run on his Windows box. I searched for a way to get whatever else it needed and found Nathan Osman's post about windeployqt, so I copied windeployqt.cmake to the cmake/Modules directory, but couldn't figure out how to use it. Is there a way to use CPack to make a package (even if it's just a tarball) that has everything needed to run the program on a Windows box that doesn't have the compiler or Qt installed?</p>
  
  <p>Here's the CMakeLists.txt file with some (hopefully irrelevant) stuff removed:</p>
  
  <pre><code>project(perfecttin)
  cmake_minimum_required(VERSION 3.8.0)
  set(CMAKE_INCLUDE_CURRENT_DIR ON)
  set(CMAKE_AUTOMOC ON)
  set(CMAKE_CXX_STANDARD 17) # appeared in CMake 3.8
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
  set(CMAKE_CXX_EXTENSIONS ON)
  set(SHARE_DIR ${CMAKE_INSTALL_PREFIX}/share/perfecttin)
  add_definitions(-DBOOST_ALL_NO_LIB)
  if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  set(Boost_USE_STATIC_LIBS ON)
  else ()
  set(Boost_USE_STATIC_LIBS OFF)
  endif ()
  
  set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
  find_package(LibPLYXX)
  find_package(Qt5 COMPONENTS Core Widgets Gui LinguistTools REQUIRED)
  find_package(Boost COMPONENTS program_options)
  find_package(Threads)
  
  qt5_add_resources(lib_resources perfecttin.qrc)
  qt5_add_translation(qm_files perfecttin_en.ts perfecttin_es.ts)
  # To update translations, run "lupdate *.cpp -ts *.ts" in the source directory.
  
  add_executable(perfecttin-gui adjelev.cpp angle.cpp binio.cpp
             &lt;snip lots of source files&gt;
                 unitbutton.cpp ${lib_resources} ${qm_files})
  target_link_libraries(perfecttin-gui ${CMAKE_THREAD_LIBS_INIT} Qt5::Widgets Qt5::Core)
  target_link_libraries(fuzzptin ${CMAKE_THREAD_LIBS_INIT})
  target_compile_definitions(fuzzptin PUBLIC _USE_MATH_DEFINES)
  target_compile_definitions(perfecttin-gui PUBLIC _USE_MATH_DEFINES)
  set_target_properties(perfecttin-gui PROPERTIES WIN32_EXECUTABLE TRUE)
  
  install(TARGETS perfecttin-gui DESTINATION bin)
  install(FILES ${qm_files} DESTINATION share/perfecttin)
  
  include_directories(${PROJECT_BINARY_DIR})
  configure_file (config.h.in config.h)
  
  set(CPACK_PACKAGE_VERSION_MAJOR ${PERFECTTIN_MAJOR_VERSION})
  set(CPACK_PACKAGE_VERSION_MINOR ${PERFECTTIN_MINOR_VERSION})
  set(CPACK_PACKAGE_VERSION_PATCH ${PERFECTTIN_PATCH_VERSION})
  set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/COPYING)
  set(CPACK_SOURCE_IGNORE_FILES /\\\\.git;.*~)
  include(CPack)
  
  include(CTest)
  </code></pre>