FindwxWidgets.cmake 43 KB

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