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
7 # FIND_PACKAGE(wxWidgets COMPONENTS base core ...)
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):
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.)
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:
28 # wxWidgets_USE_UNICODE
29 # wxWidgets_USE_UNIVERSAL
30 # wxWidgets_USE_STATIC
32 # The following are set after the configuration is done for both
33 # windows and unix style:
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. WXUSINGDLL
45 # wxWidgets_DEFINITIONS_DEBUG- Contains defines required to compile/link
46 # against WX debug builds, e.g. __WXDEBUG__
47 # wxWidgets_CXX_FLAGS - Include dirs and compiler flags for
48 # unices, empty on WIN32. Essentially
49 # "`wx-config --cxxflags`".
50 # wxWidgets_USE_FILE - Convenience include file.
53 # FIND_PACKAGE(wxWidgets COMPONENTS base core gl net)
55 # INCLUDE(${wxWidgets_USE_FILE})
56 # # and for each of your dependant executable/library targets:
57 # TARGET_LINK_LIBRARIES(<YourTarget> ${wxWidgets_LIBRARIES})
58 # ENDIF(wxWidgets_FOUND)
60 # If wxWidgets is required (i.e., not an optional part):
61 # FIND_PACKAGE(wxWidgets REQUIRED base core gl net)
62 # INCLUDE(${wxWidgets_USE_FILE})
63 # # and for each of your dependant executable/library targets:
64 # TARGET_LINK_LIBRARIES(<YourTarget> ${wxWidgets_LIBRARIES})
67 # FIXME: check this and provide a correct sample usage...
68 # Remember to connect back to the upper text.
69 # Sample usage with monolithic wx build:
71 # FIND_PACKAGE(wxWidgets COMPONENTS mono)
77 # This module has been tested on the WIN32 platform with wxWidgets
78 # 2.6.2, 2.6.3, and 2.5.3. However, it has been designed to
79 # easily extend support to all possible builds, e.g., static/shared,
80 # debug/release, unicode, universal, multilib/monolithic, etc..
82 # If you want to use the module and your build type is not supported
83 # out-of-the-box, please contact me to exchange information on how
84 # your system is setup and I'll try to add support for it.
88 # Miguel A. Figueroa-Villanueva (miguelf at ieee dot org).
89 # Jan Woetzel (jw at mip.informatik.uni-kiel.de).
91 # Based on previous works of:
92 # Jan Woetzel (FindwxWindows.cmake),
93 # Jorgen Bodde and Jerry Fath (FindwxWin.cmake).
97 # (1) Option/Setting to use all available wx libs
98 # In contrast to expert developer who lists the
99 # minimal set of required libs in wxWidgets_USE_LIBS
100 # there is the newbie user:
101 # - who just wants to link against WX with more 'magic'
102 # - doesn't know the internal structure of WX or how it was built,
103 # in particular if it is monolithic or not
104 # - want to link against all available WX libs
105 # Basically, the intent here is to mimic what wx-config would do by
106 # default (i.e., `wx-config --libs`).
109 # Add a reserved keyword "std" that initializes to what wx-config
110 # would default to. If the user has not set the wxWidgets_USE_LIBS,
111 # default to "std" instead of "base core" as it is now. To implement
112 # "std" will basically boil down to a FOR_EACH lib-FOUND, but maybe
113 # checking whether a minimal set was found.
116 # FIXME: This and all the DBG_MSG calls should be removed after the
119 # Helper macro to control the debugging output globally. There are
120 # two versions for controlling how verbose your output should be.
123 # "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}")
125 MACRO(DBG_MSG_V _MSG)
127 # "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}")
130 # Clear return values in case the module is loaded more than once.
131 SET(wxWidgets_FOUND FALSE)
132 SET(wxWidgets_INCLUDE_DIRS "")
133 SET(wxWidgets_LIBRARIES "")
134 SET(wxWidgets_LIBRARY_DIRS "")
135 SET(wxWidgets_CXX_FLAGS "")
137 # Using SYSTEM with INCLUDE_DIRECTORIES in conjunction with wxWidgets on
138 # the Mac produces compiler errors. Set wxWidgets_INCLUDE_DIRS_NO_SYSTEM
139 # to prevent UsewxWidgets.cmake from using SYSTEM.
141 # See cmake mailing list discussions for more info:
142 # http://www.cmake.org/pipermail/cmake/2008-April/021115.html
143 # http://www.cmake.org/pipermail/cmake/2008-April/021146.html
146 SET(wxWidgets_INCLUDE_DIRS_NO_SYSTEM 1)
149 # DEPRECATED: This is a patch to support the DEPRECATED use of
150 # wxWidgets_USE_LIBS.
152 # If wxWidgets_USE_LIBS is set:
153 # - if using <components>, then override wxWidgets_USE_LIBS
154 # - else set wxWidgets_FIND_COMPONENTS to wxWidgets_USE_LIBS
155 IF(wxWidgets_USE_LIBS AND NOT wxWidgets_FIND_COMPONENTS)
156 SET(wxWidgets_FIND_COMPONENTS ${wxWidgets_USE_LIBS})
157 ENDIF(wxWidgets_USE_LIBS AND NOT wxWidgets_FIND_COMPONENTS)
158 DBG_MSG("wxWidgets_FIND_COMPONENTS : ${wxWidgets_FIND_COMPONENTS}")
160 # Add the convenience use file if available.
162 # Get dir of this file which may reside in:
163 # - CMAKE_MAKE_ROOT/Modules on CMake installation
164 # - CMAKE_MODULE_PATH if user prefers his own specialized version
165 SET(wxWidgets_USE_FILE "")
166 GET_FILENAME_COMPONENT(
167 wxWidgets_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
168 # Prefer an existing customized version, but the user might override
169 # the FindwxWidgets module and not the UsewxWidgets one.
170 IF(EXISTS "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
171 SET(wxWidgets_USE_FILE
172 "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
173 ELSE(EXISTS "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
174 SET(wxWidgets_USE_FILE UsewxWidgets.cmake)
175 ENDIF(EXISTS "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
177 #=====================================================================
178 #=====================================================================
179 IF(WIN32 AND NOT CYGWIN AND NOT MSYS)
180 SET(wxWidgets_FIND_STYLE "win32")
181 ELSE(WIN32 AND NOT CYGWIN AND NOT MSYS)
183 SET(wxWidgets_FIND_STYLE "unix")
185 ENDIF(WIN32 AND NOT CYGWIN AND NOT MSYS)
187 #=====================================================================
189 #=====================================================================
190 IF(wxWidgets_FIND_STYLE STREQUAL "win32")
191 # Useful common wx libs needed by almost all components.
192 SET(wxWidgets_COMMON_LIBRARIES png tiff jpeg zlib regex expat)
194 # DEPRECATED: Use FIND_PACKAGE(wxWidgets COMPONENTS mono) instead.
195 IF(NOT wxWidgets_FIND_COMPONENTS)
196 IF(wxWidgets_USE_MONOLITHIC)
197 SET(wxWidgets_FIND_COMPONENTS mono)
198 ELSE(wxWidgets_USE_MONOLITHIC)
199 SET(wxWidgets_FIND_COMPONENTS base core) # this is default
200 ENDIF(wxWidgets_USE_MONOLITHIC)
201 ENDIF(NOT wxWidgets_FIND_COMPONENTS)
203 # Always add the common required libs.
204 LIST(APPEND wxWidgets_FIND_COMPONENTS ${wxWidgets_COMMON_LIBRARIES})
206 #-------------------------------------------------------------------
207 # WIN32: Helper MACROS
208 #-------------------------------------------------------------------
210 # Get filename components for a configuration. For example,
211 # if _CONFIGURATION = mswunivud, then _UNV=univ, _UCD=u _DBG=d
212 # if _CONFIGURATION = mswu, then _UNV="", _UCD=u _DBG=""
214 MACRO(WX_GET_NAME_COMPONENTS _CONFIGURATION _UNV _UCD _DBG)
215 STRING(REGEX MATCH "univ" ${_UNV} "${_CONFIGURATION}")
216 STRING(REGEX REPLACE "msw.*(u)[d]*$" "u" ${_UCD} "${_CONFIGURATION}")
217 IF(${_UCD} STREQUAL ${_CONFIGURATION})
219 ENDIF(${_UCD} STREQUAL ${_CONFIGURATION})
220 STRING(REGEX MATCH "d$" ${_DBG} "${_CONFIGURATION}")
221 ENDMACRO(WX_GET_NAME_COMPONENTS)
224 # Find libraries associated to a configuration.
226 MACRO(WX_FIND_LIBS _UNV _UCD _DBG)
227 DBG_MSG_V("m_unv = ${_UNV}")
228 DBG_MSG_V("m_ucd = ${_UCD}")
229 DBG_MSG_V("m_dbg = ${_DBG}")
231 # FIXME: What if both regex libs are available. regex should be
232 # found outside the loop and only wx${LIB}${_UCD}${_DBG}.
233 # Find wxWidgets common libraries.
234 FOREACH(LIB ${wxWidgets_COMMON_LIBRARIES})
235 FIND_LIBRARY(WX_${LIB}${_DBG}
237 wx${LIB}${_UCD}${_DBG} # for regex
242 MARK_AS_ADVANCED(WX_${LIB}${_DBG})
245 # Find wxWidgets multilib base libraries.
246 FIND_LIBRARY(WX_base${_DBG}
248 wxbase29${_UCD}${_DBG}
249 wxbase28${_UCD}${_DBG}
250 wxbase27${_UCD}${_DBG}
251 wxbase26${_UCD}${_DBG}
252 wxbase25${_UCD}${_DBG}
256 MARK_AS_ADVANCED(WX_base${_DBG})
257 FOREACH(LIB net odbc xml)
258 FIND_LIBRARY(WX_${LIB}${_DBG}
260 wxbase29${_UCD}${_DBG}_${LIB}
261 wxbase28${_UCD}${_DBG}_${LIB}
262 wxbase27${_UCD}${_DBG}_${LIB}
263 wxbase26${_UCD}${_DBG}_${LIB}
264 wxbase25${_UCD}${_DBG}_${LIB}
268 MARK_AS_ADVANCED(WX_${LIB}${_DBG})
271 # Find wxWidgets monolithic library.
272 FIND_LIBRARY(WX_mono${_DBG}
274 wxmsw${_UNV}29${_UCD}${_DBG}
275 wxmsw${_UNV}28${_UCD}${_DBG}
276 wxmsw${_UNV}27${_UCD}${_DBG}
277 wxmsw${_UNV}26${_UCD}${_DBG}
278 wxmsw${_UNV}25${_UCD}${_DBG}
282 MARK_AS_ADVANCED(WX_mono${_DBG})
284 # Find wxWidgets multilib libraries.
285 FOREACH(LIB core adv aui html media xrc dbgrid gl qa richtext)
286 FIND_LIBRARY(WX_${LIB}${_DBG}
288 wxmsw${_UNV}29${_UCD}${_DBG}_${LIB}
289 wxmsw${_UNV}28${_UCD}${_DBG}_${LIB}
290 wxmsw${_UNV}27${_UCD}${_DBG}_${LIB}
291 wxmsw${_UNV}26${_UCD}${_DBG}_${LIB}
292 wxmsw${_UNV}25${_UCD}${_DBG}_${LIB}
296 MARK_AS_ADVANCED(WX_${LIB}${_DBG})
298 ENDMACRO(WX_FIND_LIBS)
301 # Clear all library paths, so that FIND_LIBRARY refinds them.
303 # Clear a lib, reset its found flag, and mark as advanced.
304 MACRO(WX_CLEAR_LIB _LIB)
305 SET(${_LIB} "${_LIB}-NOTFOUND" CACHE FILEPATH "Cleared." FORCE)
306 SET(${_LIB}_FOUND FALSE)
307 MARK_AS_ADVANCED(${_LIB})
308 ENDMACRO(WX_CLEAR_LIB)
309 # Clear all debug or release library paths (arguments are "d" or "").
310 MACRO(WX_CLEAR_ALL_LIBS _DBG)
311 # Clear wxWidgets common libraries.
312 FOREACH(LIB ${wxWidgets_COMMON_LIBRARIES})
313 WX_CLEAR_LIB(WX_${LIB}${_DBG})
316 # Clear wxWidgets multilib base libraries.
317 WX_CLEAR_LIB(WX_base${_DBG})
318 FOREACH(LIB net odbc xml)
319 WX_CLEAR_LIB(WX_${LIB}${_DBG})
322 # Clear wxWidgets monolithic library.
323 WX_CLEAR_LIB(WX_mono${_DBG})
325 # Clear wxWidgets multilib libraries.
326 FOREACH(LIB core adv aui html media xrc dbgrid gl qa richtext)
327 WX_CLEAR_LIB(WX_${LIB}${_DBG})
329 ENDMACRO(WX_CLEAR_ALL_LIBS)
330 # Clear all wxWidgets debug libraries.
331 MACRO(WX_CLEAR_ALL_DBG_LIBS)
332 WX_CLEAR_ALL_LIBS("d")
333 ENDMACRO(WX_CLEAR_ALL_DBG_LIBS)
334 # Clear all wxWidgets release libraries.
335 MACRO(WX_CLEAR_ALL_REL_LIBS)
336 WX_CLEAR_ALL_LIBS("")
337 ENDMACRO(WX_CLEAR_ALL_REL_LIBS)
340 # Set the wxWidgets_LIBRARIES variable.
341 # Also, Sets output variable wxWidgets_FOUND to FALSE if it fails.
343 MACRO(WX_SET_LIBRARIES _LIBS _DBG)
344 DBG_MSG_V("Looking for ${${_LIBS}}")
345 IF(WX_USE_REL_AND_DBG)
346 FOREACH(LIB ${${_LIBS}})
347 DBG_MSG_V("Searching for ${LIB} and ${LIB}d")
348 DBG_MSG_V("WX_${LIB} : ${WX_${LIB}}")
349 DBG_MSG_V("WX_${LIB}d : ${WX_${LIB}d}")
350 IF(WX_${LIB} AND WX_${LIB}d)
351 DBG_MSG_V("Found ${LIB} and ${LIB}d")
352 LIST(APPEND wxWidgets_LIBRARIES
353 debug ${WX_${LIB}d} optimized ${WX_${LIB}}
355 ELSE(WX_${LIB} AND WX_${LIB}d)
356 DBG_MSG_V("- not found due to missing WX_${LIB}=${WX_${LIB}} or WX_${LIB}d=${WX_${LIB}d}")
357 SET(wxWidgets_FOUND FALSE)
358 ENDIF(WX_${LIB} AND WX_${LIB}d)
360 ELSE(WX_USE_REL_AND_DBG)
361 FOREACH(LIB ${${_LIBS}})
362 DBG_MSG_V("Searching for ${LIB}${_DBG}")
363 DBG_MSG_V("WX_${LIB}${_DBG} : ${WX_${LIB}${_DBG}}")
365 DBG_MSG_V("Found ${LIB}${_DBG}")
366 LIST(APPEND wxWidgets_LIBRARIES ${WX_${LIB}${_DBG}})
367 ELSE(WX_${LIB}${_DBG})
369 "- not found due to missing WX_${LIB}${_DBG}=${WX_${LIB}${_DBG}}")
370 SET(wxWidgets_FOUND FALSE)
371 ENDIF(WX_${LIB}${_DBG})
373 ENDIF(WX_USE_REL_AND_DBG)
376 LIST(FIND ${_LIBS} gl WX_USE_GL)
377 IF(NOT WX_USE_GL EQUAL -1)
378 DBG_MSG_V("- is required.")
379 LIST(APPEND wxWidgets_LIBRARIES opengl32 glu32)
380 ENDIF(NOT WX_USE_GL EQUAL -1)
382 LIST(APPEND wxWidgets_LIBRARIES winmm comctl32 rpcrt4 wsock32)
383 ENDMACRO(WX_SET_LIBRARIES)
385 #-------------------------------------------------------------------
386 # WIN32: Start actual work.
387 #-------------------------------------------------------------------
389 # Look for an installation tree.
390 FIND_PATH(wxWidgets_ROOT_DIR
391 NAMES include/wx/wx.h
393 $ENV{wxWidgets_ROOT_DIR}
395 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\wxWidgets_is1;Inno Setup: App Path]" # WX 2.6.x
430 DOC "wxWidgets base/installation directory?"
433 # If wxWidgets_ROOT_DIR changed, clear lib dir.
434 IF(NOT WX_ROOT_DIR STREQUAL wxWidgets_ROOT_DIR)
435 SET(WX_ROOT_DIR ${wxWidgets_ROOT_DIR}
436 CACHE INTERNAL "wxWidgets_ROOT_DIR")
437 SET(wxWidgets_LIB_DIR "wxWidgets_LIB_DIR-NOTFOUND"
438 CACHE PATH "Cleared." FORCE)
439 ENDIF(NOT WX_ROOT_DIR STREQUAL wxWidgets_ROOT_DIR)
442 # Select one default tree inside the already determined wx tree.
443 # Prefer static/shared order usually consistent with build
446 SET(WX_LIB_DIR_PREFIX gcc)
448 SET(WX_LIB_DIR_PREFIX vc)
450 IF(BUILD_SHARED_LIBS)
451 FIND_PATH(wxWidgets_LIB_DIR
462 ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_dll # prefer shared
463 ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_lib
464 DOC "Path to wxWidgets libraries?"
467 ELSE(BUILD_SHARED_LIBS)
468 FIND_PATH(wxWidgets_LIB_DIR
479 ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_lib # prefer static
480 ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_dll
481 DOC "Path to wxWidgets libraries?"
484 ENDIF(BUILD_SHARED_LIBS)
486 # If wxWidgets_LIB_DIR changed, clear all libraries.
487 IF(NOT WX_LIB_DIR STREQUAL wxWidgets_LIB_DIR)
488 SET(WX_LIB_DIR ${wxWidgets_LIB_DIR} CACHE INTERNAL "wxWidgets_LIB_DIR")
489 WX_CLEAR_ALL_DBG_LIBS()
490 WX_CLEAR_ALL_REL_LIBS()
491 ENDIF(NOT WX_LIB_DIR STREQUAL wxWidgets_LIB_DIR)
494 # If building shared libs, define WXUSINGDLL to use dllimport.
495 IF(WX_LIB_DIR MATCHES ".*[dD][lL][lL].*")
496 SET(wxWidgets_DEFINITIONS WXUSINGDLL)
497 DBG_MSG_V("detected SHARED/DLL tree WX_LIB_DIR=${WX_LIB_DIR}")
498 ENDIF(WX_LIB_DIR MATCHES ".*[dD][lL][lL].*")
500 # Search for available configuration types.
501 FOREACH(CFG mswunivud mswunivd mswud mswd mswunivu mswuniv mswu msw)
502 SET(WX_${CFG}_FOUND FALSE)
503 IF(EXISTS ${WX_LIB_DIR}/${CFG})
504 LIST(APPEND WX_CONFIGURATION_LIST ${CFG})
505 SET(WX_${CFG}_FOUND TRUE)
506 SET(WX_CONFIGURATION ${CFG})
507 ENDIF(EXISTS ${WX_LIB_DIR}/${CFG})
509 DBG_MSG_V("WX_CONFIGURATION_LIST=${WX_CONFIGURATION_LIST}")
512 SET(wxWidgets_FOUND TRUE)
514 # If the selected configuration wasn't found force the default
515 # one. Otherwise, use it but still force a refresh for
516 # updating the doc string with the current list of available
518 IF(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
519 SET(wxWidgets_CONFIGURATION ${WX_CONFIGURATION} CACHE STRING
520 "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
521 ELSE(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
522 SET(wxWidgets_CONFIGURATION ${wxWidgets_CONFIGURATION} CACHE STRING
523 "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
524 ENDIF(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
526 # If release config selected, and both release/debug exist.
527 IF(WX_${wxWidgets_CONFIGURATION}d_FOUND)
528 OPTION(wxWidgets_USE_REL_AND_DBG
529 "Use release and debug configurations?" TRUE)
530 SET(WX_USE_REL_AND_DBG ${wxWidgets_USE_REL_AND_DBG})
531 ELSE(WX_${wxWidgets_CONFIGURATION}d_FOUND)
532 # If the option exists (already in cache), force it false.
533 IF(wxWidgets_USE_REL_AND_DBG)
534 SET(wxWidgets_USE_REL_AND_DBG FALSE CACHE BOOL
535 "No ${wxWidgets_CONFIGURATION}d found." FORCE)
536 ENDIF(wxWidgets_USE_REL_AND_DBG)
537 SET(WX_USE_REL_AND_DBG FALSE)
538 ENDIF(WX_${wxWidgets_CONFIGURATION}d_FOUND)
540 # Get configuration parameters from the name.
541 WX_GET_NAME_COMPONENTS(${wxWidgets_CONFIGURATION} UNV UCD DBG)
543 # Set wxWidgets main include directory.
544 IF(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
545 SET(wxWidgets_INCLUDE_DIRS ${WX_ROOT_DIR}/include)
546 ELSE(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
547 DBG_MSG("wxWidgets_FOUND FALSE because WX_ROOT_DIR=${WX_ROOT_DIR} has no ${WX_ROOT_DIR}/include/wx/wx.h")
548 SET(wxWidgets_FOUND FALSE)
549 ENDIF(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
551 # Set wxWidgets lib setup include directory.
552 IF(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
553 LIST(APPEND wxWidgets_INCLUDE_DIRS
554 ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION})
555 ELSE(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
556 DBG_MSG("WXWIDGET_FOUND FALSE because ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h does not exists.")
557 SET(wxWidgets_FOUND FALSE)
558 ENDIF(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
560 # Find wxWidgets libraries.
561 WX_FIND_LIBS("${UNV}" "${UCD}" "${DBG}")
562 IF(WX_USE_REL_AND_DBG)
563 WX_FIND_LIBS("${UNV}" "${UCD}" "d")
564 ENDIF(WX_USE_REL_AND_DBG)
566 # Settings for requested libs (i.e., include dir, libraries, etc.).
567 WX_SET_LIBRARIES(wxWidgets_FIND_COMPONENTS "${DBG}")
569 # Add necessary definitions for unicode builds
570 IF("${UCD}" STREQUAL "u")
571 LIST(APPEND wxWidgets_DEFINITIONS UNICODE _UNICODE)
572 ENDIF("${UCD}" STREQUAL "u")
574 # Add necessary definitions for debug builds
575 SET(wxWidgets_DEFINITIONS_DEBUG _DEBUG __WXDEBUG__)
577 ENDIF(WX_CONFIGURATION)
581 #=====================================================================
583 #=====================================================================
584 ELSE(wxWidgets_FIND_STYLE STREQUAL "win32")
585 IF(wxWidgets_FIND_STYLE STREQUAL "unix")
586 #-----------------------------------------------------------------
587 # UNIX: Helper MACROS
588 #-----------------------------------------------------------------
590 # Set the default values based on "wx-config --selected-config".
592 MACRO(WX_CONFIG_SELECT_GET_DEFAULT)
594 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --selected-config
595 OUTPUT_VARIABLE _wx_selected_config
596 RESULT_VARIABLE _wx_result
599 IF(_wx_result EQUAL 0)
600 FOREACH(_opt_name debug static unicode universal)
601 STRING(TOUPPER ${_opt_name} _upper_opt_name)
602 IF(_wx_selected_config MATCHES ".*${_opt_name}.*")
603 SET(wxWidgets_DEFAULT_${_upper_opt_name} ON)
604 ELSE(_wx_selected_config MATCHES ".*${_opt_name}.*")
605 SET(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
606 ENDIF(_wx_selected_config MATCHES ".*${_opt_name}.*")
607 ENDFOREACH(_opt_name)
608 ELSE(_wx_result EQUAL 0)
609 FOREACH(_upper_opt_name DEBUG STATIC UNICODE UNIVERSAL)
610 SET(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
611 ENDFOREACH(_upper_opt_name)
612 ENDIF(_wx_result EQUAL 0)
613 ENDMACRO(WX_CONFIG_SELECT_GET_DEFAULT)
616 # Query a boolean configuration option to determine if the system
617 # has both builds available. If so, provide the selection option
620 MACRO(WX_CONFIG_SELECT_QUERY_BOOL _OPT_NAME _OPT_HELP)
622 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --${_OPT_NAME}=yes
623 RESULT_VARIABLE _wx_result_yes
628 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --${_OPT_NAME}=no
629 RESULT_VARIABLE _wx_result_no
633 STRING(TOUPPER ${_OPT_NAME} _UPPER_OPT_NAME)
634 IF(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
635 OPTION(wxWidgets_USE_${_UPPER_OPT_NAME}
636 ${_OPT_HELP} ${wxWidgets_DEFAULT_${_UPPER_OPT_NAME}})
637 ELSE(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
638 # If option exists (already in cache), force to available one.
639 IF(DEFINED wxWidgets_USE_${_UPPER_OPT_NAME})
640 IF(_wx_result_yes EQUAL 0)
641 SET(wxWidgets_USE_${_UPPER_OPT_NAME} ON CACHE BOOL ${_OPT_HELP} FORCE)
642 ELSE(_wx_result_yes EQUAL 0)
643 SET(wxWidgets_USE_${_UPPER_OPT_NAME} OFF CACHE BOOL ${_OPT_HELP} FORCE)
644 ENDIF(_wx_result_yes EQUAL 0)
645 ENDIF(DEFINED wxWidgets_USE_${_UPPER_OPT_NAME})
646 ENDIF(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
647 ENDMACRO(WX_CONFIG_SELECT_QUERY_BOOL)
650 # Set wxWidgets_SELECT_OPTIONS to wx-config options for selecting
651 # among multiple builds.
653 MACRO(WX_CONFIG_SELECT_SET_OPTIONS)
654 SET(wxWidgets_SELECT_OPTIONS "")
655 FOREACH(_opt_name debug static unicode universal)
656 STRING(TOUPPER ${_opt_name} _upper_opt_name)
657 IF(DEFINED wxWidgets_USE_${_upper_opt_name})
658 IF(wxWidgets_USE_${_upper_opt_name})
659 LIST(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=yes)
660 ELSE(wxWidgets_USE_${_upper_opt_name})
661 LIST(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=no)
662 ENDIF(wxWidgets_USE_${_upper_opt_name})
663 ENDIF(DEFINED wxWidgets_USE_${_upper_opt_name})
664 ENDFOREACH(_opt_name)
665 ENDMACRO(WX_CONFIG_SELECT_SET_OPTIONS)
667 #-----------------------------------------------------------------
668 # UNIX: Start actual work.
669 #-----------------------------------------------------------------
670 # Support cross-compiling, only search in the target platform.
671 FIND_PROGRAM(wxWidgets_CONFIG_EXECUTABLE wx-config
672 ONLY_CMAKE_FIND_ROOT_PATH
675 IF(wxWidgets_CONFIG_EXECUTABLE)
676 SET(wxWidgets_FOUND TRUE)
678 # get defaults based on "wx-config --selected-config"
679 WX_CONFIG_SELECT_GET_DEFAULT()
681 # for each option: if both builds are available, provide option
682 WX_CONFIG_SELECT_QUERY_BOOL(debug "Use debug build?")
683 WX_CONFIG_SELECT_QUERY_BOOL(unicode "Use unicode build?")
684 WX_CONFIG_SELECT_QUERY_BOOL(universal "Use universal build?")
685 WX_CONFIG_SELECT_QUERY_BOOL(static "Link libraries statically?")
687 # process selection to set wxWidgets_SELECT_OPTIONS
688 WX_CONFIG_SELECT_SET_OPTIONS()
689 DBG_MSG("wxWidgets_SELECT_OPTIONS=${wxWidgets_SELECT_OPTIONS}")
691 # run the wx-config program to get cxxflags
693 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
694 ${wxWidgets_SELECT_OPTIONS} --cxxflags
695 OUTPUT_VARIABLE wxWidgets_CXX_FLAGS
700 STRING(STRIP "${wxWidgets_CXX_FLAGS}" wxWidgets_CXX_FLAGS)
701 SEPARATE_ARGUMENTS(wxWidgets_CXX_FLAGS)
703 DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
705 # parse definitions from cxxflags; drop -D* from CXXFLAGS and the -D prefix
706 STRING(REGEX MATCHALL "-D[^;]+"
707 wxWidgets_DEFINITIONS "${wxWidgets_CXX_FLAGS}")
708 STRING(REGEX REPLACE "-D[^;]+;" ""
709 wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
710 STRING(REPLACE "-D" ""
711 wxWidgets_DEFINITIONS "${wxWidgets_DEFINITIONS}")
713 # parse include dirs from cxxflags; drop -I prefix
714 STRING(REGEX MATCHALL "-I[^;]+"
715 wxWidgets_INCLUDE_DIRS "${wxWidgets_CXX_FLAGS}")
716 STRING(REGEX REPLACE "-I[^;]+;" ""
717 wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
718 STRING(REPLACE "-I" ""
719 wxWidgets_INCLUDE_DIRS "${wxWidgets_INCLUDE_DIRS}")
721 DBG_MSG_V("wxWidgets_DEFINITIONS=${wxWidgets_DEFINITIONS}")
722 DBG_MSG_V("wxWidgets_INCLUDE_DIRS=${wxWidgets_INCLUDE_DIRS}")
723 DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
726 SET(wxWidgets_FOUND FALSE)
728 "${wxWidgets_CONFIG_EXECUTABLE} --cxxflags FAILED with RET=${RET}")
731 # run the wx-config program to get the libs
732 # - NOTE: wx-config doesn't verify that the libs requested exist
733 # it just produces the names. Maybe a TRY_COMPILE would
735 STRING(REPLACE ";" ","
736 wxWidgets_FIND_COMPONENTS "${wxWidgets_FIND_COMPONENTS}")
738 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
739 ${wxWidgets_SELECT_OPTIONS} --libs ${wxWidgets_FIND_COMPONENTS}
740 OUTPUT_VARIABLE wxWidgets_LIBRARIES
745 STRING(STRIP "${wxWidgets_LIBRARIES}" wxWidgets_LIBRARIES)
746 SEPARATE_ARGUMENTS(wxWidgets_LIBRARIES)
747 STRING(REPLACE "-framework;" "-framework "
748 wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
749 STRING(REPLACE "-arch;" "-arch "
750 wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
751 STRING(REPLACE "-isysroot;" "-isysroot "
752 wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
754 # extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES)
755 STRING(REGEX MATCHALL "-L[^;]+"
756 wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARIES}")
757 STRING(REPLACE "-L" ""
758 wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARY_DIRS}")
760 DBG_MSG_V("wxWidgets_LIBRARIES=${wxWidgets_LIBRARIES}")
761 DBG_MSG_V("wxWidgets_LIBRARY_DIRS=${wxWidgets_LIBRARY_DIRS}")
764 SET(wxWidgets_FOUND FALSE)
765 DBG_MSG("${wxWidgets_CONFIG_EXECUTABLE} --libs ${wxWidgets_FIND_COMPONENTS} FAILED with RET=${RET}")
767 ENDIF(wxWidgets_CONFIG_EXECUTABLE)
769 #=====================================================================
770 # Neither UNIX_FIND_STYLE, nor WIN32_FIND_STYLE
771 #=====================================================================
772 ELSE(wxWidgets_FIND_STYLE STREQUAL "unix")
773 IF(NOT wxWidgets_FIND_QUIETLY)
775 "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): \n"
776 " Platform unknown/unsupported. It's neither WIN32 nor UNIX "
779 ENDIF(NOT wxWidgets_FIND_QUIETLY)
780 ENDIF(wxWidgets_FIND_STYLE STREQUAL "unix")
781 ENDIF(wxWidgets_FIND_STYLE STREQUAL "win32")
784 DBG_MSG("wxWidgets_FOUND : ${wxWidgets_FOUND}")
785 DBG_MSG("wxWidgets_INCLUDE_DIRS : ${wxWidgets_INCLUDE_DIRS}")
786 DBG_MSG("wxWidgets_LIBRARY_DIRS : ${wxWidgets_LIBRARY_DIRS}")
787 DBG_MSG("wxWidgets_LIBRARIES : ${wxWidgets_LIBRARIES}")
788 DBG_MSG("wxWidgets_CXX_FLAGS : ${wxWidgets_CXX_FLAGS}")
789 DBG_MSG("wxWidgets_USE_FILE : ${wxWidgets_USE_FILE}")
791 #=====================================================================
792 #=====================================================================
793 INCLUDE(FindPackageHandleStandardArgs)
794 FIND_PACKAGE_HANDLE_STANDARD_ARGS(wxWidgets DEFAULT_MSG wxWidgets_FOUND)
795 # Maintain consistency with all other variables.
796 SET(wxWidgets_FOUND ${WXWIDGETS_FOUND})
798 #=====================================================================
799 # Macros for use in wxWidgets apps.
800 # - This module will not fail to find wxWidgets based on the code
801 # below. Hence, it's required to check for validity of:
803 # wxWidgets_wxrc_EXECUTABLE
804 #=====================================================================
806 # Resource file compiler.
807 FIND_PROGRAM(wxWidgets_wxrc_EXECUTABLE wxrc
808 ${wxWidgets_ROOT_DIR}/utils/wxrc/vc_msw
812 # WX_SPLIT_ARGUMENTS_ON(<keyword> <left> <right> <arg1> <arg2> ...)
814 # Sets <left> and <right> to contain arguments to the left and right,
815 # respectively, of <keyword>.
818 # FUNCTION(WXWIDGETS_ADD_RESOURCES outfiles)
819 # WX_SPLIT_ARGUMENTS_ON(OPTIONS wxrc_files wxrc_options ${ARGN})
821 # ENDFUNCTION(WXWIDGETS_ADD_RESOURCES)
823 # WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o file.C)
825 # NOTE: This is a generic piece of code that should be renamed to
826 # SPLIT_ARGUMENTS_ON and put in a file serving the same purpose as
827 # FindPackageStandardArgs.cmake. At the time of this writing
828 # FindQt4.cmake has a QT4_EXTRACT_OPTIONS, which I basically copied
829 # here a bit more generalized. So, there are already two find modules
830 # using this approach.
832 FUNCTION(WX_SPLIT_ARGUMENTS_ON _keyword _leftvar _rightvar)
833 # FIXME: Document that the input variables will be cleared.
834 #LIST(APPEND ${_leftvar} "")
835 #LIST(APPEND ${_rightvar} "")
839 SET(_doing_right FALSE)
840 FOREACH(element ${ARGN})
841 IF("${element}" STREQUAL "${_keyword}")
842 SET(_doing_right TRUE)
843 ELSE("${element}" STREQUAL "${_keyword}")
845 LIST(APPEND ${_rightvar} "${element}")
847 LIST(APPEND ${_leftvar} "${element}")
849 ENDIF("${element}" STREQUAL "${_keyword}")
852 SET(${_leftvar} ${${_leftvar}} PARENT_SCOPE)
853 SET(${_rightvar} ${${_rightvar}} PARENT_SCOPE)
854 ENDFUNCTION(WX_SPLIT_ARGUMENTS_ON)
857 # WX_GET_DEPENDENCIES_FROM_XML(
865 # FIXME: Add documentation here...
867 FUNCTION(WX_GET_DEPENDENCIES_FROM_XML
875 STRING(REGEX MATCHALL
878 "${${_xml_contents}}"
880 FOREACH(dep_file ${dep_file_list})
881 STRING(REGEX REPLACE ${_clean_patt} "" dep_file "${dep_file}")
883 # make the file have an absolute path
884 IF(NOT IS_ABSOLUTE "${dep_file}")
885 SET(dep_file "${${_depends_path}}/${dep_file}")
886 ENDIF(NOT IS_ABSOLUTE "${dep_file}")
888 # append file to dependency list
889 LIST(APPEND ${_depends} "${dep_file}")
892 SET(${_depends} ${${_depends}} PARENT_SCOPE)
893 ENDFUNCTION(WX_GET_DEPENDENCIES_FROM_XML)
896 # WXWIDGETS_ADD_RESOURCES(<sources> <xrc_files>
897 # OPTIONS <options> [NO_CPP_CODE])
899 # Adds a custom command for resource file compilation of the
900 # <xrc_files> and appends the output files to <sources>.
903 # WXWIDGETS_ADD_RESOURCES(sources xrc/main_frame.xrc)
904 # WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o altname.cxx)
906 FUNCTION(WXWIDGETS_ADD_RESOURCES _outfiles)
907 WX_SPLIT_ARGUMENTS_ON(OPTIONS rc_file_list rc_options ${ARGN})
909 # Parse files for dependencies.
910 SET(rc_file_list_abs "")
912 FOREACH(rc_file ${rc_file_list})
913 GET_FILENAME_COMPONENT(depends_path ${rc_file} PATH)
915 GET_FILENAME_COMPONENT(rc_file_abs ${rc_file} ABSOLUTE)
916 LIST(APPEND rc_file_list_abs "${rc_file_abs}")
918 # All files have absolute paths or paths relative to the location
920 FILE(READ "${rc_file_abs}" rc_file_contents)
922 # get bitmap/bitmap2 files
923 WX_GET_DEPENDENCIES_FROM_XML(
932 WX_GET_DEPENDENCIES_FROM_XML(
941 WX_GET_DEPENDENCIES_FROM_XML(
943 "<object[^>]*class=\"wxIcon\"[^<]+"
953 # If NO_CPP_CODE option specified, then produce .xrs file rather
954 # than a .cpp file (i.e., don't add the default --cpp-code option).
955 LIST(FIND rc_options NO_CPP_CODE index)
957 LIST(APPEND rc_options --cpp-code)
958 # wxrc's default output filename for cpp code.
959 SET(outfile resource.cpp)
961 LIST(REMOVE_AT rc_options ${index})
962 # wxrc's default output filename for xrs file.
963 SET(outfile resource.xrs)
964 ENDIF(index EQUAL -1)
966 # Get output name for use in ADD_CUSTOM_COMMAND.
967 # - short option scanning
968 LIST(FIND rc_options -o index)
969 IF(NOT index EQUAL -1)
970 MATH(EXPR filename_index "${index} + 1")
971 LIST(GET rc_options ${filename_index} outfile)
972 #LIST(REMOVE_AT rc_options ${index} ${filename_index})
973 ENDIF(NOT index EQUAL -1)
974 # - long option scanning
975 STRING(REGEX MATCH "--output=[^;]*" outfile_opt "${rc_options}")
977 STRING(REPLACE "--output=" "" outfile "${outfile_opt}")
979 #STRING(REGEX REPLACE "--output=[^;]*;?" "" rc_options "${rc_options}")
980 #STRING(REGEX REPLACE ";$" "" rc_options "${rc_options}")
982 IF(NOT IS_ABSOLUTE "${outfile}")
983 SET(outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
984 ENDIF(NOT IS_ABSOLUTE "${outfile}")
987 COMMAND ${wxWidgets_wxrc_EXECUTABLE} ${rc_options} ${rc_file_list_abs}
988 DEPENDS ${rc_file_list_abs} ${rc_depends}
991 # Add generated header to output file list.
992 LIST(FIND rc_options -e short_index)
993 LIST(FIND rc_options --extra-cpp-code long_index)
994 IF(NOT short_index EQUAL -1 OR NOT long_index EQUAL -1)
995 GET_FILENAME_COMPONENT(outfile_ext ${outfile} EXT)
996 STRING(REPLACE "${outfile_ext}" ".h" outfile_header "${outfile}")
997 LIST(APPEND ${_outfiles} "${outfile_header}")
998 SET_SOURCE_FILES_PROPERTIES(
999 "${outfile_header}" PROPERTIES GENERATED TRUE
1001 ENDIF(NOT short_index EQUAL -1 OR NOT long_index EQUAL -1)
1003 # Add generated file to output file list.
1004 LIST(APPEND ${_outfiles} "${outfile}")
1006 SET(${_outfiles} ${${_outfiles}} PARENT_SCOPE)
1007 ENDFUNCTION(WXWIDGETS_ADD_RESOURCES)