FindwxWidgets.cmake 40 KB

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