FindwxWidgets.cmake 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindwxWidgets
  5. -------------
  6. Finds a wxWidgets installation and provides usage requirements for usage in
  7. projects:
  8. .. code-block:: cmake
  9. find_package(wxWidgets [<version>] [COMPONENTS <components>...] [...])
  10. wxWidgets (formerly known as wxWindows) is a widget toolkit and tools
  11. library for creating graphical user interfaces (GUIs) for cross-platform
  12. applications.
  13. .. versionadded:: 3.4
  14. Support for :command:`find_package` version argument.
  15. .. versionadded:: 3.14
  16. ``OPTIONAL_COMPONENTS`` support.
  17. Components
  18. ^^^^^^^^^^
  19. wxWidgets is a modular library. This module supports components to specify
  20. the modules to use. Components can be specified with the
  21. :command:`find_package` command:
  22. .. code-block:: cmake
  23. find_package(
  24. wxWidgets
  25. [COMPONENTS <components>...]
  26. [OPTIONAL_COMPONENTS <components>...]
  27. )
  28. Supported components include:
  29. ``base``
  30. Finds the library that provides mandatory classes that any wxWidgets code
  31. depends on. This component is always required for applications
  32. implementing wxWidgets.
  33. ``core``
  34. Finds the library that provides basic GUI classes such as GDI classes or
  35. controls.
  36. ``gl``
  37. Finds the OpenGL support.
  38. ``mono``
  39. Finds the wxWidgets monolithic library.
  40. ``aui``
  41. Finds the Advanced User Interface docking library.
  42. ``net``
  43. Finds the library that provides network access.
  44. ``webview``
  45. .. versionadded:: 3.4
  46. Finds the library that provides rendering of web documents
  47. (HTML/CSS/JavaScript).
  48. For a full list of supported wxWidgets components, refer to the upstream
  49. documentation.
  50. If no components are specified, this module by default searches for ``core``
  51. and ``base`` components.
  52. Imported Targets
  53. ^^^^^^^^^^^^^^^^
  54. This module provides the following :ref:`Imported Targets`:
  55. ``wxWidgets::wxWidgets``
  56. .. versionadded:: 3.27
  57. An interface imported target encapsulating the wxWidgets usage requirements
  58. for the found components, available if wxWidgets is found.
  59. Result Variables
  60. ^^^^^^^^^^^^^^^^
  61. This module defines the following variables:
  62. ``wxWidgets_FOUND``
  63. Boolean indicating whether (the requested version of) wxWidgets and all
  64. its requested components are found.
  65. ``wxWidgets_VERSION``
  66. .. versionadded:: 4.2
  67. The version of the wxWidgets found.
  68. ``wxWidgets_INCLUDE_DIRS``
  69. Include directories for WIN32, i.e., where to find ``<wx/wx.h>`` and
  70. ``<wx/setup.h>``; possibly empty for Unix-like systems.
  71. ``wxWidgets_LIBRARIES``
  72. Path to the wxWidgets libraries.
  73. ``wxWidgets_LIBRARY_DIRS``
  74. Compile time link dirs, useful for setting ``rpath`` on Unix-like systems.
  75. Typically an empty string in WIN32 environment.
  76. ``wxWidgets_DEFINITIONS``
  77. Contains compile definitions required to compile/link against WX, e.g.
  78. ``WXUSINGDLL``.
  79. ``wxWidgets_DEFINITIONS_DEBUG``
  80. Contains compile definitions required to compile/link against WX debug builds,
  81. e.g. ``__WXDEBUG__``.
  82. ``wxWidgets_CXX_FLAGS``
  83. Include directories and compiler flags for Unix-like systems, empty on
  84. Windows. Essentially the output of ``wx-config --cxxflags``.
  85. Hints
  86. ^^^^^
  87. This module accepts the following variables before calling
  88. ``find_package(wxWidgets)``:
  89. ``WX_CONFIG``
  90. .. versionadded:: 3.11
  91. Environment variable to manually specify the name of the wxWidgets library
  92. configuration provider executable that will be searched besides the default
  93. name ``wx-config``.
  94. ``WXRC_CMD``
  95. .. versionadded:: 3.11
  96. Environment variable to manually specify the name of the wxWidgets resource
  97. file compiler executable that will be searched besides the default name
  98. ``wxrc``.
  99. There are two search branches: a Windows style and a Unix style. For
  100. Windows, the following variables are searched for and set to defaults
  101. in case of multiple choices. Change them if the defaults are not
  102. desired (i.e., these are the only variables that should be changed to
  103. select a configuration):
  104. ``wxWidgets_ROOT_DIR``
  105. Base wxWidgets directory (e.g., ``C:/wxWidgets-3.2.0``).
  106. ``wxWidgets_LIB_DIR``
  107. Path to wxWidgets libraries (e.g., ``C:/wxWidgets-3.2.0/lib/vc_x64_lib``).
  108. ``wxWidgets_CONFIGURATION``
  109. Configuration to use (e.g., msw, mswd, mswu, mswunivud, etc.)
  110. ``wxWidgets_EXCLUDE_COMMON_LIBRARIES``
  111. Set to TRUE to exclude linking of commonly required libs (e.g., png, tiff,
  112. jpeg, zlib, regex, expat, scintilla, lexilla, etc.).
  113. For Unix style this module uses the ``wx-config`` utility. Selecting
  114. between debug/release, unicode/ansi, universal/non-universal, and
  115. static/shared is possible in the QtDialog or ccmake interfaces by turning
  116. ON/OFF the following variables:
  117. ``wxWidgets_USE_DEBUG``
  118. If enabled, the wxWidgets debug build will be searched.
  119. ``wxWidgets_USE_UNICODE``
  120. If enabled, the wxWidgets unicode build will be searched.
  121. ``wxWidgets_USE_UNIVERSAL``
  122. If enabled, the wxWidgets universal build will be searched.
  123. ``wxWidgets_USE_STATIC``
  124. If enabled, static wxWidgets libraries will be linked.
  125. ``wxWidgets_CONFIG_OPTIONS``
  126. This variable can be used for all other options that need to be passed to
  127. the wx-config utility. For example, to use the base toolkit found on the
  128. system at ``/usr`` install prefix, set the variable (before calling the
  129. :command:`find_package` command) as such:
  130. .. code-block:: cmake
  131. set(wxWidgets_CONFIG_OPTIONS --toolkit=base --prefix=/usr)
  132. Deprecated Variables
  133. ^^^^^^^^^^^^^^^^^^^^
  134. The following variables are provided for backward compatibility:
  135. ``wxWidgets_VERSION_STRING``
  136. .. deprecated:: 4.2
  137. Use ``wxWidgets_VERSION``, which has the same value.
  138. .. versionadded:: 3.4
  139. The version of the wxWidgets found.
  140. ``wxWidgets_USE_FILE``
  141. .. deprecated:: 4.2
  142. Instead of using this variable, include the :module:`UsewxWidgets`
  143. module directly:
  144. .. code-block:: cmake
  145. include(UsewxWidgets)
  146. The path to the :module:`UsewxWidgets` module for using wxWidgets in the
  147. current directory. For example:
  148. .. code-block:: cmake
  149. find_package(wxWidgets)
  150. if(wxWidgets_FOUND)
  151. include(${wxWidgets_USE_FILE})
  152. endif()
  153. Examples
  154. ^^^^^^^^
  155. Example: Finding wxWidgets
  156. """"""""""""""""""""""""""
  157. Finding wxWidgets and making it required (if wxWidgets is not found,
  158. processing stops with an error message):
  159. .. code-block:: cmake
  160. find_package(wxWidgets REQUIRED)
  161. Example: Using Imported Target
  162. """"""""""""""""""""""""""""""
  163. Finding wxWidgets and using imported target in a project:
  164. .. code-block:: cmake
  165. find_package(wxWidgets)
  166. target_link_libraries(example PRIVATE wxWidgets::wxWidgets)
  167. Example: Using Components
  168. """""""""""""""""""""""""
  169. Finding wxWidgets and specifying components:
  170. .. code-block:: cmake
  171. find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net)
  172. target_link_libraries(example PRIVATE wxWidgets::wxWidgets)
  173. Example: Monolithic wxWidgets Build
  174. """""""""""""""""""""""""""""""""""
  175. Sample usage with monolithic wxWidgets build:
  176. .. code-block:: cmake
  177. find_package(wxWidgets COMPONENTS mono)
  178. target_link_libraries(example PRIVATE wxWidgets::wxWidgets)
  179. Example: Using Variables
  180. """"""""""""""""""""""""
  181. Finding and using wxWidgets in CMake versions prior to 3.27, when the
  182. imported target wasn't yet available:
  183. .. code-block:: cmake
  184. # Note that for MinGW users the order of libs is important.
  185. find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net)
  186. if(wxWidgets_FOUND)
  187. include(UsewxWidgets)
  188. # and for each of the project dependent executable/library targets:
  189. target_link_libraries(example ${wxWidgets_LIBRARIES})
  190. endif()
  191. #]=======================================================================]
  192. # NOTES
  193. #
  194. # This module has been tested on the WIN32 platform with wxWidgets
  195. # 2.6.2, 2.6.3, and 2.5.3. However, it has been designed to
  196. # easily extend support to all possible builds, e.g., static/shared,
  197. # debug/release, unicode, universal, multilib/monolithic, etc..
  198. #
  199. # If you want to use the module and your build type is not supported
  200. # out-of-the-box, please contact me to exchange information on how
  201. # your system is setup and I'll try to add support for it.
  202. #
  203. # AUTHOR
  204. #
  205. # Miguel A. Figueroa-Villanueva (miguelf at ieee dot org).
  206. # Jan Woetzel (jw at mip.informatik.uni-kiel.de).
  207. #
  208. # Based on previous works of:
  209. # Jan Woetzel (FindwxWindows.cmake),
  210. # Jorgen Bodde and Jerry Fath (FindwxWin.cmake).
  211. # TODO/ideas
  212. #
  213. # (1) Option/Setting to use all available wx libs
  214. # In contrast to expert developer who lists the
  215. # minimal set of required libs in wxWidgets_USE_LIBS
  216. # there is the newbie user:
  217. # - who just wants to link against WX with more 'magic'
  218. # - doesn't know the internal structure of WX or how it was built,
  219. # in particular if it is monolithic or not
  220. # - want to link against all available WX libs
  221. # Basically, the intent here is to mimic what wx-config would do by
  222. # default (i.e., `wx-config --libs`).
  223. #
  224. # Possible solution:
  225. # Add a reserved keyword "std" that initializes to what wx-config
  226. # would default to. If the user has not set the wxWidgets_USE_LIBS,
  227. # default to "std" instead of "base core" as it is now. To implement
  228. # "std" will basically boil down to a FOR_EACH lib-FOUND, but maybe
  229. # checking whether a minimal set was found.
  230. # FIXME: This and all the DBG_MSG calls should be removed after the
  231. # module stabilizes.
  232. #
  233. # Helper macro to control the debugging output globally. There are
  234. # two versions for controlling how verbose your output should be.
  235. macro(DBG_MSG _MSG)
  236. # message(STATUS
  237. # "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}")
  238. endmacro()
  239. macro(DBG_MSG_V _MSG)
  240. # message(STATUS
  241. # "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}")
  242. endmacro()
  243. # Clear return values in case the module is loaded more than once.
  244. set(wxWidgets_FOUND FALSE)
  245. set(wxWidgets_INCLUDE_DIRS "")
  246. set(wxWidgets_LIBRARIES "")
  247. set(wxWidgets_LIBRARY_DIRS "")
  248. set(wxWidgets_CXX_FLAGS "")
  249. # DEPRECATED: This is a patch to support the DEPRECATED use of
  250. # wxWidgets_USE_LIBS.
  251. #
  252. # If wxWidgets_USE_LIBS is set:
  253. # - if using <components>, then override wxWidgets_USE_LIBS
  254. # - else set wxWidgets_FIND_COMPONENTS to wxWidgets_USE_LIBS
  255. if(wxWidgets_USE_LIBS AND NOT wxWidgets_FIND_COMPONENTS)
  256. set(wxWidgets_FIND_COMPONENTS ${wxWidgets_USE_LIBS})
  257. endif()
  258. DBG_MSG("wxWidgets_FIND_COMPONENTS : ${wxWidgets_FIND_COMPONENTS}")
  259. # Add the convenience use file if available.
  260. #
  261. # Get dir of this file which may reside in:
  262. # - CMAKE_ROOT/Modules on CMake installation
  263. # - CMAKE_MODULE_PATH if the user prefers their own specialized version
  264. set(wxWidgets_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_DIR}")
  265. # Prefer an existing customized version, but the user might override
  266. # the FindwxWidgets module and not the UsewxWidgets one.
  267. if(EXISTS "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
  268. set(wxWidgets_USE_FILE "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
  269. else()
  270. set(wxWidgets_USE_FILE UsewxWidgets)
  271. endif()
  272. # Known wxWidgets versions.
  273. set(wx_versions 3.3 3.2 3.1 3.0 2.9 2.8 2.7 2.6 2.5)
  274. macro(wx_extract_version)
  275. unset(_wx_filename)
  276. find_file(_wx_filename wx/version.h PATHS ${wxWidgets_INCLUDE_DIRS} NO_DEFAULT_PATH)
  277. dbg_msg("_wx_filename: ${_wx_filename}")
  278. if(NOT _wx_filename)
  279. message(FATAL_ERROR "wxWidgets wx/version.h file not found in ${wxWidgets_INCLUDE_DIRS}.")
  280. endif()
  281. file(READ "${_wx_filename}" _wx_version_h)
  282. unset(_wx_filename CACHE)
  283. string(REGEX REPLACE "^(.*\n)?#define +wxMAJOR_VERSION +([0-9]+).*"
  284. "\\2" wxWidgets_VERSION_MAJOR "${_wx_version_h}" )
  285. string(REGEX REPLACE "^(.*\n)?#define +wxMINOR_VERSION +([0-9]+).*"
  286. "\\2" wxWidgets_VERSION_MINOR "${_wx_version_h}" )
  287. string(REGEX REPLACE "^(.*\n)?#define +wxRELEASE_NUMBER +([0-9]+).*"
  288. "\\2" wxWidgets_VERSION_PATCH "${_wx_version_h}" )
  289. string(REGEX REPLACE "^(.*\n)?#define +wxSUBRELEASE_NUMBER +([0-9]+).*"
  290. "\\2" wxWidgets_VERSION_TWEAK "${_wx_version_h}" )
  291. set(wxWidgets_VERSION
  292. "${wxWidgets_VERSION_MAJOR}.${wxWidgets_VERSION_MINOR}.${wxWidgets_VERSION_PATCH}")
  293. if(${wxWidgets_VERSION_TWEAK} GREATER 0)
  294. string(APPEND wxWidgets_VERSION ".${wxWidgets_VERSION_TWEAK}")
  295. endif()
  296. set(wxWidgets_VERSION_STRING "${wxWidgets_VERSION}")
  297. endmacro()
  298. #=====================================================================
  299. # Determine whether unix or win32 paths should be used
  300. #=====================================================================
  301. if(WIN32 AND NOT CYGWIN AND NOT MSYS AND NOT CMAKE_CROSSCOMPILING)
  302. set(wxWidgets_FIND_STYLE "win32")
  303. else()
  304. set(wxWidgets_FIND_STYLE "unix")
  305. endif()
  306. #=====================================================================
  307. # WIN32_FIND_STYLE
  308. #=====================================================================
  309. if(wxWidgets_FIND_STYLE STREQUAL "win32")
  310. # Useful common wx libs needed by almost all components.
  311. set(wxWidgets_COMMON_LIBRARIES png tiff jpeg zlib regex expat)
  312. # Libraries needed by stc component
  313. set(wxWidgets_STC_LIBRARIES scintilla lexilla)
  314. # DEPRECATED: Use find_package(wxWidgets COMPONENTS mono) instead.
  315. if(NOT wxWidgets_FIND_COMPONENTS)
  316. if(wxWidgets_USE_MONOLITHIC)
  317. set(wxWidgets_FIND_COMPONENTS mono)
  318. else()
  319. set(wxWidgets_FIND_COMPONENTS core base) # this is default
  320. endif()
  321. endif()
  322. # Add the common (usually required libs) unless
  323. # wxWidgets_EXCLUDE_COMMON_LIBRARIES has been set.
  324. if(NOT wxWidgets_EXCLUDE_COMMON_LIBRARIES)
  325. if(stc IN_LIST wxWidgets_FIND_COMPONENTS)
  326. list(APPEND wxWidgets_FIND_COMPONENTS ${wxWidgets_STC_LIBRARIES})
  327. endif()
  328. list(APPEND wxWidgets_FIND_COMPONENTS ${wxWidgets_COMMON_LIBRARIES})
  329. endif()
  330. # Remove duplicates, for example when user has specified common libraries.
  331. list(REMOVE_DUPLICATES wxWidgets_FIND_COMPONENTS)
  332. #-------------------------------------------------------------------
  333. # WIN32: Helper MACROS
  334. #-------------------------------------------------------------------
  335. #
  336. # Get filename components for a configuration. For example,
  337. # if _CONFIGURATION = mswunivud, then _PF="msw", _UNV=univ, _UCD=u _DBG=d
  338. # if _CONFIGURATION = mswu, then _PF="msw", _UNV="", _UCD=u _DBG=""
  339. #
  340. macro(WX_GET_NAME_COMPONENTS _CONFIGURATION _PF _UNV _UCD _DBG)
  341. DBG_MSG_V(${_CONFIGURATION})
  342. string(REGEX MATCH "univ" ${_UNV} "${_CONFIGURATION}")
  343. string(REGEX REPLACE "[msw|qt].*(u)[d]*$" "u" ${_UCD} "${_CONFIGURATION}")
  344. if(${_UCD} STREQUAL ${_CONFIGURATION})
  345. set(${_UCD} "")
  346. endif()
  347. string(REGEX MATCH "d$" ${_DBG} "${_CONFIGURATION}")
  348. string(REGEX MATCH "^[msw|qt]*" ${_PF} "${_CONFIGURATION}")
  349. endmacro()
  350. #
  351. # Find libraries associated to a configuration.
  352. #
  353. macro(WX_FIND_LIBS _PF _UNV _UCD _DBG _VER)
  354. DBG_MSG_V("m_unv = ${_UNV}")
  355. DBG_MSG_V("m_ucd = ${_UCD}")
  356. DBG_MSG_V("m_dbg = ${_DBG}")
  357. DBG_MSG_V("m_ver = ${_VER}")
  358. # FIXME: What if both regex libs are available. regex should be
  359. # found outside the loop and only wx${LIB}${_UCD}${_DBG}.
  360. # Find wxWidgets common libraries.
  361. foreach(LIB ${wxWidgets_COMMON_LIBRARIES} ${wxWidgets_STC_LIBRARIES})
  362. find_library(WX_${LIB}${_DBG}
  363. NAMES
  364. wx${LIB}${_UCD}${_DBG} # for regex
  365. wx${LIB}${_DBG}
  366. PATHS ${WX_LIB_DIR}
  367. NO_DEFAULT_PATH
  368. )
  369. mark_as_advanced(WX_${LIB}${_DBG})
  370. endforeach()
  371. # Find wxWidgets multilib base libraries.
  372. find_library(WX_base${_DBG}
  373. NAMES wxbase${_VER}${_UCD}${_DBG}
  374. PATHS ${WX_LIB_DIR}
  375. NO_DEFAULT_PATH
  376. )
  377. mark_as_advanced(WX_base${_DBG})
  378. foreach(LIB net odbc xml)
  379. find_library(WX_${LIB}${_DBG}
  380. NAMES wxbase${_VER}${_UCD}${_DBG}_${LIB}
  381. PATHS ${WX_LIB_DIR}
  382. NO_DEFAULT_PATH
  383. )
  384. mark_as_advanced(WX_${LIB}${_DBG})
  385. endforeach()
  386. # Find wxWidgets monolithic library.
  387. find_library(WX_mono${_DBG}
  388. NAMES wx${_PF}${_UNV}${_VER}${_UCD}${_DBG}
  389. PATHS ${WX_LIB_DIR}
  390. NO_DEFAULT_PATH
  391. )
  392. mark_as_advanced(WX_mono${_DBG})
  393. # Find wxWidgets multilib libraries.
  394. foreach(LIB core adv aui html media xrc dbgrid gl qa richtext
  395. stc ribbon propgrid webview)
  396. find_library(WX_${LIB}${_DBG}
  397. NAMES wx${_PF}${_UNV}${_VER}${_UCD}${_DBG}_${LIB}
  398. PATHS ${WX_LIB_DIR}
  399. NO_DEFAULT_PATH
  400. )
  401. mark_as_advanced(WX_${LIB}${_DBG})
  402. endforeach()
  403. endmacro()
  404. #
  405. # Clear all library paths, so that FIND_LIBRARY refinds them.
  406. #
  407. # Clear a lib, reset its found flag, and mark as advanced.
  408. macro(WX_CLEAR_LIB _LIB)
  409. set(${_LIB} "${_LIB}-NOTFOUND" CACHE FILEPATH "Cleared." FORCE)
  410. set(${_LIB}_FOUND FALSE)
  411. mark_as_advanced(${_LIB})
  412. endmacro()
  413. # Clear all debug or release library paths (arguments are "d" or "").
  414. macro(WX_CLEAR_ALL_LIBS _DBG)
  415. # Clear wxWidgets common libraries.
  416. foreach(LIB ${wxWidgets_COMMON_LIBRARIES} ${wxWidgets_STC_LIBRARIES})
  417. WX_CLEAR_LIB(WX_${LIB}${_DBG})
  418. endforeach()
  419. # Clear wxWidgets multilib base libraries.
  420. WX_CLEAR_LIB(WX_base${_DBG})
  421. foreach(LIB net odbc xml)
  422. WX_CLEAR_LIB(WX_${LIB}${_DBG})
  423. endforeach()
  424. # Clear wxWidgets monolithic library.
  425. WX_CLEAR_LIB(WX_mono${_DBG})
  426. # Clear wxWidgets multilib libraries.
  427. foreach(LIB core adv aui html media xrc dbgrid gl qa richtext
  428. webview stc ribbon propgrid)
  429. WX_CLEAR_LIB(WX_${LIB}${_DBG})
  430. endforeach()
  431. endmacro()
  432. # Clear all wxWidgets debug libraries.
  433. macro(WX_CLEAR_ALL_DBG_LIBS)
  434. WX_CLEAR_ALL_LIBS("d")
  435. endmacro()
  436. # Clear all wxWidgets release libraries.
  437. macro(WX_CLEAR_ALL_REL_LIBS)
  438. WX_CLEAR_ALL_LIBS("")
  439. endmacro()
  440. #
  441. # Set the wxWidgets_LIBRARIES variable.
  442. # Also, Sets output variable wxWidgets_FOUND to FALSE if it fails.
  443. #
  444. macro(WX_SET_LIBRARIES _LIBS _DBG)
  445. DBG_MSG_V("Looking for ${${_LIBS}}")
  446. if(WX_USE_REL_AND_DBG)
  447. foreach(LIB ${${_LIBS}})
  448. DBG_MSG_V("Searching for ${LIB} and ${LIB}d")
  449. DBG_MSG_V("WX_${LIB} : ${WX_${LIB}}")
  450. DBG_MSG_V("WX_${LIB}d : ${WX_${LIB}d}")
  451. if(WX_${LIB} AND WX_${LIB}d)
  452. DBG_MSG_V("Found ${LIB} and ${LIB}d")
  453. list(APPEND wxWidgets_LIBRARIES
  454. debug ${WX_${LIB}d} optimized ${WX_${LIB}}
  455. )
  456. set(wxWidgets_${LIB}_FOUND TRUE)
  457. elseif(NOT wxWidgets_FIND_REQUIRED_${LIB})
  458. DBG_MSG_V("- ignored optional missing WX_${LIB}=${WX_${LIB}} or WX_${LIB}d=${WX_${LIB}d}")
  459. else()
  460. DBG_MSG_V("- not found due to missing WX_${LIB}=${WX_${LIB}} or WX_${LIB}d=${WX_${LIB}d}")
  461. set(wxWidgets_FOUND FALSE)
  462. endif()
  463. endforeach()
  464. else()
  465. foreach(LIB ${${_LIBS}})
  466. DBG_MSG_V("Searching for ${LIB}${_DBG}")
  467. DBG_MSG_V("WX_${LIB}${_DBG} : ${WX_${LIB}${_DBG}}")
  468. if(WX_${LIB}${_DBG})
  469. DBG_MSG_V("Found ${LIB}${_DBG}")
  470. list(APPEND wxWidgets_LIBRARIES ${WX_${LIB}${_DBG}})
  471. set(wxWidgets_${LIB}_FOUND TRUE)
  472. elseif(NOT wxWidgets_FIND_REQUIRED_${LIB})
  473. DBG_MSG_V("- ignored optional missing WX_${LIB}${_DBG}=${WX_${LIB}${_DBG}}")
  474. else()
  475. DBG_MSG_V("- not found due to missing WX_${LIB}${_DBG}=${WX_${LIB}${_DBG}}")
  476. set(wxWidgets_FOUND FALSE)
  477. endif()
  478. endforeach()
  479. endif()
  480. DBG_MSG_V("OpenGL")
  481. if(gl IN_LIST ${_LIBS})
  482. DBG_MSG_V("- is required.")
  483. list(APPEND wxWidgets_LIBRARIES opengl32 glu32)
  484. endif()
  485. if(stc IN_LIST ${_LIBS})
  486. list(APPEND wxWidgets_LIBRARIES imm32)
  487. endif()
  488. list(APPEND wxWidgets_LIBRARIES gdiplus msimg32 winmm comctl32 uuid oleacc uxtheme rpcrt4 shlwapi version wsock32)
  489. endmacro()
  490. #-------------------------------------------------------------------
  491. # WIN32: Start actual work.
  492. #-------------------------------------------------------------------
  493. set(wx_paths "wxWidgets")
  494. foreach(version ${wx_versions})
  495. foreach(patch RANGE 15 0 -1)
  496. list(APPEND wx_paths "wxWidgets-${version}.${patch}")
  497. foreach(tweak RANGE 3 1 -1)
  498. list(APPEND wx_paths "wxWidgets-${version}.${patch}.${tweak}")
  499. endforeach()
  500. endforeach()
  501. endforeach()
  502. # Look for an installation tree.
  503. find_path(wxWidgets_ROOT_DIR
  504. NAMES include/wx/wx.h
  505. PATHS
  506. ENV wxWidgets_ROOT_DIR
  507. ENV WXWIN
  508. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\wxWidgets_is1;Inno Setup: App Path]" # WX 2.6.x
  509. C:/
  510. D:/
  511. ENV ProgramFiles
  512. PATH_SUFFIXES
  513. ${wx_paths}
  514. DOC "wxWidgets base/installation directory"
  515. )
  516. # If wxWidgets_ROOT_DIR changed, clear lib dir.
  517. if(NOT WX_ROOT_DIR STREQUAL wxWidgets_ROOT_DIR)
  518. if(NOT wxWidgets_LIB_DIR OR WX_ROOT_DIR)
  519. set(wxWidgets_LIB_DIR "wxWidgets_LIB_DIR-NOTFOUND"
  520. CACHE PATH "Cleared." FORCE)
  521. endif()
  522. set(WX_ROOT_DIR ${wxWidgets_ROOT_DIR}
  523. CACHE INTERNAL "wxWidgets_ROOT_DIR")
  524. endif()
  525. if(WX_ROOT_DIR)
  526. # Select one default tree inside the already determined wx tree.
  527. # Prefer static/shared order usually consistent with build
  528. # settings.
  529. set(_WX_TOOL "")
  530. set(_WX_TOOLVER "")
  531. set(_WX_ARCH "")
  532. if(MINGW)
  533. set(_WX_TOOL gcc)
  534. elseif(MSVC)
  535. set(_WX_TOOL vc)
  536. set(_WX_TOOLVER ${MSVC_TOOLSET_VERSION})
  537. # support for a lib/vc14x_x64_dll/ path from wxW 3.1.3 distribution
  538. string(REGEX REPLACE ".$" "x" _WX_TOOLVERx ${_WX_TOOLVER})
  539. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  540. set(_WX_ARCH _x64)
  541. endif()
  542. endif()
  543. if(BUILD_SHARED_LIBS)
  544. find_path(wxWidgets_LIB_DIR
  545. NAMES
  546. qtu/wx/setup.h
  547. qtud/wx/setup.h
  548. msw/wx/setup.h
  549. mswd/wx/setup.h
  550. mswu/wx/setup.h
  551. mswud/wx/setup.h
  552. mswuniv/wx/setup.h
  553. mswunivd/wx/setup.h
  554. mswunivu/wx/setup.h
  555. mswunivud/wx/setup.h
  556. PATHS
  557. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}_xp${_WX_ARCH}_dll # prefer shared
  558. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}${_WX_ARCH}_dll # prefer shared
  559. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVERx}_xp${_WX_ARCH}_dll # prefer shared
  560. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVERx}${_WX_ARCH}_dll # prefer shared
  561. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_ARCH}_dll # prefer shared
  562. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}_xp${_WX_ARCH}_lib
  563. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}${_WX_ARCH}_lib
  564. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVERx}_xp${_WX_ARCH}_lib
  565. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVERx}${_WX_ARCH}_lib
  566. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_ARCH}_lib
  567. DOC "Path to wxWidgets libraries"
  568. NO_DEFAULT_PATH
  569. )
  570. else()
  571. find_path(wxWidgets_LIB_DIR
  572. NAMES
  573. qtu/wx/setup.h
  574. qtud/wx/setup.h
  575. msw/wx/setup.h
  576. mswd/wx/setup.h
  577. mswu/wx/setup.h
  578. mswud/wx/setup.h
  579. mswuniv/wx/setup.h
  580. mswunivd/wx/setup.h
  581. mswunivu/wx/setup.h
  582. mswunivud/wx/setup.h
  583. PATHS
  584. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}_xp${_WX_ARCH}_lib # prefer static
  585. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}${_WX_ARCH}_lib # prefer static
  586. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVERx}_xp${_WX_ARCH}_lib # prefer static
  587. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVERx}${_WX_ARCH}_lib # prefer static
  588. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_ARCH}_lib # prefer static
  589. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}_xp${_WX_ARCH}_dll
  590. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}${_WX_ARCH}_dll
  591. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVERx}_xp${_WX_ARCH}_dll
  592. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVERx}${_WX_ARCH}_dll
  593. ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_ARCH}_dll
  594. DOC "Path to wxWidgets libraries"
  595. NO_DEFAULT_PATH
  596. )
  597. endif()
  598. unset(_WX_TOOL)
  599. unset(_WX_TOOLVER)
  600. unset(_WX_ARCH)
  601. # If wxWidgets_LIB_DIR changed, clear all libraries.
  602. if(NOT WX_LIB_DIR STREQUAL wxWidgets_LIB_DIR)
  603. set(WX_LIB_DIR ${wxWidgets_LIB_DIR} CACHE INTERNAL "wxWidgets_LIB_DIR")
  604. WX_CLEAR_ALL_DBG_LIBS()
  605. WX_CLEAR_ALL_REL_LIBS()
  606. endif()
  607. if(WX_LIB_DIR)
  608. # If building shared libs, define WXUSINGDLL to use dllimport.
  609. if(WX_LIB_DIR MATCHES "[dD][lL][lL]")
  610. set(wxWidgets_DEFINITIONS WXUSINGDLL)
  611. DBG_MSG_V("detected SHARED/DLL tree WX_LIB_DIR=${WX_LIB_DIR}")
  612. endif()
  613. # Search for available configuration types.
  614. foreach(CFG mswunivud mswunivd mswud mswd mswunivu mswuniv mswu msw qt qtd qtu qtud)
  615. set(WX_${CFG}_FOUND FALSE)
  616. if(EXISTS ${WX_LIB_DIR}/${CFG})
  617. list(APPEND WX_CONFIGURATION_LIST ${CFG})
  618. set(WX_${CFG}_FOUND TRUE)
  619. set(WX_CONFIGURATION ${CFG})
  620. endif()
  621. endforeach()
  622. DBG_MSG_V("WX_CONFIGURATION_LIST=${WX_CONFIGURATION_LIST}")
  623. if(WX_CONFIGURATION)
  624. set(wxWidgets_FOUND TRUE)
  625. # If the selected configuration wasn't found force the default
  626. # one. Otherwise, use it but still force a refresh for
  627. # updating the doc string with the current list of available
  628. # configurations.
  629. if(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
  630. set(wxWidgets_CONFIGURATION ${WX_CONFIGURATION} CACHE STRING
  631. "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
  632. else()
  633. set(wxWidgets_CONFIGURATION ${wxWidgets_CONFIGURATION} CACHE STRING
  634. "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
  635. endif()
  636. # If release config selected, and both release/debug exist.
  637. if(WX_${wxWidgets_CONFIGURATION}d_FOUND)
  638. option(wxWidgets_USE_REL_AND_DBG
  639. "Use release and debug configurations?" TRUE)
  640. set(WX_USE_REL_AND_DBG ${wxWidgets_USE_REL_AND_DBG})
  641. else()
  642. # If the option exists (already in cache), force it false.
  643. if(wxWidgets_USE_REL_AND_DBG)
  644. set(wxWidgets_USE_REL_AND_DBG FALSE CACHE BOOL
  645. "No ${wxWidgets_CONFIGURATION}d found." FORCE)
  646. endif()
  647. set(WX_USE_REL_AND_DBG FALSE)
  648. endif()
  649. # Get configuration parameters from the name.
  650. WX_GET_NAME_COMPONENTS(${wxWidgets_CONFIGURATION} PF UNV UCD DBG)
  651. # Set wxWidgets lib setup include directory.
  652. if(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
  653. set(wxWidgets_INCLUDE_DIRS
  654. ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION})
  655. else()
  656. DBG_MSG("wxWidgets_FOUND FALSE because ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h does not exist.")
  657. set(wxWidgets_FOUND FALSE)
  658. endif()
  659. # Set wxWidgets main include directory.
  660. if(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
  661. list(APPEND wxWidgets_INCLUDE_DIRS ${WX_ROOT_DIR}/include)
  662. else()
  663. DBG_MSG("wxWidgets_FOUND FALSE because WX_ROOT_DIR=${WX_ROOT_DIR} has no ${WX_ROOT_DIR}/include/wx/wx.h")
  664. set(wxWidgets_FOUND FALSE)
  665. endif()
  666. # Get version number.
  667. wx_extract_version()
  668. set(VER "${wxWidgets_VERSION_MAJOR}${wxWidgets_VERSION_MINOR}")
  669. # Find wxWidgets libraries.
  670. WX_FIND_LIBS("${PF}" "${UNV}" "${UCD}" "${DBG}" "${VER}")
  671. if(WX_USE_REL_AND_DBG)
  672. WX_FIND_LIBS("${PF}" "${UNV}" "${UCD}" "d" "${VER}")
  673. endif()
  674. # Settings for requested libs (i.e., include dir, libraries, etc.).
  675. WX_SET_LIBRARIES(wxWidgets_FIND_COMPONENTS "${DBG}")
  676. # Add necessary definitions for unicode builds
  677. if("${UCD}" STREQUAL "u")
  678. list(APPEND wxWidgets_DEFINITIONS UNICODE _UNICODE)
  679. endif()
  680. # Add necessary definitions for debug builds
  681. set(wxWidgets_DEFINITIONS_DEBUG _DEBUG __WXDEBUG__)
  682. endif()
  683. endif()
  684. endif()
  685. if(MINGW AND NOT wxWidgets_FOUND)
  686. # Try unix search mode as well.
  687. set(wxWidgets_FIND_STYLE "unix")
  688. dbg_msg_v("wxWidgets_FIND_STYLE changed to unix")
  689. endif()
  690. endif()
  691. #=====================================================================
  692. # UNIX_FIND_STYLE
  693. #=====================================================================
  694. if(wxWidgets_FIND_STYLE STREQUAL "unix")
  695. #-----------------------------------------------------------------
  696. # UNIX: Helper MACROS
  697. #-----------------------------------------------------------------
  698. #
  699. # Set the default values based on "wx-config --selected-config".
  700. #
  701. macro(WX_CONFIG_SELECT_GET_DEFAULT)
  702. execute_process(
  703. COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
  704. ${wxWidgets_CONFIG_OPTIONS} --selected-config
  705. OUTPUT_VARIABLE _wx_selected_config
  706. RESULT_VARIABLE _wx_result
  707. ERROR_QUIET
  708. )
  709. if(_wx_result EQUAL 0)
  710. foreach(_opt_name debug static unicode universal)
  711. string(TOUPPER ${_opt_name} _upper_opt_name)
  712. if(_wx_selected_config MATCHES "${_opt_name}")
  713. set(wxWidgets_DEFAULT_${_upper_opt_name} ON)
  714. else()
  715. set(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
  716. endif()
  717. endforeach()
  718. else()
  719. foreach(_upper_opt_name DEBUG STATIC UNICODE UNIVERSAL)
  720. set(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
  721. endforeach()
  722. endif()
  723. endmacro()
  724. #
  725. # Query a boolean configuration option to determine if the system
  726. # has both builds available. If so, provide the selection option
  727. # to the user.
  728. #
  729. macro(WX_CONFIG_SELECT_QUERY_BOOL _OPT_NAME _OPT_HELP)
  730. execute_process(
  731. COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
  732. ${wxWidgets_CONFIG_OPTIONS} --${_OPT_NAME}=yes
  733. RESULT_VARIABLE _wx_result_yes
  734. OUTPUT_QUIET
  735. ERROR_QUIET
  736. )
  737. execute_process(
  738. COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
  739. ${wxWidgets_CONFIG_OPTIONS} --${_OPT_NAME}=no
  740. RESULT_VARIABLE _wx_result_no
  741. OUTPUT_QUIET
  742. ERROR_QUIET
  743. )
  744. string(TOUPPER ${_OPT_NAME} _UPPER_OPT_NAME)
  745. if(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
  746. option(wxWidgets_USE_${_UPPER_OPT_NAME}
  747. ${_OPT_HELP} ${wxWidgets_DEFAULT_${_UPPER_OPT_NAME}})
  748. else()
  749. # If option exists (already in cache), force to available one.
  750. if(DEFINED wxWidgets_USE_${_UPPER_OPT_NAME})
  751. if(_wx_result_yes EQUAL 0)
  752. set(wxWidgets_USE_${_UPPER_OPT_NAME} ON CACHE BOOL ${_OPT_HELP} FORCE)
  753. else()
  754. set(wxWidgets_USE_${_UPPER_OPT_NAME} OFF CACHE BOOL ${_OPT_HELP} FORCE)
  755. endif()
  756. endif()
  757. endif()
  758. endmacro()
  759. #
  760. # Set wxWidgets_SELECT_OPTIONS to wx-config options for selecting
  761. # among multiple builds.
  762. #
  763. macro(WX_CONFIG_SELECT_SET_OPTIONS)
  764. set(wxWidgets_SELECT_OPTIONS ${wxWidgets_CONFIG_OPTIONS})
  765. foreach(_opt_name debug static unicode universal)
  766. string(TOUPPER ${_opt_name} _upper_opt_name)
  767. if(DEFINED wxWidgets_USE_${_upper_opt_name})
  768. if(wxWidgets_USE_${_upper_opt_name})
  769. list(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=yes)
  770. else()
  771. list(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=no)
  772. endif()
  773. endif()
  774. endforeach()
  775. endmacro()
  776. #-----------------------------------------------------------------
  777. # UNIX: Start actual work.
  778. #-----------------------------------------------------------------
  779. # Support cross-compiling, only search in the target platform.
  780. #
  781. # Look for wx-config -- this can be set in the environment,
  782. # or try versioned and toolchain-versioned variants of the -config
  783. # executable as well.
  784. set(wx_config_names "wx-config")
  785. foreach(version ${wx_versions})
  786. list(APPEND wx_config_names "wx-config-${version}" "wxgtk3u-${version}-config" "wxgtk2u-${version}-config")
  787. endforeach()
  788. find_program(wxWidgets_CONFIG_EXECUTABLE
  789. NAMES
  790. $ENV{WX_CONFIG}
  791. ${wx_config_names}
  792. DOC "Location of wxWidgets library configuration provider binary (wx-config)."
  793. ONLY_CMAKE_FIND_ROOT_PATH
  794. )
  795. if(wxWidgets_CONFIG_EXECUTABLE)
  796. set(wxWidgets_FOUND TRUE)
  797. # get defaults based on "wx-config --selected-config"
  798. WX_CONFIG_SELECT_GET_DEFAULT()
  799. # for each option: if both builds are available, provide option
  800. WX_CONFIG_SELECT_QUERY_BOOL(debug "Use debug build?")
  801. WX_CONFIG_SELECT_QUERY_BOOL(unicode "Use unicode build?")
  802. WX_CONFIG_SELECT_QUERY_BOOL(universal "Use universal build?")
  803. WX_CONFIG_SELECT_QUERY_BOOL(static "Link libraries statically?")
  804. # process selection to set wxWidgets_SELECT_OPTIONS
  805. WX_CONFIG_SELECT_SET_OPTIONS()
  806. DBG_MSG("wxWidgets_SELECT_OPTIONS=${wxWidgets_SELECT_OPTIONS}")
  807. # run the wx-config program to get cxxflags
  808. execute_process(
  809. COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
  810. ${wxWidgets_SELECT_OPTIONS} --cxxflags
  811. OUTPUT_VARIABLE wxWidgets_CXX_FLAGS
  812. RESULT_VARIABLE RET
  813. ERROR_QUIET
  814. )
  815. if(RET EQUAL 0)
  816. string(STRIP "${wxWidgets_CXX_FLAGS}" wxWidgets_CXX_FLAGS)
  817. separate_arguments(wxWidgets_CXX_FLAGS_LIST NATIVE_COMMAND "${wxWidgets_CXX_FLAGS}")
  818. DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
  819. # parse definitions and include dirs from cxxflags
  820. # drop the -D and -I prefixes
  821. set(wxWidgets_CXX_FLAGS)
  822. foreach(arg IN LISTS wxWidgets_CXX_FLAGS_LIST)
  823. if("${arg}" MATCHES "^-I(.*)$")
  824. # include directory
  825. list(APPEND wxWidgets_INCLUDE_DIRS "${CMAKE_MATCH_1}")
  826. elseif("${arg}" MATCHES "^-D(.*)$")
  827. # compile definition
  828. list(APPEND wxWidgets_DEFINITIONS "${CMAKE_MATCH_1}")
  829. else()
  830. list(APPEND wxWidgets_CXX_FLAGS "${arg}")
  831. endif()
  832. endforeach()
  833. DBG_MSG_V("wxWidgets_DEFINITIONS=${wxWidgets_DEFINITIONS}")
  834. DBG_MSG_V("wxWidgets_INCLUDE_DIRS=${wxWidgets_INCLUDE_DIRS}")
  835. DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
  836. else()
  837. set(wxWidgets_FOUND FALSE)
  838. DBG_MSG_V(
  839. "${wxWidgets_CONFIG_EXECUTABLE} --cxxflags FAILED with RET=${RET}")
  840. endif()
  841. # run the wx-config program to get the libs
  842. # - NOTE: wx-config doesn't verify that the libs requested exist
  843. # it just produces the names. Maybe a TRY_COMPILE would
  844. # be useful here...
  845. unset(_cmp_req)
  846. unset(_cmp_opt)
  847. foreach(_cmp IN LISTS wxWidgets_FIND_COMPONENTS)
  848. if(wxWidgets_FIND_REQUIRED_${_cmp})
  849. list(APPEND _cmp_req "${_cmp}")
  850. else()
  851. list(APPEND _cmp_opt "${_cmp}")
  852. endif()
  853. endforeach()
  854. DBG_MSG_V("wxWidgets required components : ${_cmp_req}")
  855. DBG_MSG_V("wxWidgets optional components : ${_cmp_opt}")
  856. if(DEFINED _cmp_opt)
  857. string(REPLACE ";" "," _cmp_opt "${_cmp_opt}")
  858. set(_cmp_opt "--optional-libs" ${_cmp_opt})
  859. endif()
  860. string(REPLACE ";" "," _cmp_req "${_cmp_req}")
  861. execute_process(
  862. COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
  863. ${wxWidgets_SELECT_OPTIONS} --libs ${_cmp_req} ${_cmp_opt}
  864. OUTPUT_VARIABLE wxWidgets_LIBRARIES
  865. RESULT_VARIABLE RET
  866. ERROR_QUIET
  867. )
  868. if(RET EQUAL 0)
  869. string(STRIP "${wxWidgets_LIBRARIES}" wxWidgets_LIBRARIES)
  870. separate_arguments(wxWidgets_LIBRARIES)
  871. string(REPLACE "-framework;" "-framework "
  872. wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
  873. string(REPLACE "-weak_framework;" "-weak_framework "
  874. wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
  875. string(REPLACE "-arch;" "-arch "
  876. wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
  877. string(REPLACE "-isysroot;" "-isysroot "
  878. wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
  879. # extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES)
  880. string(REGEX MATCHALL "-L[^;]+"
  881. wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARIES}")
  882. string(REGEX REPLACE "-L([^;]+)" "\\1"
  883. wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARY_DIRS}")
  884. DBG_MSG_V("wxWidgets_LIBRARIES=${wxWidgets_LIBRARIES}")
  885. DBG_MSG_V("wxWidgets_LIBRARY_DIRS=${wxWidgets_LIBRARY_DIRS}")
  886. else()
  887. set(wxWidgets_FOUND FALSE)
  888. DBG_MSG("${wxWidgets_CONFIG_EXECUTABLE} --libs ${_cmp_req} ${_cmp_opt} FAILED with RET=${RET}")
  889. endif()
  890. unset(_cmp_req)
  891. unset(_cmp_opt)
  892. endif()
  893. # When using wx-config in MSYS, the include paths are UNIX style paths which may or may
  894. # not work correctly depending on you MSYS/MinGW configuration. CMake expects native
  895. # paths internally.
  896. if(wxWidgets_FOUND AND MSYS)
  897. find_program(_cygpath_exe cygpath ONLY_CMAKE_FIND_ROOT_PATH)
  898. DBG_MSG_V("_cygpath_exe: ${_cygpath_exe}")
  899. if(_cygpath_exe)
  900. set(_tmp_path "")
  901. foreach(_path ${wxWidgets_INCLUDE_DIRS})
  902. execute_process(
  903. COMMAND cygpath -w ${_path}
  904. OUTPUT_VARIABLE _native_path
  905. RESULT_VARIABLE _retv
  906. OUTPUT_STRIP_TRAILING_WHITESPACE
  907. ERROR_QUIET
  908. )
  909. if(_retv EQUAL 0)
  910. file(TO_CMAKE_PATH ${_native_path} _native_path)
  911. DBG_MSG_V("Path ${_path} converted to ${_native_path}")
  912. string(APPEND _tmp_path " ${_native_path}")
  913. endif()
  914. endforeach()
  915. DBG_MSG("Setting wxWidgets_INCLUDE_DIRS = ${_tmp_path}")
  916. set(wxWidgets_INCLUDE_DIRS ${_tmp_path})
  917. separate_arguments(wxWidgets_INCLUDE_DIRS)
  918. list(REMOVE_ITEM wxWidgets_INCLUDE_DIRS "")
  919. set(_tmp_path "")
  920. foreach(_path ${wxWidgets_LIBRARY_DIRS})
  921. execute_process(
  922. COMMAND cygpath -w ${_path}
  923. OUTPUT_VARIABLE _native_path
  924. RESULT_VARIABLE _retv
  925. OUTPUT_STRIP_TRAILING_WHITESPACE
  926. ERROR_QUIET
  927. )
  928. if(_retv EQUAL 0)
  929. file(TO_CMAKE_PATH ${_native_path} _native_path)
  930. DBG_MSG_V("Path ${_path} converted to ${_native_path}")
  931. string(APPEND _tmp_path " ${_native_path}")
  932. endif()
  933. endforeach()
  934. DBG_MSG("Setting wxWidgets_LIBRARY_DIRS = ${_tmp_path}")
  935. set(wxWidgets_LIBRARY_DIRS ${_tmp_path})
  936. separate_arguments(wxWidgets_LIBRARY_DIRS)
  937. list(REMOVE_ITEM wxWidgets_LIBRARY_DIRS "")
  938. endif()
  939. unset(_cygpath_exe CACHE)
  940. endif()
  941. # Check that all libraries are present, as wx-config does not check it
  942. set(_wx_lib_missing "")
  943. foreach(_wx_lib_ ${wxWidgets_LIBRARIES})
  944. if("${_wx_lib_}" MATCHES "^-l(.*)")
  945. set(_wx_lib_name "${CMAKE_MATCH_1}")
  946. if(_wx_lib_name STREQUAL "atomic")
  947. continue()
  948. endif()
  949. unset(_wx_lib_found CACHE)
  950. find_library(_wx_lib_found NAMES ${_wx_lib_name} HINTS ${wxWidgets_LIBRARY_DIRS})
  951. if(_wx_lib_found STREQUAL _wx_lib_found-NOTFOUND)
  952. list(APPEND _wx_lib_missing ${_wx_lib_name})
  953. endif()
  954. unset(_wx_lib_found CACHE)
  955. endif()
  956. endforeach()
  957. if (_wx_lib_missing)
  958. string(REPLACE ";" " " _wx_lib_missing "${_wx_lib_missing}")
  959. DBG_MSG_V("wxWidgets not found due to following missing libraries: ${_wx_lib_missing}")
  960. set(wxWidgets_FOUND FALSE)
  961. unset(wxWidgets_LIBRARIES)
  962. endif()
  963. unset(_wx_lib_missing)
  964. endif()
  965. # Check if a specific version was requested by find_package().
  966. if(wxWidgets_FOUND)
  967. wx_extract_version()
  968. endif()
  969. file(TO_CMAKE_PATH "${wxWidgets_INCLUDE_DIRS}" wxWidgets_INCLUDE_DIRS)
  970. file(TO_CMAKE_PATH "${wxWidgets_LIBRARY_DIRS}" wxWidgets_LIBRARY_DIRS)
  971. # Debug output:
  972. DBG_MSG("wxWidgets_FOUND : ${wxWidgets_FOUND}")
  973. DBG_MSG("wxWidgets_INCLUDE_DIRS : ${wxWidgets_INCLUDE_DIRS}")
  974. DBG_MSG("wxWidgets_LIBRARY_DIRS : ${wxWidgets_LIBRARY_DIRS}")
  975. DBG_MSG("wxWidgets_LIBRARIES : ${wxWidgets_LIBRARIES}")
  976. DBG_MSG("wxWidgets_CXX_FLAGS : ${wxWidgets_CXX_FLAGS}")
  977. #=====================================================================
  978. #=====================================================================
  979. include(FindPackageHandleStandardArgs)
  980. # FIXME: set wxWidgets_<comp>_FOUND for wx-config branch
  981. # and use HANDLE_COMPONENTS on Unix too
  982. if(wxWidgets_FIND_STYLE STREQUAL "win32")
  983. set(wxWidgets_HANDLE_COMPONENTS "HANDLE_COMPONENTS")
  984. endif()
  985. find_package_handle_standard_args(wxWidgets
  986. REQUIRED_VARS wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS
  987. VERSION_VAR wxWidgets_VERSION
  988. ${wxWidgets_HANDLE_COMPONENTS}
  989. )
  990. unset(wxWidgets_HANDLE_COMPONENTS)
  991. if(wxWidgets_FOUND AND NOT TARGET wxWidgets::wxWidgets)
  992. add_library(wxWidgets::wxWidgets INTERFACE IMPORTED)
  993. target_link_libraries(wxWidgets::wxWidgets INTERFACE ${wxWidgets_LIBRARIES})
  994. target_link_directories(wxWidgets::wxWidgets INTERFACE ${wxWidgets_LIBRARY_DIRS})
  995. target_include_directories(wxWidgets::wxWidgets INTERFACE ${wxWidgets_INCLUDE_DIRS})
  996. target_compile_options(wxWidgets::wxWidgets INTERFACE ${wxWidgets_CXX_FLAGS})
  997. target_compile_definitions(wxWidgets::wxWidgets INTERFACE ${wxWidgets_DEFINITIONS})
  998. # FIXME: Add "$<$<CONFIG:Debug>:${wxWidgets_DEFINITIONS_DEBUG}>"
  999. # if the debug library variant is available.
  1000. endif()
  1001. #=====================================================================
  1002. # Macros for use in wxWidgets apps.
  1003. # - This module will not fail to find wxWidgets based on the code
  1004. # below. Hence, it's required to check for validity of:
  1005. #
  1006. # wxWidgets_wxrc_EXECUTABLE
  1007. #=====================================================================
  1008. # Resource file compiler.
  1009. find_program(wxWidgets_wxrc_EXECUTABLE
  1010. NAMES $ENV{WXRC_CMD} wxrc
  1011. PATHS ${wxWidgets_ROOT_DIR}/utils/wxrc/vc_msw
  1012. DOC "Location of wxWidgets resource file compiler binary (wxrc)"
  1013. )
  1014. #
  1015. # WX_SPLIT_ARGUMENTS_ON(<keyword> <left> <right> <arg1> <arg2> ...)
  1016. #
  1017. # Sets <left> and <right> to contain arguments to the left and right,
  1018. # respectively, of <keyword>.
  1019. #
  1020. # Example usage:
  1021. # function(WXWIDGETS_ADD_RESOURCES outfiles)
  1022. # WX_SPLIT_ARGUMENTS_ON(OPTIONS wxrc_files wxrc_options ${ARGN})
  1023. # ...
  1024. # endfunction()
  1025. #
  1026. # WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o file.C)
  1027. #
  1028. # NOTE: This is a generic piece of code that should be renamed to
  1029. # SPLIT_ARGUMENTS_ON and put in a file serving the same purpose as
  1030. # FindPackageHandleStandardArgs.cmake. At the time of this writing
  1031. # FindQt4.cmake has a qt4_extract_options(), which I basically copied
  1032. # here a bit more generalized. So, there are already two find modules
  1033. # using this approach.
  1034. #
  1035. function(WX_SPLIT_ARGUMENTS_ON _keyword _leftvar _rightvar)
  1036. # FIXME: Document that the input variables will be cleared.
  1037. #list(APPEND ${_leftvar} "")
  1038. #list(APPEND ${_rightvar} "")
  1039. set(${_leftvar} "")
  1040. set(${_rightvar} "")
  1041. set(_doing_right FALSE)
  1042. foreach(element ${ARGN})
  1043. if("${element}" STREQUAL "${_keyword}")
  1044. set(_doing_right TRUE)
  1045. else()
  1046. if(_doing_right)
  1047. list(APPEND ${_rightvar} "${element}")
  1048. else()
  1049. list(APPEND ${_leftvar} "${element}")
  1050. endif()
  1051. endif()
  1052. endforeach()
  1053. set(${_leftvar} ${${_leftvar}} PARENT_SCOPE)
  1054. set(${_rightvar} ${${_rightvar}} PARENT_SCOPE)
  1055. endfunction()
  1056. #
  1057. # WX_GET_DEPENDENCIES_FROM_XML(
  1058. # <depends>
  1059. # <match_pattern>
  1060. # <clean_pattern>
  1061. # <xml_contents>
  1062. # <depends_path>
  1063. # )
  1064. #
  1065. # FIXME: Add documentation here...
  1066. #
  1067. function(WX_GET_DEPENDENCIES_FROM_XML
  1068. _depends
  1069. _match_patt
  1070. _clean_patt
  1071. _xml_contents
  1072. _depends_path
  1073. )
  1074. string(REGEX MATCHALL
  1075. ${_match_patt}
  1076. dep_file_list
  1077. "${${_xml_contents}}"
  1078. )
  1079. foreach(dep_file ${dep_file_list})
  1080. string(REGEX REPLACE ${_clean_patt} "" dep_file "${dep_file}")
  1081. # make the file have an absolute path
  1082. if(NOT IS_ABSOLUTE "${dep_file}")
  1083. set(dep_file "${${_depends_path}}/${dep_file}")
  1084. endif()
  1085. # append file to dependency list
  1086. list(APPEND ${_depends} "${dep_file}")
  1087. endforeach()
  1088. set(${_depends} ${${_depends}} PARENT_SCOPE)
  1089. endfunction()
  1090. #
  1091. # WXWIDGETS_ADD_RESOURCES(<sources> <xrc_files>
  1092. # OPTIONS <options> [NO_CPP_CODE])
  1093. #
  1094. # Adds a custom command for resource file compilation of the
  1095. # <xrc_files> and appends the output files to <sources>.
  1096. #
  1097. # Example usages:
  1098. # WXWIDGETS_ADD_RESOURCES(sources xrc/main_frame.xrc)
  1099. # WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o altname.cxx)
  1100. #
  1101. function(WXWIDGETS_ADD_RESOURCES _outfiles)
  1102. WX_SPLIT_ARGUMENTS_ON(OPTIONS rc_file_list rc_options ${ARGN})
  1103. # Parse files for dependencies.
  1104. set(rc_file_list_abs "")
  1105. set(rc_depends "")
  1106. foreach(rc_file ${rc_file_list})
  1107. get_filename_component(depends_path ${rc_file} PATH)
  1108. get_filename_component(rc_file_abs ${rc_file} ABSOLUTE)
  1109. list(APPEND rc_file_list_abs "${rc_file_abs}")
  1110. # All files have absolute paths or paths relative to the location
  1111. # of the rc file.
  1112. file(READ "${rc_file_abs}" rc_file_contents)
  1113. # get bitmap/bitmap2 files
  1114. WX_GET_DEPENDENCIES_FROM_XML(
  1115. rc_depends
  1116. "<bitmap[^<]+"
  1117. "^<bitmap[^>]*>"
  1118. rc_file_contents
  1119. depends_path
  1120. )
  1121. # get url files
  1122. WX_GET_DEPENDENCIES_FROM_XML(
  1123. rc_depends
  1124. "<url[^<]+"
  1125. "^<url[^>]*>"
  1126. rc_file_contents
  1127. depends_path
  1128. )
  1129. # get wxIcon files
  1130. WX_GET_DEPENDENCIES_FROM_XML(
  1131. rc_depends
  1132. "<object[^>]*class=\"wxIcon\"[^<]+"
  1133. "^<object[^>]*>"
  1134. rc_file_contents
  1135. depends_path
  1136. )
  1137. endforeach()
  1138. #
  1139. # Parse options.
  1140. #
  1141. # If NO_CPP_CODE option specified, then produce .xrs file rather
  1142. # than a .cpp file (i.e., don't add the default --cpp-code option).
  1143. list(FIND rc_options NO_CPP_CODE index)
  1144. if(index EQUAL -1)
  1145. list(APPEND rc_options --cpp-code)
  1146. # wxrc's default output filename for cpp code.
  1147. set(outfile resource.cpp)
  1148. else()
  1149. list(REMOVE_AT rc_options ${index})
  1150. # wxrc's default output filename for xrs file.
  1151. set(outfile resource.xrs)
  1152. endif()
  1153. # Get output name for use in ADD_CUSTOM_COMMAND.
  1154. # - short option scanning
  1155. list(FIND rc_options -o index)
  1156. if(NOT index EQUAL -1)
  1157. math(EXPR filename_index "${index} + 1")
  1158. list(GET rc_options ${filename_index} outfile)
  1159. #list(REMOVE_AT rc_options ${index} ${filename_index})
  1160. endif()
  1161. # - long option scanning
  1162. string(REGEX MATCH "--output=[^;]*" outfile_opt "${rc_options}")
  1163. if(outfile_opt)
  1164. string(REPLACE "--output=" "" outfile "${outfile_opt}")
  1165. endif()
  1166. #string(REGEX REPLACE "--output=[^;]*;?" "" rc_options "${rc_options}")
  1167. #string(REGEX REPLACE ";$" "" rc_options "${rc_options}")
  1168. if(NOT IS_ABSOLUTE "${outfile}")
  1169. set(outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
  1170. endif()
  1171. add_custom_command(
  1172. OUTPUT "${outfile}"
  1173. COMMAND ${wxWidgets_wxrc_EXECUTABLE} ${rc_options} ${rc_file_list_abs}
  1174. DEPENDS ${rc_file_list_abs} ${rc_depends}
  1175. )
  1176. # Add generated header to output file list.
  1177. list(FIND rc_options -e short_index)
  1178. list(FIND rc_options --extra-cpp-code long_index)
  1179. if(NOT short_index EQUAL -1 OR NOT long_index EQUAL -1)
  1180. get_filename_component(outfile_ext ${outfile} EXT)
  1181. string(REPLACE "${outfile_ext}" ".h" outfile_header "${outfile}")
  1182. list(APPEND ${_outfiles} "${outfile_header}")
  1183. set_source_files_properties(
  1184. "${outfile_header}" PROPERTIES GENERATED TRUE
  1185. )
  1186. endif()
  1187. # Add generated file to output file list.
  1188. list(APPEND ${_outfiles} "${outfile}")
  1189. set(${_outfiles} ${${_outfiles}} PARENT_SCOPE)
  1190. endfunction()