aboutsummaryrefslogtreecommitdiffstats
path: root/src/QtCreatorDeployment.cmake
blob: cf2567ca4ec1c4e9e6800e6432fb3089da24e910 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Dependencies component
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16)
  get_target_property(moc_binary Qt5::moc IMPORTED_LOCATION)
  get_filename_component(moc_dir "${moc_binary}" DIRECTORY)
  get_filename_component(qt5_base_dir "${moc_dir}/../" ABSOLUTE)

  if (MSVC AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(exclusion_mask PATTERN "*d.dll" EXCLUDE)
  endif()

  if (WIN32)
    set(qt5_plugin_dest_dir ${IDE_BIN_PATH}/plugins)
    set(qt5_qml_dest_dir ${IDE_BIN_PATH}/qml)
    set(qt_conf_dir ${IDE_APP_PATH})
  elseif(APPLE)
    set(qt5_plugin_dest_dir ${IDE_PLUGIN_PATH})
    set(qt5_qml_dest_dir ${IDE_DATA_PATH}/../Imports/qtquick2)
    set(qt_conf_dir ${IDE_DATA_PATH})
  else()
    set(qt5_plugin_dest_dir ${IDE_LIBRARY_BASE_PATH}/Qt/plugins)
    set(qt5_qml_dest_dir ${IDE_LIBRARY_BASE_PATH}/Qt/qml)
    set(qt_conf_dir ${IDE_APP_PATH})
  endif()

  foreach(plugin
    designer iconengines imageformats platforms platformthemes
    printsupport qmltooling sqldrivers styles)
    if(NOT EXISTS "${qt5_base_dir}/plugins/${plugin}")
      continue()
    endif()
    install(
      DIRECTORY "${qt5_base_dir}/plugins/${plugin}"
      DESTINATION ${qt5_plugin_dest_dir}
      COMPONENT Dependencies EXCLUDE_FROM_ALL
      ${exclusion_mask}
    )
  endforeach()

  install(
    DIRECTORY "${qt5_base_dir}/qml/"
    DESTINATION ${qt5_qml_dest_dir}
    COMPONENT Dependencies EXCLUDE_FROM_ALL
    PATTERN "qml/*"
    ${exclusion_mask}
  )

  install(CODE "
    get_filename_component(install_prefix \"\${CMAKE_INSTALL_PREFIX}\" ABSOLUTE)
    file(RELATIVE_PATH qt_conf_binaries
      \"\${install_prefix}/${qt_conf_dir}\"
      \"\${install_prefix}/${IDE_BIN_PATH}\"
    )
    if (NOT qt_conf_binaries)
      set(qt_conf_binaries .)
    endif()
    file(RELATIVE_PATH qt_conf_plugins
      \"\${install_prefix}/${qt_conf_dir}\"
      \"\${install_prefix}/${qt5_plugin_dest_dir}\"
    )
    file(RELATIVE_PATH qt_conf_qml
      \"\${install_prefix}/${qt_conf_dir}\"
      \"\${install_prefix}/${qt5_qml_dest_dir}\"
    )

    file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qt_conf_dir}/qt.conf\"
      \"[Paths]\n\"
      \"Binaries=\${qt_conf_binaries}\n\"
      \"Plugins=\${qt_conf_plugins}\n\"
      \"Qml2Imports=\${qt_conf_qml}\n\"
     )
    "
    COMPONENT Dependencies EXCLUDE_FROM_ALL
   )

  # Analyze the binaries and install missing dependencies if they are
  # found the CMAKE_PREFIX_PATH e.g. Qt, Clang
  install(CODE
    "
    if (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES \"Clang\")
      set(CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL objdump)
    endif()
    if (WIN32)
      set(pre_exclude_regexes PRE_EXCLUDE_REGEXES \"api-ms-.*|ext-ms-\.*\")
    endif()

    get_filename_component(install_prefix \"\${CMAKE_INSTALL_PREFIX}\" ABSOLUTE)

    set(installed_EXECUTABLES_NOT_PREFIXED \"${__QTC_INSTALLED_EXECUTABLES}\")
    set(installed_LIBRARIES_NOT_PREFIXED \"${__QTC_INSTALLED_LIBRARIES}\")
    set(installed_MODULES_NOT_PREFIXED \"${__QTC_INSTALLED_PLUGINS}\")

    foreach(binary_type EXECUTABLES LIBRARIES MODULES)
      foreach(element IN LISTS installed_\${binary_type}_NOT_PREFIXED)
        if (EXISTS \"\${install_prefix}/\${element}\")
          list(APPEND installed_\${binary_type} \"\${install_prefix}/\${element}\")
        endif()
      endforeach()
    endforeach()

    # Install first the dependencies, and in second step the dependencies
    # from the installed dependencies e.g. libicu for libQt5Core on Linux.
    foreach(step 1 2)
      foreach(binary_type EXECUTABLES LIBRARIES MODULES)
        list(LENGTH installed_\${binary_type} list_size)
        if (NOT list_size EQUAL 0)
          set(\${binary_type}_TO_ANALYZE \${binary_type} \"\${installed_\${binary_type}}\")
        else()
          set(\${binary_type}_TO_ANALYZE \"\")
        endif()
      endforeach()

      file(GET_RUNTIME_DEPENDENCIES
        UNRESOLVED_DEPENDENCIES_VAR unresolved_deps
        \${EXECUTABLES_TO_ANALYZE}
        \${LIBRARIES_TO_ANALYZE}
        \${MODULES_TO_ANALYZE}
        DIRECTORIES
          \"\${install_prefix}/${IDE_PLUGIN_PATH}\"
          \"\${install_prefix}/${IDE_LIBEXEC_PATH}\"
          \"\${install_prefix}/${IDE_LIBRARY_PATH}\"
        \${pre_exclude_regexes}
      )

      # Clear for second step
      set(installed_EXECUTABLES \"\")
      set(installed_LIBRARIES \"\")
      set(installed_MODULES \"\")

      list(REMOVE_DUPLICATES unresolved_deps)

      if (WIN32)
        # Needed by QmlDesigner, QmlProfiler, but they are not referenced directly.
        list(APPEND unresolved_deps libEGL.dll libGLESv2.dll)
      endif()

      get_filename_component(compiler_dir \"${CMAKE_CXX_COMPILER}\" DIRECTORY)
      file(TO_CMAKE_PATH \"${CMAKE_PREFIX_PATH}\" prefix_path)
      list(APPEND prefix_path \"\${compiler_dir}\")
      foreach(so IN LISTS unresolved_deps)
        string(REPLACE \"@rpath/\" \"\" so \"\${so}\")
        get_filename_component(so_dir \"\${so}\" DIRECTORY)
        message(STATUS \"Unresolved dependency: \${so}\")
        foreach(p IN LISTS prefix_path)
          message(STATUS \"Trying: \${p}/\${so}\")
          if (EXISTS \"\${p}/\${so}\")
            file(INSTALL \"\${p}/\${so}\"
              DESTINATION \"\${install_prefix}/${IDE_APP_PATH}/\${so_dir}\"
              FOLLOW_SYMLINK_CHAIN)
            list(APPEND installed_LIBRARIES \"\${install_prefix}/${IDE_APP_PATH}/\${so}\")
            break()
          endif()
          message(STATUS \"Trying: \${p}/bin/\${so}\")
          if (EXISTS \"\${p}/bin/\${so}\")
            file(INSTALL \"\${p}/bin/\${so}\"
              DESTINATION \"\${install_prefix}/${IDE_BIN_PATH}/\${so_dir}\"
              FOLLOW_SYMLINK_CHAIN)
            list(APPEND installed_LIBRARIES \"\${install_prefix}/${IDE_BIN_PATH}/\${so}\")
            break()
          endif()
          message(STATUS \"Trying: \${p}/lib/\${so}\")
          if (EXISTS \"\${p}/lib/\${so}\")
            file(INSTALL \"\${p}/lib/\${so}\"
              DESTINATION \"\${install_prefix}/${IDE_LIBRARY_PATH}/\${so_dir}\"
              FOLLOW_SYMLINK_CHAIN)
            list(APPEND installed_LIBRARIES \"\${install_prefix}/${IDE_LIBRARY_PATH}/\${so}\")
            break()
          endif()
        endforeach()
      endforeach()
    endforeach()
    "
    COMPONENT Dependencies EXCLUDE_FROM_ALL
  )

  if (MSVC)
    set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP ON)
    include(InstallRequiredsystemLibraries)

    install(PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
      DESTINATION ${IDE_APP_PATH}
      COMPONENT Dependencies EXCLUDE_FROM_ALL
    )
  endif()

endif()