FindwxWidgets.cmake 36 KB

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