FindwxWidgets.cmake 38 KB

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