FindwxWidgets.cmake 34 KB

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