FindwxWidgets.cmake 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  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 distributed 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})
  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. FIND_LIBRARY(WX_${LIB}${_DBG}
  288. NAMES
  289. wxmsw${_UNV}29${_UCD}${_DBG}_${LIB}
  290. wxmsw${_UNV}28${_UCD}${_DBG}_${LIB}
  291. wxmsw${_UNV}27${_UCD}${_DBG}_${LIB}
  292. wxmsw${_UNV}26${_UCD}${_DBG}_${LIB}
  293. wxmsw${_UNV}25${_UCD}${_DBG}_${LIB}
  294. PATHS ${WX_LIB_DIR}
  295. NO_DEFAULT_PATH
  296. )
  297. MARK_AS_ADVANCED(WX_${LIB}${_DBG})
  298. ENDFOREACH(LIB)
  299. ENDMACRO(WX_FIND_LIBS)
  300. #
  301. # Clear all library paths, so that FIND_LIBRARY refinds them.
  302. #
  303. # Clear a lib, reset its found flag, and mark as advanced.
  304. MACRO(WX_CLEAR_LIB _LIB)
  305. SET(${_LIB} "${_LIB}-NOTFOUND" CACHE FILEPATH "Cleared." FORCE)
  306. SET(${_LIB}_FOUND FALSE)
  307. MARK_AS_ADVANCED(${_LIB})
  308. ENDMACRO(WX_CLEAR_LIB)
  309. # Clear all debug or release library paths (arguments are "d" or "").
  310. MACRO(WX_CLEAR_ALL_LIBS _DBG)
  311. # Clear wxWidgets common libraries.
  312. FOREACH(LIB ${wxWidgets_COMMON_LIBRARIES})
  313. WX_CLEAR_LIB(WX_${LIB}${_DBG})
  314. ENDFOREACH(LIB)
  315. # Clear wxWidgets multilib base libraries.
  316. WX_CLEAR_LIB(WX_base${_DBG})
  317. FOREACH(LIB net odbc xml)
  318. WX_CLEAR_LIB(WX_${LIB}${_DBG})
  319. ENDFOREACH(LIB)
  320. # Clear wxWidgets monolithic library.
  321. WX_CLEAR_LIB(WX_mono${_DBG})
  322. # Clear wxWidgets multilib libraries.
  323. FOREACH(LIB core adv aui html media xrc dbgrid gl qa richtext)
  324. WX_CLEAR_LIB(WX_${LIB}${_DBG})
  325. ENDFOREACH(LIB)
  326. ENDMACRO(WX_CLEAR_ALL_LIBS)
  327. # Clear all wxWidgets debug libraries.
  328. MACRO(WX_CLEAR_ALL_DBG_LIBS)
  329. WX_CLEAR_ALL_LIBS("d")
  330. ENDMACRO(WX_CLEAR_ALL_DBG_LIBS)
  331. # Clear all wxWidgets release libraries.
  332. MACRO(WX_CLEAR_ALL_REL_LIBS)
  333. WX_CLEAR_ALL_LIBS("")
  334. ENDMACRO(WX_CLEAR_ALL_REL_LIBS)
  335. #
  336. # Set the wxWidgets_LIBRARIES variable.
  337. # Also, Sets output variable wxWidgets_FOUND to FALSE if it fails.
  338. #
  339. MACRO(WX_SET_LIBRARIES _LIBS _DBG)
  340. DBG_MSG_V("Looking for ${${_LIBS}}")
  341. IF(WX_USE_REL_AND_DBG)
  342. FOREACH(LIB ${${_LIBS}})
  343. DBG_MSG_V("Searching for ${LIB} and ${LIB}d")
  344. DBG_MSG_V("WX_${LIB} : ${WX_${LIB}}")
  345. DBG_MSG_V("WX_${LIB}d : ${WX_${LIB}d}")
  346. IF(WX_${LIB} AND WX_${LIB}d)
  347. DBG_MSG_V("Found ${LIB} and ${LIB}d")
  348. LIST(APPEND wxWidgets_LIBRARIES
  349. debug ${WX_${LIB}d} optimized ${WX_${LIB}}
  350. )
  351. ELSE(WX_${LIB} AND WX_${LIB}d)
  352. DBG_MSG_V("- not found due to missing WX_${LIB}=${WX_${LIB}} or WX_${LIB}d=${WX_${LIB}d}")
  353. SET(wxWidgets_FOUND FALSE)
  354. ENDIF(WX_${LIB} AND WX_${LIB}d)
  355. ENDFOREACH(LIB)
  356. ELSE(WX_USE_REL_AND_DBG)
  357. FOREACH(LIB ${${_LIBS}})
  358. DBG_MSG_V("Searching for ${LIB}${_DBG}")
  359. DBG_MSG_V("WX_${LIB}${_DBG} : ${WX_${LIB}${_DBG}}")
  360. IF(WX_${LIB}${_DBG})
  361. DBG_MSG_V("Found ${LIB}${_DBG}")
  362. LIST(APPEND wxWidgets_LIBRARIES ${WX_${LIB}${_DBG}})
  363. ELSE(WX_${LIB}${_DBG})
  364. DBG_MSG_V(
  365. "- not found due to missing WX_${LIB}${_DBG}=${WX_${LIB}${_DBG}}")
  366. SET(wxWidgets_FOUND FALSE)
  367. ENDIF(WX_${LIB}${_DBG})
  368. ENDFOREACH(LIB)
  369. ENDIF(WX_USE_REL_AND_DBG)
  370. DBG_MSG_V("OpenGL")
  371. LIST(FIND ${_LIBS} gl WX_USE_GL)
  372. IF(NOT WX_USE_GL EQUAL -1)
  373. DBG_MSG_V("- is required.")
  374. LIST(APPEND wxWidgets_LIBRARIES opengl32 glu32)
  375. ENDIF(NOT WX_USE_GL EQUAL -1)
  376. LIST(APPEND wxWidgets_LIBRARIES winmm comctl32 rpcrt4 wsock32)
  377. ENDMACRO(WX_SET_LIBRARIES)
  378. #-------------------------------------------------------------------
  379. # WIN32: Start actual work.
  380. #-------------------------------------------------------------------
  381. # Look for an installation tree.
  382. FIND_PATH(wxWidgets_ROOT_DIR
  383. NAMES include/wx/wx.h
  384. PATHS
  385. $ENV{wxWidgets_ROOT_DIR}
  386. $ENV{WXWIN}
  387. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\wxWidgets_is1;Inno Setup: App Path]" # WX 2.6.x
  388. C:/
  389. D:/
  390. $ENV{ProgramFiles}
  391. PATH_SUFFIXES
  392. wxWidgets-2.9.4
  393. wxWidgets-2.9.3
  394. wxWidgets-2.9.2
  395. wxWidgets-2.9.1
  396. wxWidgets-2.9.0
  397. wxWidgets-2.8.9
  398. wxWidgets-2.8.8
  399. wxWidgets-2.8.7
  400. wxWidgets-2.8.6
  401. wxWidgets-2.8.5
  402. wxWidgets-2.8.4
  403. wxWidgets-2.8.3
  404. wxWidgets-2.8.2
  405. wxWidgets-2.8.1
  406. wxWidgets-2.8.0
  407. wxWidgets-2.7.4
  408. wxWidgets-2.7.3
  409. wxWidgets-2.7.2
  410. wxWidgets-2.7.1
  411. wxWidgets-2.7.0
  412. wxWidgets-2.7.0-1
  413. wxWidgets-2.6.4
  414. wxWidgets-2.6.3
  415. wxWidgets-2.6.2
  416. wxWidgets-2.6.1
  417. wxWidgets-2.5.4
  418. wxWidgets-2.5.3
  419. wxWidgets-2.5.2
  420. wxWidgets-2.5.1
  421. wxWidgets
  422. DOC "wxWidgets base/installation directory?"
  423. )
  424. # If wxWidgets_ROOT_DIR changed, clear lib dir.
  425. IF(NOT WX_ROOT_DIR STREQUAL wxWidgets_ROOT_DIR)
  426. SET(WX_ROOT_DIR ${wxWidgets_ROOT_DIR}
  427. CACHE INTERNAL "wxWidgets_ROOT_DIR")
  428. SET(wxWidgets_LIB_DIR "wxWidgets_LIB_DIR-NOTFOUND"
  429. CACHE PATH "Cleared." FORCE)
  430. ENDIF(NOT WX_ROOT_DIR STREQUAL wxWidgets_ROOT_DIR)
  431. IF(WX_ROOT_DIR)
  432. # Select one default tree inside the already determined wx tree.
  433. # Prefer static/shared order usually consistent with build
  434. # settings.
  435. IF(MINGW)
  436. SET(WX_LIB_DIR_PREFIX gcc)
  437. ELSE(MINGW)
  438. SET(WX_LIB_DIR_PREFIX vc)
  439. ENDIF(MINGW)
  440. IF(BUILD_SHARED_LIBS)
  441. FIND_PATH(wxWidgets_LIB_DIR
  442. NAMES
  443. msw/wx/setup.h
  444. mswd/wx/setup.h
  445. mswu/wx/setup.h
  446. mswud/wx/setup.h
  447. mswuniv/wx/setup.h
  448. mswunivd/wx/setup.h
  449. mswunivu/wx/setup.h
  450. mswunivud/wx/setup.h
  451. PATHS
  452. ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_dll # prefer shared
  453. ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_lib
  454. DOC "Path to wxWidgets libraries?"
  455. NO_DEFAULT_PATH
  456. )
  457. ELSE(BUILD_SHARED_LIBS)
  458. FIND_PATH(wxWidgets_LIB_DIR
  459. NAMES
  460. msw/wx/setup.h
  461. mswd/wx/setup.h
  462. mswu/wx/setup.h
  463. mswud/wx/setup.h
  464. mswuniv/wx/setup.h
  465. mswunivd/wx/setup.h
  466. mswunivu/wx/setup.h
  467. mswunivud/wx/setup.h
  468. PATHS
  469. ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_lib # prefer static
  470. ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_dll
  471. DOC "Path to wxWidgets libraries?"
  472. NO_DEFAULT_PATH
  473. )
  474. ENDIF(BUILD_SHARED_LIBS)
  475. # If wxWidgets_LIB_DIR changed, clear all libraries.
  476. IF(NOT WX_LIB_DIR STREQUAL wxWidgets_LIB_DIR)
  477. SET(WX_LIB_DIR ${wxWidgets_LIB_DIR} CACHE INTERNAL "wxWidgets_LIB_DIR")
  478. WX_CLEAR_ALL_DBG_LIBS()
  479. WX_CLEAR_ALL_REL_LIBS()
  480. ENDIF(NOT WX_LIB_DIR STREQUAL wxWidgets_LIB_DIR)
  481. IF(WX_LIB_DIR)
  482. # If building shared libs, define WXUSINGDLL to use dllimport.
  483. IF(WX_LIB_DIR MATCHES ".*[dD][lL][lL].*")
  484. SET(wxWidgets_DEFINITIONS WXUSINGDLL)
  485. DBG_MSG_V("detected SHARED/DLL tree WX_LIB_DIR=${WX_LIB_DIR}")
  486. ENDIF(WX_LIB_DIR MATCHES ".*[dD][lL][lL].*")
  487. # Search for available configuration types.
  488. FOREACH(CFG mswunivud mswunivd mswud mswd mswunivu mswuniv mswu msw)
  489. SET(WX_${CFG}_FOUND FALSE)
  490. IF(EXISTS ${WX_LIB_DIR}/${CFG})
  491. LIST(APPEND WX_CONFIGURATION_LIST ${CFG})
  492. SET(WX_${CFG}_FOUND TRUE)
  493. SET(WX_CONFIGURATION ${CFG})
  494. ENDIF(EXISTS ${WX_LIB_DIR}/${CFG})
  495. ENDFOREACH(CFG)
  496. DBG_MSG_V("WX_CONFIGURATION_LIST=${WX_CONFIGURATION_LIST}")
  497. IF(WX_CONFIGURATION)
  498. SET(wxWidgets_FOUND TRUE)
  499. # If the selected configuration wasn't found force the default
  500. # one. Otherwise, use it but still force a refresh for
  501. # updating the doc string with the current list of available
  502. # configurations.
  503. IF(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
  504. SET(wxWidgets_CONFIGURATION ${WX_CONFIGURATION} CACHE STRING
  505. "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
  506. ELSE(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
  507. SET(wxWidgets_CONFIGURATION ${wxWidgets_CONFIGURATION} CACHE STRING
  508. "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
  509. ENDIF(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
  510. # If release config selected, and both release/debug exist.
  511. IF(WX_${wxWidgets_CONFIGURATION}d_FOUND)
  512. OPTION(wxWidgets_USE_REL_AND_DBG
  513. "Use release and debug configurations?" TRUE)
  514. SET(WX_USE_REL_AND_DBG ${wxWidgets_USE_REL_AND_DBG})
  515. ELSE(WX_${wxWidgets_CONFIGURATION}d_FOUND)
  516. # If the option exists (already in cache), force it false.
  517. IF(wxWidgets_USE_REL_AND_DBG)
  518. SET(wxWidgets_USE_REL_AND_DBG FALSE CACHE BOOL
  519. "No ${wxWidgets_CONFIGURATION}d found." FORCE)
  520. ENDIF(wxWidgets_USE_REL_AND_DBG)
  521. SET(WX_USE_REL_AND_DBG FALSE)
  522. ENDIF(WX_${wxWidgets_CONFIGURATION}d_FOUND)
  523. # Get configuration parameters from the name.
  524. WX_GET_NAME_COMPONENTS(${wxWidgets_CONFIGURATION} UNV UCD DBG)
  525. # Set wxWidgets main include directory.
  526. IF(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
  527. SET(wxWidgets_INCLUDE_DIRS ${WX_ROOT_DIR}/include)
  528. ELSE(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
  529. DBG_MSG("wxWidgets_FOUND FALSE because WX_ROOT_DIR=${WX_ROOT_DIR} has no ${WX_ROOT_DIR}/include/wx/wx.h")
  530. SET(wxWidgets_FOUND FALSE)
  531. ENDIF(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
  532. # Set wxWidgets lib setup include directory.
  533. IF(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
  534. LIST(APPEND wxWidgets_INCLUDE_DIRS
  535. ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION})
  536. ELSE(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
  537. DBG_MSG("WXWIDGET_FOUND FALSE because ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h does not exists.")
  538. SET(wxWidgets_FOUND FALSE)
  539. ENDIF(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
  540. # Find wxWidgets libraries.
  541. WX_FIND_LIBS("${UNV}" "${UCD}" "${DBG}")
  542. IF(WX_USE_REL_AND_DBG)
  543. WX_FIND_LIBS("${UNV}" "${UCD}" "d")
  544. ENDIF(WX_USE_REL_AND_DBG)
  545. # Settings for requested libs (i.e., include dir, libraries, etc.).
  546. WX_SET_LIBRARIES(wxWidgets_FIND_COMPONENTS "${DBG}")
  547. # Add necessary definitions for unicode builds
  548. IF("${UCD}" STREQUAL "u")
  549. LIST(APPEND wxWidgets_DEFINITIONS UNICODE _UNICODE)
  550. ENDIF("${UCD}" STREQUAL "u")
  551. # Add necessary definitions for debug builds
  552. SET(wxWidgets_DEFINITIONS_DEBUG _DEBUG __WXDEBUG__)
  553. ENDIF(WX_CONFIGURATION)
  554. ENDIF(WX_LIB_DIR)
  555. ENDIF(WX_ROOT_DIR)
  556. #=====================================================================
  557. # UNIX_FIND_STYLE
  558. #=====================================================================
  559. ELSE(wxWidgets_FIND_STYLE STREQUAL "win32")
  560. IF(wxWidgets_FIND_STYLE STREQUAL "unix")
  561. #-----------------------------------------------------------------
  562. # UNIX: Helper MACROS
  563. #-----------------------------------------------------------------
  564. #
  565. # Set the default values based on "wx-config --selected-config".
  566. #
  567. MACRO(WX_CONFIG_SELECT_GET_DEFAULT)
  568. EXECUTE_PROCESS(
  569. COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --selected-config
  570. OUTPUT_VARIABLE _wx_selected_config
  571. RESULT_VARIABLE _wx_result
  572. ERROR_QUIET
  573. )
  574. IF(_wx_result EQUAL 0)
  575. FOREACH(_opt_name debug static unicode universal)
  576. STRING(TOUPPER ${_opt_name} _upper_opt_name)
  577. IF(_wx_selected_config MATCHES ".*${_opt_name}.*")
  578. SET(wxWidgets_DEFAULT_${_upper_opt_name} ON)
  579. ELSE(_wx_selected_config MATCHES ".*${_opt_name}.*")
  580. SET(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
  581. ENDIF(_wx_selected_config MATCHES ".*${_opt_name}.*")
  582. ENDFOREACH(_opt_name)
  583. ELSE(_wx_result EQUAL 0)
  584. FOREACH(_upper_opt_name DEBUG STATIC UNICODE UNIVERSAL)
  585. SET(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
  586. ENDFOREACH(_upper_opt_name)
  587. ENDIF(_wx_result EQUAL 0)
  588. ENDMACRO(WX_CONFIG_SELECT_GET_DEFAULT)
  589. #
  590. # Query a boolean configuration option to determine if the system
  591. # has both builds available. If so, provide the selection option
  592. # to the user.
  593. #
  594. MACRO(WX_CONFIG_SELECT_QUERY_BOOL _OPT_NAME _OPT_HELP)
  595. EXECUTE_PROCESS(
  596. COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --${_OPT_NAME}=yes
  597. RESULT_VARIABLE _wx_result_yes
  598. OUTPUT_QUIET
  599. ERROR_QUIET
  600. )
  601. EXECUTE_PROCESS(
  602. COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --${_OPT_NAME}=no
  603. RESULT_VARIABLE _wx_result_no
  604. OUTPUT_QUIET
  605. ERROR_QUIET
  606. )
  607. STRING(TOUPPER ${_OPT_NAME} _UPPER_OPT_NAME)
  608. IF(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
  609. OPTION(wxWidgets_USE_${_UPPER_OPT_NAME}
  610. ${_OPT_HELP} ${wxWidgets_DEFAULT_${_UPPER_OPT_NAME}})
  611. ELSE(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
  612. # If option exists (already in cache), force to available one.
  613. IF(DEFINED wxWidgets_USE_${_UPPER_OPT_NAME})
  614. IF(_wx_result_yes EQUAL 0)
  615. SET(wxWidgets_USE_${_UPPER_OPT_NAME} ON CACHE BOOL ${_OPT_HELP} FORCE)
  616. ELSE(_wx_result_yes EQUAL 0)
  617. SET(wxWidgets_USE_${_UPPER_OPT_NAME} OFF CACHE BOOL ${_OPT_HELP} FORCE)
  618. ENDIF(_wx_result_yes EQUAL 0)
  619. ENDIF(DEFINED wxWidgets_USE_${_UPPER_OPT_NAME})
  620. ENDIF(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
  621. ENDMACRO(WX_CONFIG_SELECT_QUERY_BOOL)
  622. #
  623. # Set wxWidgets_SELECT_OPTIONS to wx-config options for selecting
  624. # among multiple builds.
  625. #
  626. MACRO(WX_CONFIG_SELECT_SET_OPTIONS)
  627. SET(wxWidgets_SELECT_OPTIONS "")
  628. FOREACH(_opt_name debug static unicode universal)
  629. STRING(TOUPPER ${_opt_name} _upper_opt_name)
  630. IF(DEFINED wxWidgets_USE_${_upper_opt_name})
  631. IF(wxWidgets_USE_${_upper_opt_name})
  632. LIST(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=yes)
  633. ELSE(wxWidgets_USE_${_upper_opt_name})
  634. LIST(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=no)
  635. ENDIF(wxWidgets_USE_${_upper_opt_name})
  636. ENDIF(DEFINED wxWidgets_USE_${_upper_opt_name})
  637. ENDFOREACH(_opt_name)
  638. ENDMACRO(WX_CONFIG_SELECT_SET_OPTIONS)
  639. #-----------------------------------------------------------------
  640. # UNIX: Start actual work.
  641. #-----------------------------------------------------------------
  642. # Support cross-compiling, only search in the target platform.
  643. FIND_PROGRAM(wxWidgets_CONFIG_EXECUTABLE wx-config
  644. ONLY_CMAKE_FIND_ROOT_PATH
  645. )
  646. IF(wxWidgets_CONFIG_EXECUTABLE)
  647. SET(wxWidgets_FOUND TRUE)
  648. # get defaults based on "wx-config --selected-config"
  649. WX_CONFIG_SELECT_GET_DEFAULT()
  650. # for each option: if both builds are available, provide option
  651. WX_CONFIG_SELECT_QUERY_BOOL(debug "Use debug build?")
  652. WX_CONFIG_SELECT_QUERY_BOOL(unicode "Use unicode build?")
  653. WX_CONFIG_SELECT_QUERY_BOOL(universal "Use universal build?")
  654. WX_CONFIG_SELECT_QUERY_BOOL(static "Link libraries statically?")
  655. # process selection to set wxWidgets_SELECT_OPTIONS
  656. WX_CONFIG_SELECT_SET_OPTIONS()
  657. DBG_MSG("wxWidgets_SELECT_OPTIONS=${wxWidgets_SELECT_OPTIONS}")
  658. # run the wx-config program to get cxxflags
  659. EXECUTE_PROCESS(
  660. COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
  661. ${wxWidgets_SELECT_OPTIONS} --cxxflags
  662. OUTPUT_VARIABLE wxWidgets_CXX_FLAGS
  663. RESULT_VARIABLE RET
  664. ERROR_QUIET
  665. )
  666. IF(RET EQUAL 0)
  667. STRING(STRIP "${wxWidgets_CXX_FLAGS}" wxWidgets_CXX_FLAGS)
  668. SEPARATE_ARGUMENTS(wxWidgets_CXX_FLAGS)
  669. DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
  670. # parse definitions from cxxflags;
  671. # drop -D* from CXXFLAGS and the -D prefix
  672. STRING(REGEX MATCHALL "-D[^;]+"
  673. wxWidgets_DEFINITIONS "${wxWidgets_CXX_FLAGS}")
  674. STRING(REGEX REPLACE "-D[^;]+(;|$)" ""
  675. wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
  676. STRING(REGEX REPLACE ";$" ""
  677. wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
  678. STRING(REPLACE "-D" ""
  679. wxWidgets_DEFINITIONS "${wxWidgets_DEFINITIONS}")
  680. # parse include dirs from cxxflags; drop -I prefix
  681. STRING(REGEX MATCHALL "-I[^;]+"
  682. wxWidgets_INCLUDE_DIRS "${wxWidgets_CXX_FLAGS}")
  683. STRING(REGEX REPLACE "-I[^;]+;" ""
  684. wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
  685. STRING(REPLACE "-I" ""
  686. wxWidgets_INCLUDE_DIRS "${wxWidgets_INCLUDE_DIRS}")
  687. DBG_MSG_V("wxWidgets_DEFINITIONS=${wxWidgets_DEFINITIONS}")
  688. DBG_MSG_V("wxWidgets_INCLUDE_DIRS=${wxWidgets_INCLUDE_DIRS}")
  689. DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
  690. ELSE(RET EQUAL 0)
  691. SET(wxWidgets_FOUND FALSE)
  692. DBG_MSG_V(
  693. "${wxWidgets_CONFIG_EXECUTABLE} --cxxflags FAILED with RET=${RET}")
  694. ENDIF(RET EQUAL 0)
  695. # run the wx-config program to get the libs
  696. # - NOTE: wx-config doesn't verify that the libs requested exist
  697. # it just produces the names. Maybe a TRY_COMPILE would
  698. # be useful here...
  699. STRING(REPLACE ";" ","
  700. wxWidgets_FIND_COMPONENTS "${wxWidgets_FIND_COMPONENTS}")
  701. EXECUTE_PROCESS(
  702. COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
  703. ${wxWidgets_SELECT_OPTIONS} --libs ${wxWidgets_FIND_COMPONENTS}
  704. OUTPUT_VARIABLE wxWidgets_LIBRARIES
  705. RESULT_VARIABLE RET
  706. ERROR_QUIET
  707. )
  708. IF(RET EQUAL 0)
  709. STRING(STRIP "${wxWidgets_LIBRARIES}" wxWidgets_LIBRARIES)
  710. SEPARATE_ARGUMENTS(wxWidgets_LIBRARIES)
  711. STRING(REPLACE "-framework;" "-framework "
  712. wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
  713. STRING(REPLACE "-arch;" "-arch "
  714. wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
  715. STRING(REPLACE "-isysroot;" "-isysroot "
  716. wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
  717. # extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES)
  718. STRING(REGEX MATCHALL "-L[^;]+"
  719. wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARIES}")
  720. STRING(REPLACE "-L" ""
  721. wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARY_DIRS}")
  722. DBG_MSG_V("wxWidgets_LIBRARIES=${wxWidgets_LIBRARIES}")
  723. DBG_MSG_V("wxWidgets_LIBRARY_DIRS=${wxWidgets_LIBRARY_DIRS}")
  724. ELSE(RET EQUAL 0)
  725. SET(wxWidgets_FOUND FALSE)
  726. DBG_MSG("${wxWidgets_CONFIG_EXECUTABLE} --libs ${wxWidgets_FIND_COMPONENTS} FAILED with RET=${RET}")
  727. ENDIF(RET EQUAL 0)
  728. ENDIF(wxWidgets_CONFIG_EXECUTABLE)
  729. #=====================================================================
  730. # Neither UNIX_FIND_STYLE, nor WIN32_FIND_STYLE
  731. #=====================================================================
  732. ELSE(wxWidgets_FIND_STYLE STREQUAL "unix")
  733. IF(NOT wxWidgets_FIND_QUIETLY)
  734. MESSAGE(STATUS
  735. "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): \n"
  736. " Platform unknown/unsupported. It's neither WIN32 nor UNIX "
  737. "find style."
  738. )
  739. ENDIF(NOT wxWidgets_FIND_QUIETLY)
  740. ENDIF(wxWidgets_FIND_STYLE STREQUAL "unix")
  741. ENDIF(wxWidgets_FIND_STYLE STREQUAL "win32")
  742. # Debug output:
  743. DBG_MSG("wxWidgets_FOUND : ${wxWidgets_FOUND}")
  744. DBG_MSG("wxWidgets_INCLUDE_DIRS : ${wxWidgets_INCLUDE_DIRS}")
  745. DBG_MSG("wxWidgets_LIBRARY_DIRS : ${wxWidgets_LIBRARY_DIRS}")
  746. DBG_MSG("wxWidgets_LIBRARIES : ${wxWidgets_LIBRARIES}")
  747. DBG_MSG("wxWidgets_CXX_FLAGS : ${wxWidgets_CXX_FLAGS}")
  748. DBG_MSG("wxWidgets_USE_FILE : ${wxWidgets_USE_FILE}")
  749. #=====================================================================
  750. #=====================================================================
  751. INCLUDE(FindPackageHandleStandardArgs)
  752. FIND_PACKAGE_HANDLE_STANDARD_ARGS(wxWidgets DEFAULT_MSG wxWidgets_FOUND)
  753. # Maintain consistency with all other variables.
  754. SET(wxWidgets_FOUND ${WXWIDGETS_FOUND})
  755. #=====================================================================
  756. # Macros for use in wxWidgets apps.
  757. # - This module will not fail to find wxWidgets based on the code
  758. # below. Hence, it's required to check for validity of:
  759. #
  760. # wxWidgets_wxrc_EXECUTABLE
  761. #=====================================================================
  762. # Resource file compiler.
  763. FIND_PROGRAM(wxWidgets_wxrc_EXECUTABLE wxrc
  764. ${wxWidgets_ROOT_DIR}/utils/wxrc/vc_msw
  765. )
  766. #
  767. # WX_SPLIT_ARGUMENTS_ON(<keyword> <left> <right> <arg1> <arg2> ...)
  768. #
  769. # Sets <left> and <right> to contain arguments to the left and right,
  770. # respectively, of <keyword>.
  771. #
  772. # Example usage:
  773. # FUNCTION(WXWIDGETS_ADD_RESOURCES outfiles)
  774. # WX_SPLIT_ARGUMENTS_ON(OPTIONS wxrc_files wxrc_options ${ARGN})
  775. # ...
  776. # ENDFUNCTION(WXWIDGETS_ADD_RESOURCES)
  777. #
  778. # WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o file.C)
  779. #
  780. # NOTE: This is a generic piece of code that should be renamed to
  781. # SPLIT_ARGUMENTS_ON and put in a file serving the same purpose as
  782. # FindPackageStandardArgs.cmake. At the time of this writing
  783. # FindQt4.cmake has a QT4_EXTRACT_OPTIONS, which I basically copied
  784. # here a bit more generalized. So, there are already two find modules
  785. # using this approach.
  786. #
  787. FUNCTION(WX_SPLIT_ARGUMENTS_ON _keyword _leftvar _rightvar)
  788. # FIXME: Document that the input variables will be cleared.
  789. #LIST(APPEND ${_leftvar} "")
  790. #LIST(APPEND ${_rightvar} "")
  791. SET(${_leftvar} "")
  792. SET(${_rightvar} "")
  793. SET(_doing_right FALSE)
  794. FOREACH(element ${ARGN})
  795. IF("${element}" STREQUAL "${_keyword}")
  796. SET(_doing_right TRUE)
  797. ELSE("${element}" STREQUAL "${_keyword}")
  798. IF(_doing_right)
  799. LIST(APPEND ${_rightvar} "${element}")
  800. ELSE(_doing_right)
  801. LIST(APPEND ${_leftvar} "${element}")
  802. ENDIF(_doing_right)
  803. ENDIF("${element}" STREQUAL "${_keyword}")
  804. ENDFOREACH(element)
  805. SET(${_leftvar} ${${_leftvar}} PARENT_SCOPE)
  806. SET(${_rightvar} ${${_rightvar}} PARENT_SCOPE)
  807. ENDFUNCTION(WX_SPLIT_ARGUMENTS_ON)
  808. #
  809. # WX_GET_DEPENDENCIES_FROM_XML(
  810. # <depends>
  811. # <match_pattern>
  812. # <clean_pattern>
  813. # <xml_contents>
  814. # <depends_path>
  815. # )
  816. #
  817. # FIXME: Add documentation here...
  818. #
  819. FUNCTION(WX_GET_DEPENDENCIES_FROM_XML
  820. _depends
  821. _match_patt
  822. _clean_patt
  823. _xml_contents
  824. _depends_path
  825. )
  826. STRING(REGEX MATCHALL
  827. ${_match_patt}
  828. dep_file_list
  829. "${${_xml_contents}}"
  830. )
  831. FOREACH(dep_file ${dep_file_list})
  832. STRING(REGEX REPLACE ${_clean_patt} "" dep_file "${dep_file}")
  833. # make the file have an absolute path
  834. IF(NOT IS_ABSOLUTE "${dep_file}")
  835. SET(dep_file "${${_depends_path}}/${dep_file}")
  836. ENDIF(NOT IS_ABSOLUTE "${dep_file}")
  837. # append file to dependency list
  838. LIST(APPEND ${_depends} "${dep_file}")
  839. ENDFOREACH(dep_file)
  840. SET(${_depends} ${${_depends}} PARENT_SCOPE)
  841. ENDFUNCTION(WX_GET_DEPENDENCIES_FROM_XML)
  842. #
  843. # WXWIDGETS_ADD_RESOURCES(<sources> <xrc_files>
  844. # OPTIONS <options> [NO_CPP_CODE])
  845. #
  846. # Adds a custom command for resource file compilation of the
  847. # <xrc_files> and appends the output files to <sources>.
  848. #
  849. # Example usages:
  850. # WXWIDGETS_ADD_RESOURCES(sources xrc/main_frame.xrc)
  851. # WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o altname.cxx)
  852. #
  853. FUNCTION(WXWIDGETS_ADD_RESOURCES _outfiles)
  854. WX_SPLIT_ARGUMENTS_ON(OPTIONS rc_file_list rc_options ${ARGN})
  855. # Parse files for dependencies.
  856. SET(rc_file_list_abs "")
  857. SET(rc_depends "")
  858. FOREACH(rc_file ${rc_file_list})
  859. GET_FILENAME_COMPONENT(depends_path ${rc_file} PATH)
  860. GET_FILENAME_COMPONENT(rc_file_abs ${rc_file} ABSOLUTE)
  861. LIST(APPEND rc_file_list_abs "${rc_file_abs}")
  862. # All files have absolute paths or paths relative to the location
  863. # of the rc file.
  864. FILE(READ "${rc_file_abs}" rc_file_contents)
  865. # get bitmap/bitmap2 files
  866. WX_GET_DEPENDENCIES_FROM_XML(
  867. rc_depends
  868. "<bitmap[^<]+"
  869. "^<bitmap[^>]*>"
  870. rc_file_contents
  871. depends_path
  872. )
  873. # get url files
  874. WX_GET_DEPENDENCIES_FROM_XML(
  875. rc_depends
  876. "<url[^<]+"
  877. "^<url[^>]*>"
  878. rc_file_contents
  879. depends_path
  880. )
  881. # get wxIcon files
  882. WX_GET_DEPENDENCIES_FROM_XML(
  883. rc_depends
  884. "<object[^>]*class=\"wxIcon\"[^<]+"
  885. "^<object[^>]*>"
  886. rc_file_contents
  887. depends_path
  888. )
  889. ENDFOREACH(rc_file)
  890. #
  891. # Parse options.
  892. #
  893. # If NO_CPP_CODE option specified, then produce .xrs file rather
  894. # than a .cpp file (i.e., don't add the default --cpp-code option).
  895. LIST(FIND rc_options NO_CPP_CODE index)
  896. IF(index EQUAL -1)
  897. LIST(APPEND rc_options --cpp-code)
  898. # wxrc's default output filename for cpp code.
  899. SET(outfile resource.cpp)
  900. ELSE(index EQUAL -1)
  901. LIST(REMOVE_AT rc_options ${index})
  902. # wxrc's default output filename for xrs file.
  903. SET(outfile resource.xrs)
  904. ENDIF(index EQUAL -1)
  905. # Get output name for use in ADD_CUSTOM_COMMAND.
  906. # - short option scanning
  907. LIST(FIND rc_options -o index)
  908. IF(NOT index EQUAL -1)
  909. MATH(EXPR filename_index "${index} + 1")
  910. LIST(GET rc_options ${filename_index} outfile)
  911. #LIST(REMOVE_AT rc_options ${index} ${filename_index})
  912. ENDIF(NOT index EQUAL -1)
  913. # - long option scanning
  914. STRING(REGEX MATCH "--output=[^;]*" outfile_opt "${rc_options}")
  915. IF(outfile_opt)
  916. STRING(REPLACE "--output=" "" outfile "${outfile_opt}")
  917. ENDIF(outfile_opt)
  918. #STRING(REGEX REPLACE "--output=[^;]*;?" "" rc_options "${rc_options}")
  919. #STRING(REGEX REPLACE ";$" "" rc_options "${rc_options}")
  920. IF(NOT IS_ABSOLUTE "${outfile}")
  921. SET(outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
  922. ENDIF(NOT IS_ABSOLUTE "${outfile}")
  923. ADD_CUSTOM_COMMAND(
  924. OUTPUT "${outfile}"
  925. COMMAND ${wxWidgets_wxrc_EXECUTABLE} ${rc_options} ${rc_file_list_abs}
  926. DEPENDS ${rc_file_list_abs} ${rc_depends}
  927. )
  928. # Add generated header to output file list.
  929. LIST(FIND rc_options -e short_index)
  930. LIST(FIND rc_options --extra-cpp-code long_index)
  931. IF(NOT short_index EQUAL -1 OR NOT long_index EQUAL -1)
  932. GET_FILENAME_COMPONENT(outfile_ext ${outfile} EXT)
  933. STRING(REPLACE "${outfile_ext}" ".h" outfile_header "${outfile}")
  934. LIST(APPEND ${_outfiles} "${outfile_header}")
  935. SET_SOURCE_FILES_PROPERTIES(
  936. "${outfile_header}" PROPERTIES GENERATED TRUE
  937. )
  938. ENDIF(NOT short_index EQUAL -1 OR NOT long_index EQUAL -1)
  939. # Add generated file to output file list.
  940. LIST(APPEND ${_outfiles} "${outfile}")
  941. SET(${_outfiles} ${${_outfiles}} PARENT_SCOPE)
  942. ENDFUNCTION(WXWIDGETS_ADD_RESOURCES)