FindwxWidgets.cmake 38 KB

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