QtStaticCMake.cmake 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. #
  2. # Copyright (c) 2019 Olivier Le Doeuff <olivier.ldff@gmail.com>
  3. #
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are met:
  8. #
  9. # 1. Redistributions of source code must retain the above copyright notice, this
  10. # list of conditions and the following disclaimer.
  11. #
  12. # 2. Redistributions in binary form must reproduce the above copyright notice,
  13. # this list of conditions and the following disclaimer in the documentation
  14. # and/or other materials provided with the distribution.
  15. #
  16. # 3. Neither the name of the copyright holder nor the names of its contributors
  17. # may be used to endorse or promote products derived from this software without
  18. # specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  21. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #
  31. cmake_minimum_required(VERSION 3.0)
  32. # ┌──────────────────────────────────────────────────────────────────┐
  33. # │ ENVIRONMENT │
  34. # └──────────────────────────────────────────────────────────────────┘
  35. # find the Qt root directory
  36. if(NOT Qt5Core_DIR)
  37. find_package(Qt5Core REQUIRED)
  38. endif()
  39. get_filename_component(QT_STATIC_QT_ROOT "${Qt5Core_DIR}/../../.." ABSOLUTE)
  40. message(STATUS "Found Qt SDK Root: ${QT_STATIC_QT_ROOT}")
  41. set(QT_STATIC_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
  42. # ┌──────────────────────────────────────────────────────────────────┐
  43. # │ GENERATE QML PLUGIN │
  44. # └──────────────────────────────────────────────────────────────────┘
  45. # We need to parse some arguments
  46. include(CMakeParseArguments)
  47. # Usage:
  48. # qt_generate_qml_plugin_import(YourApp
  49. # QML_DIR "/path/to/qtsdk"
  50. # QML_SRC "/path/to/yourApp/qml"
  51. # OUTPUT "YourApp_qml_plugin_import.cpp"
  52. # OUTPUT_DIR "/path/to/generate"
  53. # EXTRA_PLUGIN
  54. # QtQuickVirtualKeyboardPlugin
  55. # QtQuickVirtualKeyboardSettingsPlugin
  56. # QtQuickVirtualKeyboardStylesPlugin
  57. # QmlFolderListModelPlugin
  58. # QQuickLayoutsPlugin
  59. # VERBOSE
  60. #)
  61. macro(qt_generate_qml_plugin_import TARGET)
  62. set(QT_STATIC_OPTIONS VERBOSE )
  63. set(QT_STATIC_ONE_VALUE_ARG QML_DIR
  64. QML_SRC
  65. OUTPUT
  66. OUTPUT_DIR
  67. )
  68. set(QT_STATIC_MULTI_VALUE_ARG
  69. EXTRA_PLUGIN)
  70. # parse the macro arguments
  71. cmake_parse_arguments(ARGSTATIC "${QT_STATIC_OPTIONS}" "${QT_STATIC_ONE_VALUE_ARG}" "${QT_STATIC_MULTI_VALUE_ARG}" ${ARGN})
  72. # Copy arg variables to local variables
  73. set(QT_STATIC_TARGET ${TARGET})
  74. set(QT_STATIC_QML_DIR ${ARGSTATIC_QML_DIR})
  75. set(QT_STATIC_QML_SRC ${ARGSTATIC_QML_SRC})
  76. set(QT_STATIC_OUTPUT ${ARGSTATIC_OUTPUT})
  77. set(QT_STATIC_OUTPUT_DIR ${ARGSTATIC_OUTPUT_DIR})
  78. set(QT_STATIC_VERBOSE ${ARGSTATIC_VERBOSE})
  79. # Default to QtSdk/qml
  80. if(NOT QT_STATIC_QML_DIR)
  81. set(QT_STATIC_QML_DIR "${QT_STATIC_QT_ROOT}/qml")
  82. if(QT_STATIC_VERBOSE)
  83. message(STATUS "QML_DIR not specified, default to ${QT_STATIC_QML_DIR}")
  84. endif()
  85. endif()
  86. # Default to ${QT_STATIC_TARGET}_qml_plugin_import.cpp
  87. if(NOT QT_STATIC_OUTPUT)
  88. set(QT_STATIC_OUTPUT ${QT_STATIC_TARGET}_qml_plugin_import.cpp)
  89. if(QT_STATIC_VERBOSE)
  90. message(STATUS "OUTPUT not specified, default to ${QT_STATIC_OUTPUT}")
  91. endif()
  92. endif()
  93. # Default to project build directory
  94. if(NOT QT_STATIC_OUTPUT_DIR)
  95. set(QT_STATIC_OUTPUT_DIR ${PROJECT_BINARY_DIR})
  96. if(QT_STATIC_VERBOSE)
  97. message(STATUS "OUTPUT not specified, default to ${QT_STATIC_OUTPUT_DIR}")
  98. endif()
  99. endif()
  100. # Print config
  101. if(QT_STATIC_VERBOSE)
  102. message(STATUS "------ QtStaticCMake Qml Generate Configuration ------")
  103. message(STATUS "TARGET : ${QT_STATIC_TARGET}")
  104. message(STATUS "QML_DIR : ${QT_STATIC_QML_DIR}")
  105. message(STATUS "QML_SRC : ${QT_STATIC_QML_SRC}")
  106. message(STATUS "OUTPUT : ${QT_STATIC_OUTPUT}")
  107. message(STATUS "OUTPUT_DIR : ${QT_STATIC_OUTPUT_DIR}")
  108. message(STATUS "EXTRA_PLUGIN : ${ARGSTATIC_EXTRA_PLUGIN}")
  109. message(STATUS "------ QtStaticCMake Qml Generate End Configuration ------")
  110. endif()
  111. if(QT_STATIC_QML_SRC)
  112. # Debug
  113. if(QT_STATIC_VERBOSE)
  114. message(STATUS "Get Qml Plugin dependencies for ${QT_STATIC_TARGET}. qmlimportscanner path is ${QT_STATIC_QT_ROOT}/bin/qmlimportscanner. RootPath is ${QT_STATIC_QML_SRC} and importPath is ${QT_STATIC_QML_DIR}.")
  115. endif()
  116. # Get Qml Plugin dependencies
  117. execute_process(
  118. COMMAND ${QT_STATIC_QT_ROOT}/bin/qmlimportscanner -rootPath ${QT_STATIC_QML_SRC} -importPath ${QT_STATIC_QML_DIR}
  119. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  120. OUTPUT_VARIABLE QT_STATIC_QML_DEPENDENCIES_JSON
  121. OUTPUT_STRIP_TRAILING_WHITESPACE
  122. )
  123. # Dump Json File for debug
  124. if(QT_STATIC_VERBOSE)
  125. message(STATUS "qmlimportscanner result: ${QT_STATIC_QML_DEPENDENCIES_JSON}")
  126. endif()
  127. # Object look like this :
  128. # {
  129. # "classname": "QtQuick2Plugin",
  130. # "name": "QtQuick",
  131. # "path": "C:/Path/To/qtbase/qml/QtQuick.2",
  132. # "plugin": "qtquick2plugin",
  133. # "relativePath": "QtQuick.2",
  134. # "type": "module",
  135. # "version": "2.14"
  136. # }
  137. # Extract everything inside { ... }
  138. if(QT_STATIC_QML_DEPENDENCIES_JSON)
  139. string(REGEX MATCHALL "\\{([^\\}]*)\\}"
  140. QT_STATIC_QML_IMPORT_JSON_OBJ ${QT_STATIC_QML_DEPENDENCIES_JSON})
  141. else()
  142. message(WARNING "qmlimportscanner didn't find any dependencies")
  143. endif()
  144. # message(STATUS "QT_STATIC_QML_IMPORT_JSON_OBJ : ${QT_STATIC_QML_IMPORT_JSON_OBJ}")
  145. # Now simply loop over objects and extract "classname" for Q_IMPORT_PLUGIN macro
  146. # And "plugin" for find_library
  147. # Also extract path as hint if available
  148. foreach(JSON_OBJECT ${QT_STATIC_QML_IMPORT_JSON_OBJ})
  149. string(REGEX MATCH "\"classname\"\\: \"([a-zA-Z0-9]*)\"" CLASS_NAME ${JSON_OBJECT})
  150. #message(STATUS "CLASS_NAME : ${CLASS_NAME}")
  151. if(CMAKE_MATCH_1 AND NOT ${CMAKE_MATCH_1} STREQUAL "")
  152. set(_TEMP_CLASSNAME ${CMAKE_MATCH_1})
  153. set(${_TEMP_CLASSNAME}_CLASSNAME ${CMAKE_MATCH_1})
  154. list(FIND QT_STATIC_QML_DEPENDENCIES_PLUGINS ${CMAKE_MATCH_1} _PLUGIN_INDEX)
  155. if(_PLUGIN_INDEX EQUAL -1)
  156. list(APPEND QT_STATIC_QML_DEPENDENCIES_PLUGINS ${CMAKE_MATCH_1})
  157. string(REGEX MATCH "\"plugin\"\\: \"([a-zA-Z0-9_]*)\"" PLUGIN_NAME ${JSON_OBJECT})
  158. set(${_TEMP_CLASSNAME}_PLUGIN ${CMAKE_MATCH_1})
  159. #message(STATUS "PLUGIN_NAME : ${PLUGIN_NAME}")
  160. string(REGEX MATCH "\"path\"\\: \"([^\"]*)\"" PLUGIN_PATH ${JSON_OBJECT})
  161. #message(STATUS "PLUGIN_PATH : ${PLUGIN_PATH}")
  162. set(${_TEMP_CLASSNAME}_PATH ${CMAKE_MATCH_1})
  163. endif()
  164. endif()
  165. endforeach()
  166. # Print dependencies
  167. # if(QT_STATIC_VERBOSE)
  168. # message(STATUS "${QT_STATIC_TARGET} qml plugin dependencies:")
  169. # foreach(PLUGIN ${QT_STATIC_QML_DEPENDENCIES_PLUGINS})
  170. # message(STATUS "${PLUGIN}")
  171. # endforeach()
  172. # endif()
  173. if(QT_STATIC_VERBOSE)
  174. message(STATUS "Generate ${QT_STATIC_OUTPUT} in ${QT_STATIC_OUTPUT_DIR}")
  175. endif()
  176. # Build file path
  177. set(QT_STATIC_QML_PLUGIN_SRC_FILE "${QT_STATIC_OUTPUT_DIR}/${QT_STATIC_OUTPUT}")
  178. # Write file header
  179. file(WRITE ${QT_STATIC_QML_PLUGIN_SRC_FILE} "// File Generated via CMake script during build time.\n"
  180. "// The purpose of this file is to force the static load of qml plugin during static build\n"
  181. "// Please rerun CMake to update this file.\n"
  182. "// File will be overwrite at each CMake run.\n"
  183. "\n#include <QtPlugin>\n\n")
  184. function(qt_static_generate_path_suffix result parentDir)
  185. file(GLOB_RECURSE children LIST_DIRECTORIES TRUE RELATIVE ${parentDir} ${parentDir}/*)
  186. set(dirlist "")
  187. foreach(child ${children})
  188. if(IS_DIRECTORY ${parentDir}/${child})
  189. list(APPEND dirlist ${child})
  190. endif()
  191. endforeach()
  192. set(${result} ${dirlist} PARENT_SCOPE)
  193. endfunction()
  194. # Generate PLUGIN_PATH_SUFFIXES for find_library PATH_SUFFIXES for plugin that do not have path set by qmlimportscanner
  195. qt_static_generate_path_suffix(PLUGIN_PATH_SUFFIXES ${QT_STATIC_QML_DIR})
  196. # Write Q_IMPORT_PLUGIN for each plugin
  197. foreach(PLUGIN ${QT_STATIC_QML_DEPENDENCIES_PLUGINS})
  198. # todo : in the future if any exclude plugin is added, filtering need to occur here.
  199. file(APPEND ${QT_STATIC_QML_PLUGIN_SRC_FILE} "Q_IMPORT_PLUGIN(${PLUGIN});\n")
  200. endforeach()
  201. # Add the file to the target sources
  202. if(QT_STATIC_VERBOSE)
  203. message(STATUS "Add ${QT_STATIC_QML_PLUGIN_SRC_FILE} to ${QT_STATIC_TARGET} sources")
  204. endif()
  205. target_sources(${QT_STATIC_TARGET} PRIVATE ${QT_STATIC_QML_PLUGIN_SRC_FILE})
  206. set(QT_STATIC_ALL_PLUGINS ${QT_STATIC_QML_DEPENDENCIES_PLUGINS} ${ARGSTATIC_EXTRA_PLUGIN})
  207. # Find the library associated with the plugin
  208. foreach(PLUGIN ${QT_STATIC_ALL_PLUGINS})
  209. # Try to use plugin name from qmlimportscanner
  210. set(_PLUGIN_LIBRARY_NAME ${${PLUGIN}_PLUGIN})
  211. if(NOT _PLUGIN_LIBRARY_NAME)
  212. #message(WARNING "Plugin ${PLUGIN} doesn't have a \"plugin\" field, use plugin name")
  213. set(_PLUGIN_LIBRARY_NAME ${PLUGIN})
  214. endif()
  215. string(TOLOWER ${_PLUGIN_LIBRARY_NAME} _PLUGIN_LIBRARY_NAME_LOWER)
  216. # Try to use path from qmlimportscanner
  217. if(${${PLUGIN}_PATH})
  218. find_library(${PLUGIN}_plugin "${_PLUGIN_LIBRARY_NAME_LOWER}"
  219. HINTS ${${PLUGIN}_PATH})
  220. find_library(${PLUGIN}_plugind "${_PLUGIN_LIBRARY_NAME_LOWER}d"
  221. HINTS ${${PLUGIN}_PATH})
  222. else()
  223. find_library(${PLUGIN}_plugin NAMES "${_PLUGIN_LIBRARY_NAME_LOWER}" "lib${_PLUGIN_LIBRARY_NAME_LOWER}"
  224. HINTS ${QT_STATIC_QML_DIR}
  225. PATH_SUFFIXES ${PLUGIN_PATH_SUFFIXES})
  226. find_library(${PLUGIN}_plugind NAMES "${_PLUGIN_LIBRARY_NAME_LOWER}d" "lib${_PLUGIN_LIBRARY_NAME_LOWER}d"
  227. HINTS ${QT_STATIC_QML_DIR}
  228. PATH_SUFFIXES ${PLUGIN_PATH_SUFFIXES})
  229. endif()
  230. # Use release library for release if available, otherwise debug library, otherwise produce warning
  231. if(${${PLUGIN}_plugin} STREQUAL "${PLUGIN}_plugin-NOTFOUND")
  232. # Fallback on debug library
  233. if(${${PLUGIN}_plugind} STREQUAL "${PLUGIN}_plugind-NOTFOUND")
  234. message(WARNING "Fail to find ${PLUGIN} for release build (release or debug library not available)")
  235. else()
  236. target_link_libraries(${QT_STATIC_TARGET} PRIVATE ${${PLUGIN}_plugind})
  237. if(QT_STATIC_VERBOSE)
  238. message(STATUS "${PLUGIN} Release : Found ${${PLUGIN}_plugind} (release library not available, use debug as fallback)")
  239. endif()
  240. endif()
  241. else()
  242. target_link_libraries(${QT_STATIC_TARGET} PRIVATE $<$<NOT:$<CONFIG:Debug>>:${${PLUGIN}_plugin}>)
  243. if(QT_STATIC_VERBOSE)
  244. message(STATUS "${PLUGIN} Release : Found ${${PLUGIN}_plugin}")
  245. endif()
  246. endif()
  247. # Use debug library for debug if available, otherwise release library, otherwise produce warning
  248. if(${${PLUGIN}_plugind} STREQUAL "${PLUGIN}_plugind-NOTFOUND")
  249. # Fallback on release library
  250. if(${${PLUGIN}_plugin} STREQUAL "${PLUGIN}_plugin-NOTFOUND")
  251. message(WARNING "Fail to find ${PLUGIN} for debug build (release or debug library not available)")
  252. else()
  253. target_link_libraries(${QT_STATIC_TARGET} PRIVATE ${${PLUGIN}_plugin})
  254. if(QT_STATIC_VERBOSE)
  255. message(STATUS "${PLUGIN} Debug : Found ${${PLUGIN}_plugin} (debug library not available, use release as fallback)")
  256. endif()
  257. endif()
  258. else()
  259. target_link_libraries(${QT_STATIC_TARGET} PRIVATE $<$<CONFIG:Debug>:${${PLUGIN}_plugind}>)
  260. if(QT_STATIC_VERBOSE)
  261. message(STATUS "${PLUGIN} Debug : Found ${${PLUGIN}_plugind}")
  262. endif()
  263. endif()
  264. endforeach()
  265. else()
  266. message(WARNING "QT_STATIC_QML_SRC not specified. Can't generate Q_IMPORT_PLUGIN for qml plugin")
  267. endif()
  268. get_target_property(CURRENT_INTERFACE_SOURCES ${QT_STATIC_TARGET} INTERFACE_SOURCES)
  269. if(${CURRENT_INTERFACE_SOURCES} STREQUAL "CURRENT_INTERFACE_SOURCES-NOTFOUND")
  270. set(CURRENT_INTERFACE_SOURCES ${QT_STATIC_QML_PLUGIN_SRC_FILE})
  271. else()
  272. set(CURRENT_INTERFACE_SOURCES ${CURRENT_INTERFACE_SOURCES} ${QT_STATIC_QML_PLUGIN_SRC_FILE})
  273. endif()
  274. set_target_properties(${QT_STATIC_TARGET} PROPERTIES INTERFACE_SOURCES "${CURRENT_INTERFACE_SOURCES}")
  275. endmacro()
  276. # ┌──────────────────────────────────────────────────────────────────┐
  277. # │ GENERATE QT PLUGIN │
  278. # └──────────────────────────────────────────────────────────────────┘
  279. # Usage:
  280. # qt_generate_plugin_import(YourApp
  281. # OUTPUT "YourApp_plugin_import.cpp"
  282. # OUTPUT_DIR "/path/to/generate"
  283. # VERBOSE
  284. #)
  285. macro(qt_generate_plugin_import TARGET)
  286. set(QT_STATIC_OPTIONS VERBOSE )
  287. set(QT_STATIC_ONE_VALUE_ARG OUTPUT
  288. OUTPUT_DIR
  289. )
  290. set(QT_STATIC_MULTI_VALUE_ARG)
  291. # parse the macro arguments
  292. cmake_parse_arguments(ARGSTATIC "${QT_STATIC_OPTIONS}" "${QT_STATIC_ONE_VALUE_ARG}" "${QT_STATIC_MULTI_VALUE_ARG}" ${ARGN})
  293. # Copy arg variables to local variables
  294. set(QT_STATIC_TARGET ${TARGET})
  295. set(QT_STATIC_OUTPUT ${ARGSTATIC_OUTPUT})
  296. set(QT_STATIC_OUTPUT_DIR ${ARGSTATIC_OUTPUT_DIR})
  297. set(QT_STATIC_VERBOSE ${ARGSTATIC_VERBOSE})
  298. # Default to ${QT_STATIC_TARGET}_qml_plugin_import.cpp
  299. if(NOT QT_STATIC_OUTPUT)
  300. set(QT_STATIC_OUTPUT ${QT_STATIC_TARGET}_plugin_import.cpp)
  301. if(QT_STATIC_VERBOSE)
  302. message(STATUS "OUTPUT not specified, default to ${QT_STATIC_OUTPUT}")
  303. endif()
  304. endif()
  305. # Default to project build directory
  306. if(NOT QT_STATIC_OUTPUT_DIR)
  307. set(QT_STATIC_OUTPUT_DIR ${PROJECT_BINARY_DIR})
  308. if(QT_STATIC_VERBOSE)
  309. message(STATUS "OUTPUT not specified, default to ${QT_STATIC_OUTPUT_DIR}")
  310. endif()
  311. endif()
  312. # Print config
  313. if(QT_STATIC_VERBOSE)
  314. message(STATUS "------ QtStaticCMake Plugin Generate Configuration ------")
  315. message(STATUS "TARGET : ${QT_STATIC_TARGET}")
  316. message(STATUS "OUTPUT : ${QT_STATIC_OUTPUT}")
  317. message(STATUS "OUTPUT_DIR : ${QT_STATIC_OUTPUT_DIR}")
  318. message(STATUS "------ QtStaticCMake Plugin Generate End Configuration ------")
  319. endif()
  320. if(QT_STATIC_VERBOSE)
  321. message(STATUS "Generate ${QT_STATIC_OUTPUT} in ${QT_STATIC_OUTPUT_DIR}")
  322. endif()
  323. set(QT_STATIC_PLUGIN_SRC_FILE "${QT_STATIC_OUTPUT_DIR}/${QT_STATIC_OUTPUT}")
  324. # Write the file header
  325. file(WRITE ${QT_STATIC_PLUGIN_SRC_FILE} "// File Generated via CMake script during build time.\n"
  326. "// The purpose of this file is to force the static load of qml plugin during static build\n"
  327. "// Please rerun CMake to update this file.\n"
  328. "// File will be overwrite at each CMake run.\n"
  329. "\n#include <QtPlugin>\n")
  330. # Get all available Qt5 module
  331. file(GLOB QT_STATIC_AVAILABLES_QT_DIRECTORIES
  332. LIST_DIRECTORIES true
  333. RELATIVE ${QT_STATIC_QT_ROOT}/lib/cmake
  334. ${QT_STATIC_QT_ROOT}/lib/cmake/Qt5*)
  335. foreach(DIR ${QT_STATIC_AVAILABLES_QT_DIRECTORIES})
  336. set(DIR_PRESENT ${${DIR}_DIR})
  337. if(DIR_PRESENT)
  338. set(DIR_PLUGIN_CONTENT ${${DIR}_PLUGINS})
  339. # Only print if there are some plugin
  340. if(DIR_PLUGIN_CONTENT)
  341. # Comment for help dubugging
  342. file(APPEND ${QT_STATIC_PLUGIN_SRC_FILE} "\n// ${DIR}\n")
  343. # Parse Plugin to append to the list only if unique
  344. foreach(PLUGIN ${DIR_PLUGIN_CONTENT})
  345. # List form is Qt5::NameOfPlugin, we just need NameOfPlugin
  346. string(REGEX MATCH ".*\\:\\:(.*)" PLUGIN_MATCH ${PLUGIN})
  347. set(PLUGIN_NAME ${CMAKE_MATCH_1})
  348. # Should be NameOfPlugin
  349. if(PLUGIN_NAME)
  350. # Keep track to only write once each plugin
  351. list(FIND QT_STATIC_DEPENDENCIES_PLUGINS ${PLUGIN_NAME} _PLUGIN_INDEX)
  352. # Only Write/Keep track if the plugin isn't already present
  353. if(_PLUGIN_INDEX EQUAL -1)
  354. list(APPEND QT_STATIC_DEPENDENCIES_PLUGINS ${PLUGIN_NAME})
  355. file(APPEND ${QT_STATIC_PLUGIN_SRC_FILE} "Q_IMPORT_PLUGIN(${PLUGIN_NAME});\n")
  356. set(PLUGIN_LIBRARY Qt5::${PLUGIN_NAME})
  357. if(QT_STATIC_VERBOSE)
  358. message(STATUS "Force link to qml plugin ${PLUGIN_LIBRARY}")
  359. endif()
  360. target_link_libraries(${QT_STATIC_TARGET} PRIVATE ${PLUGIN_LIBRARY})
  361. endif()
  362. endif()
  363. endforeach()
  364. endif()
  365. endif()
  366. endforeach()
  367. # Print dependencies
  368. if(QT_STATIC_VERBOSE)
  369. message(STATUS "${QT_STATIC_TARGET} plugin dependencies:")
  370. foreach(PLUGIN ${QT_STATIC_DEPENDENCIES_PLUGINS})
  371. message(STATUS "${PLUGIN}")
  372. endforeach()
  373. endif()
  374. # Add the generated file into source of the application
  375. if(QT_STATIC_VERBOSE)
  376. message(STATUS "Add ${QT_STATIC_PLUGIN_SRC_FILE} to ${QT_STATIC_TARGET} sources")
  377. endif()
  378. target_sources(${QT_STATIC_TARGET} PRIVATE ${QT_STATIC_PLUGIN_SRC_FILE})
  379. if(${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
  380. # Link to the platform library
  381. if(QT_STATIC_VERBOSE)
  382. message(STATUS "Add -u _qt_registerPlatformPlugin linker flag to ${QT_STATIC_TARGET} in order to force load qios library")
  383. endif()
  384. target_link_libraries(${QT_STATIC_TARGET} PUBLIC "-u _qt_registerPlatformPlugin")
  385. endif()
  386. get_target_property(CURRENT_INTERFACE_SOURCES ${QT_STATIC_TARGET} INTERFACE_SOURCES)
  387. if(${CURRENT_INTERFACE_SOURCES} STREQUAL "CURRENT_INTERFACE_SOURCES-NOTFOUND")
  388. set(CURRENT_INTERFACE_SOURCES ${QT_STATIC_PLUGIN_SRC_FILE})
  389. else()
  390. set(CURRENT_INTERFACE_SOURCES ${CURRENT_INTERFACE_SOURCES} ${QT_STATIC_PLUGIN_SRC_FILE})
  391. endif()
  392. set_target_properties(${QT_STATIC_TARGET} PROPERTIES INTERFACE_SOURCES "${CURRENT_INTERFACE_SOURCES}")
  393. endmacro()