FindwxWidgets.cmake 38 KB

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