You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1206 lines
41 KiB

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