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. -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.
51 # FIND_PACKAGE(wxWidgets COMPONENTS base core gl net)
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)
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})
65 # FIXME: check this and provide a correct sample usage...
66 # Remember to connect back to the upper text.
67 # Sample usage with monolithic wx build:
69 # FIND_PACKAGE(wxWidgets COMPONENTS mono)
75 # This module has been tested on the WIN32 platform with wxWidgets
76 # 2.6.2, 2.6.3, and 2.5.3. However, it has been designed to
77 # easily extend support to all possible builds, e.g., static/shared,
78 # debug/release, unicode, universal, multilib/monolithic, etc..
80 # If you want to use the module and your build type is not supported
81 # out-of-the-box, please contact me to exchange information on how
82 # your system is setup and I'll try to add support for it.
86 # Miguel A. Figueroa-Villanueva (miguelf at ieee dot org).
87 # Jan Woetzel (jw at mip.informatik.uni-kiel.de).
89 # Based on previous works of:
90 # Jan Woetzel (FindwxWindows.cmake),
91 # Jorgen Bodde and Jerry Fath (FindwxWin.cmake).
95 # (1) Option/Setting to use all available wx libs
96 # In contrast to expert developer who lists the
97 # minimal set of required libs in wxWidgets_USE_LIBS
98 # there is the newbie user:
99 # - who just wants to link against WX with more 'magic'
100 # - doesn't know the internal structure of WX or how it was built,
101 # in particular if it is monolithic or not
102 # - want to link against all available WX libs
103 # Basically, the intent here is to mimic what wx-config would do by
104 # default (i.e., `wx-config --libs`).
107 # Add a reserved keyword "std" that initializes to what wx-config
108 # would default to. If the user has not set the wxWidgets_USE_LIBS,
109 # default to "std" instead of "base core" as it is now. To implement
110 # "std" will basically boil down to a FOR_EACH lib-FOUND, but maybe
111 # checking whether a minimal set was found.
114 # FIXME: This and all the DBG_MSG calls should be removed after the
117 # Helper macro to control the debugging output globally. There are
118 # two versions for controlling how verbose your output should be.
121 # "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}")
123 MACRO(DBG_MSG_V _MSG)
125 # "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}")
128 # Clear return values in case the module is loaded more than once.
129 SET(wxWidgets_FOUND FALSE)
130 SET(wxWidgets_INCLUDE_DIRS "")
131 SET(wxWidgets_LIBRARIES "")
132 SET(wxWidgets_LIBRARY_DIRS "")
133 SET(wxWidgets_CXX_FLAGS "")
135 # Using SYSTEM with INCLUDE_DIRECTORIES in conjunction with wxWidgets on
136 # the Mac produces compiler errors. Set wxWidgets_INCLUDE_DIRS_NO_SYSTEM
137 # to prevent UsewxWidgets.cmake from using SYSTEM.
139 # See cmake mailing list discussions for more info:
140 # http://www.cmake.org/pipermail/cmake/2008-April/021115.html
141 # http://www.cmake.org/pipermail/cmake/2008-April/021146.html
144 SET(wxWidgets_INCLUDE_DIRS_NO_SYSTEM 1)
147 # DEPRECATED: This is a patch to support the DEPRECATED use of
148 # wxWidgets_USE_LIBS.
150 # If wxWidgets_USE_LIBS is set:
151 # - if using <components>, then override wxWidgets_USE_LIBS
152 # - else set wxWidgets_FIND_COMPONENTS to wxWidgets_USE_LIBS
153 IF(wxWidgets_USE_LIBS AND NOT wxWidgets_FIND_COMPONENTS)
154 SET(wxWidgets_FIND_COMPONENTS ${wxWidgets_USE_LIBS})
155 ENDIF(wxWidgets_USE_LIBS AND NOT wxWidgets_FIND_COMPONENTS)
156 DBG_MSG("wxWidgets_FIND_COMPONENTS : ${wxWidgets_FIND_COMPONENTS}")
158 # Add the convenience use file if available.
160 # Get dir of this file which may reside in:
161 # - CMAKE_MAKE_ROOT/Modules on CMake installation
162 # - CMAKE_MODULE_PATH if user prefers his own specialized version
163 SET(wxWidgets_USE_FILE "")
164 GET_FILENAME_COMPONENT(
165 wxWidgets_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
166 # Prefer an existing customized version, but the user might override
167 # the FindwxWidgets module and not the UsewxWidgets one.
168 IF(EXISTS "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
169 SET(wxWidgets_USE_FILE
170 "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
171 ELSE(EXISTS "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
172 SET(wxWidgets_USE_FILE UsewxWidgets.cmake)
173 ENDIF(EXISTS "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
175 #=====================================================================
176 #=====================================================================
177 IF(WIN32 AND NOT CYGWIN AND NOT MSYS)
178 SET(wxWidgets_FIND_STYLE "win32")
179 ELSE(WIN32 AND NOT CYGWIN AND NOT MSYS)
181 SET(wxWidgets_FIND_STYLE "unix")
183 ENDIF(WIN32 AND NOT CYGWIN AND NOT MSYS)
185 #=====================================================================
187 #=====================================================================
188 IF(wxWidgets_FIND_STYLE STREQUAL "win32")
189 # Useful common wx libs needed by almost all components.
190 SET(wxWidgets_COMMON_LIBRARIES png tiff jpeg zlib regex expat)
192 # DEPRECATED: Use FIND_PACKAGE(wxWidgets COMPONENTS mono) instead.
193 IF(NOT wxWidgets_FIND_COMPONENTS)
194 IF(wxWidgets_USE_MONOLITHIC)
195 SET(wxWidgets_FIND_COMPONENTS mono)
196 ELSE(wxWidgets_USE_MONOLITHIC)
197 SET(wxWidgets_FIND_COMPONENTS base core) # this is default
198 ENDIF(wxWidgets_USE_MONOLITHIC)
199 ENDIF(NOT wxWidgets_FIND_COMPONENTS)
201 # Always add the common required libs.
202 LIST(APPEND wxWidgets_FIND_COMPONENTS ${wxWidgets_COMMON_LIBRARIES})
204 #-------------------------------------------------------------------
205 # WIN32: Helper MACROS
206 #-------------------------------------------------------------------
208 # Get filename components for a configuration. For example,
209 # if _CONFIGURATION = mswunivud, then _UNV=univ, _UCD=u _DBG=d
210 # if _CONFIGURATION = mswu, then _UNV="", _UCD=u _DBG=""
212 MACRO(WX_GET_NAME_COMPONENTS _CONFIGURATION _UNV _UCD _DBG)
213 STRING(REGEX MATCH "univ" ${_UNV} "${_CONFIGURATION}")
214 STRING(REGEX REPLACE "msw.*(u)[d]*$" "u" ${_UCD} "${_CONFIGURATION}")
215 IF(${_UCD} STREQUAL ${_CONFIGURATION})
217 ENDIF(${_UCD} STREQUAL ${_CONFIGURATION})
218 STRING(REGEX MATCH "d$" ${_DBG} "${_CONFIGURATION}")
219 ENDMACRO(WX_GET_NAME_COMPONENTS)
222 # Find libraries associated to a configuration.
224 MACRO(WX_FIND_LIBS _UNV _UCD _DBG)
225 DBG_MSG_V("m_unv = ${_UNV}")
226 DBG_MSG_V("m_ucd = ${_UCD}")
227 DBG_MSG_V("m_dbg = ${_DBG}")
229 # FIXME: What if both regex libs are available. regex should be
230 # found outside the loop and only wx${LIB}${_UCD}${_DBG}.
231 # Find wxWidgets common libraries.
232 FOREACH(LIB ${wxWidgets_COMMON_LIBRARIES})
233 FIND_LIBRARY(WX_${LIB}${_DBG}
235 wx${LIB}${_UCD}${_DBG} # for regex
240 MARK_AS_ADVANCED(WX_${LIB}${_DBG})
243 # Find wxWidgets multilib base libraries.
244 FIND_LIBRARY(WX_base${_DBG}
246 wxbase29${_UCD}${_DBG}
247 wxbase28${_UCD}${_DBG}
248 wxbase27${_UCD}${_DBG}
249 wxbase26${_UCD}${_DBG}
250 wxbase25${_UCD}${_DBG}
254 MARK_AS_ADVANCED(WX_base${_DBG})
255 FOREACH(LIB net odbc xml)
256 FIND_LIBRARY(WX_${LIB}${_DBG}
258 wxbase29${_UCD}${_DBG}_${LIB}
259 wxbase28${_UCD}${_DBG}_${LIB}
260 wxbase27${_UCD}${_DBG}_${LIB}
261 wxbase26${_UCD}${_DBG}_${LIB}
262 wxbase25${_UCD}${_DBG}_${LIB}
266 MARK_AS_ADVANCED(WX_${LIB}${_DBG})
269 # Find wxWidgets monolithic library.
270 FIND_LIBRARY(WX_mono${_DBG}
272 wxmsw${_UNV}29${_UCD}${_DBG}
273 wxmsw${_UNV}28${_UCD}${_DBG}
274 wxmsw${_UNV}27${_UCD}${_DBG}
275 wxmsw${_UNV}26${_UCD}${_DBG}
276 wxmsw${_UNV}25${_UCD}${_DBG}
280 MARK_AS_ADVANCED(WX_mono${_DBG})
282 # Find wxWidgets multilib libraries.
283 FOREACH(LIB core adv aui html media xrc dbgrid gl qa richtext)
284 FIND_LIBRARY(WX_${LIB}${_DBG}
286 wxmsw${_UNV}29${_UCD}${_DBG}_${LIB}
287 wxmsw${_UNV}28${_UCD}${_DBG}_${LIB}
288 wxmsw${_UNV}27${_UCD}${_DBG}_${LIB}
289 wxmsw${_UNV}26${_UCD}${_DBG}_${LIB}
290 wxmsw${_UNV}25${_UCD}${_DBG}_${LIB}
294 MARK_AS_ADVANCED(WX_${LIB}${_DBG})
296 ENDMACRO(WX_FIND_LIBS)
299 # Clear all library paths, so that FIND_LIBRARY refinds them.
301 # Clear a lib, reset its found flag, and mark as advanced.
302 MACRO(WX_CLEAR_LIB _LIB)
303 SET(${_LIB} "${_LIB}-NOTFOUND" CACHE FILEPATH "Cleared." FORCE)
304 SET(${_LIB}_FOUND FALSE)
305 MARK_AS_ADVANCED(${_LIB})
306 ENDMACRO(WX_CLEAR_LIB)
307 # Clear all debug or release library paths (arguments are "d" or "").
308 MACRO(WX_CLEAR_ALL_LIBS _DBG)
309 # Clear wxWidgets common libraries.
310 FOREACH(LIB ${wxWidgets_COMMON_LIBRARIES})
311 WX_CLEAR_LIB(WX_${LIB}${_DBG})
314 # Clear wxWidgets multilib base libraries.
315 WX_CLEAR_LIB(WX_base${_DBG})
316 FOREACH(LIB net odbc xml)
317 WX_CLEAR_LIB(WX_${LIB}${_DBG})
320 # Clear wxWidgets monolithic library.
321 WX_CLEAR_LIB(WX_mono${_DBG})
323 # Clear wxWidgets multilib libraries.
324 FOREACH(LIB core adv aui html media xrc dbgrid gl qa richtext)
325 WX_CLEAR_LIB(WX_${LIB}${_DBG})
327 ENDMACRO(WX_CLEAR_ALL_LIBS)
328 # Clear all wxWidgets debug libraries.
329 MACRO(WX_CLEAR_ALL_DBG_LIBS)
330 WX_CLEAR_ALL_LIBS("d")
331 ENDMACRO(WX_CLEAR_ALL_DBG_LIBS)
332 # Clear all wxWidgets release libraries.
333 MACRO(WX_CLEAR_ALL_REL_LIBS)
334 WX_CLEAR_ALL_LIBS("")
335 ENDMACRO(WX_CLEAR_ALL_REL_LIBS)
338 # Set the wxWidgets_LIBRARIES variable.
339 # Also, Sets output variable wxWidgets_FOUND to FALSE if it fails.
341 MACRO(WX_SET_LIBRARIES _LIBS _DBG)
342 DBG_MSG_V("Looking for ${${_LIBS}}")
343 IF(WX_USE_REL_AND_DBG)
344 FOREACH(LIB ${${_LIBS}})
345 DBG_MSG_V("Searching for ${LIB} and ${LIB}d")
346 DBG_MSG_V("WX_${LIB} : ${WX_${LIB}}")
347 DBG_MSG_V("WX_${LIB}d : ${WX_${LIB}d}")
348 IF(WX_${LIB} AND WX_${LIB}d)
349 DBG_MSG_V("Found ${LIB} and ${LIB}d")
350 LIST(APPEND wxWidgets_LIBRARIES
351 debug ${WX_${LIB}d} optimized ${WX_${LIB}}
353 ELSE(WX_${LIB} AND WX_${LIB}d)
354 DBG_MSG_V("- not found due to missing WX_${LIB}=${WX_${LIB}} or WX_${LIB}d=${WX_${LIB}d}")
355 SET(wxWidgets_FOUND FALSE)
356 ENDIF(WX_${LIB} AND WX_${LIB}d)
358 ELSE(WX_USE_REL_AND_DBG)
359 FOREACH(LIB ${${_LIBS}})
360 DBG_MSG_V("Searching for ${LIB}${_DBG}")
361 DBG_MSG_V("WX_${LIB}${_DBG} : ${WX_${LIB}${_DBG}}")
363 DBG_MSG_V("Found ${LIB}${_DBG}")
364 LIST(APPEND wxWidgets_LIBRARIES ${WX_${LIB}${_DBG}})
365 ELSE(WX_${LIB}${_DBG})
367 "- not found due to missing WX_${LIB}${_DBG}=${WX_${LIB}${_DBG}}")
368 SET(wxWidgets_FOUND FALSE)
369 ENDIF(WX_${LIB}${_DBG})
371 ENDIF(WX_USE_REL_AND_DBG)
374 LIST(FIND ${_LIBS} gl WX_USE_GL)
375 IF(NOT WX_USE_GL EQUAL -1)
376 DBG_MSG_V("- is required.")
377 LIST(APPEND wxWidgets_LIBRARIES opengl32 glu32)
378 ENDIF(NOT WX_USE_GL EQUAL -1)
380 LIST(APPEND wxWidgets_LIBRARIES winmm comctl32 rpcrt4 wsock32)
381 ENDMACRO(WX_SET_LIBRARIES)
383 #-------------------------------------------------------------------
384 # WIN32: Start actual work.
385 #-------------------------------------------------------------------
387 # Look for an installation tree.
388 FIND_PATH(wxWidgets_ROOT_DIR
389 NAMES include/wx/wx.h
391 $ENV{wxWidgets_ROOT_DIR}
393 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\wxWidgets_is1;Inno Setup: App Path]" # WX 2.6.x
428 DOC "wxWidgets base/installation directory?"
431 # If wxWidgets_ROOT_DIR changed, clear lib dir.
432 IF(NOT WX_ROOT_DIR STREQUAL wxWidgets_ROOT_DIR)
433 SET(WX_ROOT_DIR ${wxWidgets_ROOT_DIR}
434 CACHE INTERNAL "wxWidgets_ROOT_DIR")
435 SET(wxWidgets_LIB_DIR "wxWidgets_LIB_DIR-NOTFOUND"
436 CACHE PATH "Cleared." FORCE)
437 ENDIF(NOT WX_ROOT_DIR STREQUAL wxWidgets_ROOT_DIR)
440 # Select one default tree inside the already determined wx tree.
441 # Prefer static/shared order usually consistent with build
444 SET(WX_LIB_DIR_PREFIX gcc)
446 SET(WX_LIB_DIR_PREFIX vc)
448 IF(BUILD_SHARED_LIBS)
449 FIND_PATH(wxWidgets_LIB_DIR
460 ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_dll # prefer shared
461 ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_lib
462 DOC "Path to wxWidgets libraries?"
465 ELSE(BUILD_SHARED_LIBS)
466 FIND_PATH(wxWidgets_LIB_DIR
477 ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_lib # prefer static
478 ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_dll
479 DOC "Path to wxWidgets libraries?"
482 ENDIF(BUILD_SHARED_LIBS)
484 # If wxWidgets_LIB_DIR changed, clear all libraries.
485 IF(NOT WX_LIB_DIR STREQUAL wxWidgets_LIB_DIR)
486 SET(WX_LIB_DIR ${wxWidgets_LIB_DIR} CACHE INTERNAL "wxWidgets_LIB_DIR")
487 WX_CLEAR_ALL_DBG_LIBS()
488 WX_CLEAR_ALL_REL_LIBS()
489 ENDIF(NOT WX_LIB_DIR STREQUAL wxWidgets_LIB_DIR)
492 SET(wxWidgets_FOUND TRUE)
494 # If building shared libs, define WXUSINGDLL to use dllimport.
495 IF(WX_LIB_DIR MATCHES ".*[dD][lL][lL].*")
496 SET(wxWidgets_DEFINITIONS "-DWXUSINGDLL")
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 # If the selected configuration wasn't found force the default
513 # one. Otherwise, use it but still force a refresh for
514 # updating the doc string with the current list of available
516 IF(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
517 SET(wxWidgets_CONFIGURATION ${WX_CONFIGURATION} CACHE STRING
518 "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
519 ELSE(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
520 SET(wxWidgets_CONFIGURATION ${wxWidgets_CONFIGURATION} CACHE STRING
521 "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
522 ENDIF(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
524 # If release config selected, and both release/debug exist.
525 IF(WX_${wxWidgets_CONFIGURATION}d_FOUND)
526 OPTION(wxWidgets_USE_REL_AND_DBG
527 "Use release and debug configurations?" TRUE)
528 SET(WX_USE_REL_AND_DBG ${wxWidgets_USE_REL_AND_DBG})
529 ELSE(WX_${wxWidgets_CONFIGURATION}d_FOUND)
530 # If the option exists (already in cache), force it false.
531 IF(wxWidgets_USE_REL_AND_DBG)
532 SET(wxWidgets_USE_REL_AND_DBG FALSE CACHE BOOL
533 "No ${wxWidgets_CONFIGURATION}d found." FORCE)
534 ENDIF(wxWidgets_USE_REL_AND_DBG)
535 SET(WX_USE_REL_AND_DBG FALSE)
536 ENDIF(WX_${wxWidgets_CONFIGURATION}d_FOUND)
538 # Get configuration parameters from the name.
539 WX_GET_NAME_COMPONENTS(${wxWidgets_CONFIGURATION} UNV UCD DBG)
541 # Set wxWidgets main include directory.
542 IF(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
543 SET(wxWidgets_INCLUDE_DIRS ${WX_ROOT_DIR}/include)
544 ELSE(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
545 DBG_MSG("wxWidgets_FOUND FALSE because WX_ROOT_DIR=${WX_ROOT_DIR} has no ${WX_ROOT_DIR}/include/wx/wx.h")
546 SET(wxWidgets_FOUND FALSE)
547 ENDIF(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
549 # Set wxWidgets lib setup include directory.
550 IF(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
551 LIST(APPEND wxWidgets_INCLUDE_DIRS
552 ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION})
553 ELSE(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
554 DBG_MSG("WXWIDGET_FOUND FALSE because ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h does not exists.")
555 SET(wxWidgets_FOUND FALSE)
556 ENDIF(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
558 # Find wxWidgets libraries.
559 WX_FIND_LIBS("${UNV}" "${UCD}" "${DBG}")
560 IF(WX_USE_REL_AND_DBG)
561 WX_FIND_LIBS("${UNV}" "${UCD}" "d")
562 ENDIF(WX_USE_REL_AND_DBG)
564 # Settings for requested libs (i.e., include dir, libraries, etc.).
565 WX_SET_LIBRARIES(wxWidgets_FIND_COMPONENTS "${DBG}")
567 ENDIF(WX_CONFIGURATION)
571 #=====================================================================
573 #=====================================================================
574 ELSE(wxWidgets_FIND_STYLE STREQUAL "win32")
575 IF(wxWidgets_FIND_STYLE STREQUAL "unix")
576 #-----------------------------------------------------------------
577 # UNIX: Helper MACROS
578 #-----------------------------------------------------------------
580 # Set the default values based on "wx-config --selected-config".
582 MACRO(WX_CONFIG_SELECT_GET_DEFAULT)
584 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --selected-config
585 OUTPUT_VARIABLE _wx_selected_config
586 RESULT_VARIABLE _wx_result
589 IF(_wx_result EQUAL 0)
590 FOREACH(_opt_name debug static unicode universal)
591 STRING(TOUPPER ${_opt_name} _upper_opt_name)
592 IF(_wx_selected_config MATCHES ".*${_opt_name}.*")
593 SET(wxWidgets_DEFAULT_${_upper_opt_name} ON)
594 ELSE(_wx_selected_config MATCHES ".*${_opt_name}.*")
595 SET(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
596 ENDIF(_wx_selected_config MATCHES ".*${_opt_name}.*")
597 ENDFOREACH(_opt_name)
598 ELSE(_wx_result EQUAL 0)
599 FOREACH(_upper_opt_name DEBUG STATIC UNICODE UNIVERSAL)
600 SET(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
601 ENDFOREACH(_upper_opt_name)
602 ENDIF(_wx_result EQUAL 0)
603 ENDMACRO(WX_CONFIG_SELECT_GET_DEFAULT)
606 # Query a boolean configuration option to determine if the system
607 # has both builds available. If so, provide the selection option
610 MACRO(WX_CONFIG_SELECT_QUERY_BOOL _OPT_NAME _OPT_HELP)
612 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --${_OPT_NAME}=yes
613 RESULT_VARIABLE _wx_result_yes
618 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --${_OPT_NAME}=no
619 RESULT_VARIABLE _wx_result_no
623 STRING(TOUPPER ${_OPT_NAME} _UPPER_OPT_NAME)
624 IF(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
625 OPTION(wxWidgets_USE_${_UPPER_OPT_NAME}
626 ${_OPT_HELP} ${wxWidgets_DEFAULT_${_UPPER_OPT_NAME}})
627 ELSE(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
628 # If option exists (already in cache), force to available one.
629 IF(DEFINED wxWidgets_USE_${_UPPER_OPT_NAME})
630 IF(_wx_result_yes EQUAL 0)
631 SET(wxWidgets_USE_${_UPPER_OPT_NAME} ON CACHE BOOL ${_OPT_HELP} FORCE)
632 ELSE(_wx_result_yes EQUAL 0)
633 SET(wxWidgets_USE_${_UPPER_OPT_NAME} OFF CACHE BOOL ${_OPT_HELP} FORCE)
634 ENDIF(_wx_result_yes EQUAL 0)
635 ENDIF(DEFINED wxWidgets_USE_${_UPPER_OPT_NAME})
636 ENDIF(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
637 ENDMACRO(WX_CONFIG_SELECT_QUERY_BOOL)
640 # Set wxWidgets_SELECT_OPTIONS to wx-config options for selecting
641 # among multiple builds.
643 MACRO(WX_CONFIG_SELECT_SET_OPTIONS)
644 SET(wxWidgets_SELECT_OPTIONS "")
645 FOREACH(_opt_name debug static unicode universal)
646 STRING(TOUPPER ${_opt_name} _upper_opt_name)
647 IF(DEFINED wxWidgets_USE_${_upper_opt_name})
648 IF(wxWidgets_USE_${_upper_opt_name})
649 LIST(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=yes)
650 ELSE(wxWidgets_USE_${_upper_opt_name})
651 LIST(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=no)
652 ENDIF(wxWidgets_USE_${_upper_opt_name})
653 ENDIF(DEFINED wxWidgets_USE_${_upper_opt_name})
654 ENDFOREACH(_opt_name)
655 ENDMACRO(WX_CONFIG_SELECT_SET_OPTIONS)
657 #-----------------------------------------------------------------
658 # UNIX: Start actual work.
659 #-----------------------------------------------------------------
660 # Support cross-compiling, only search in the target platform.
661 FIND_PROGRAM(wxWidgets_CONFIG_EXECUTABLE wx-config
662 ONLY_CMAKE_FIND_ROOT_PATH
665 IF(wxWidgets_CONFIG_EXECUTABLE)
666 SET(wxWidgets_FOUND TRUE)
668 # get defaults based on "wx-config --selected-config"
669 WX_CONFIG_SELECT_GET_DEFAULT()
671 # for each option: if both builds are available, provide option
672 WX_CONFIG_SELECT_QUERY_BOOL(debug "Use debug build?")
673 WX_CONFIG_SELECT_QUERY_BOOL(unicode "Use unicode build?")
674 WX_CONFIG_SELECT_QUERY_BOOL(universal "Use universal build?")
675 WX_CONFIG_SELECT_QUERY_BOOL(static "Link libraries statically?")
677 # process selection to set wxWidgets_SELECT_OPTIONS
678 WX_CONFIG_SELECT_SET_OPTIONS()
679 DBG_MSG("wxWidgets_SELECT_OPTIONS=${wxWidgets_SELECT_OPTIONS}")
681 # run the wx-config program to get cxxflags
683 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
684 ${wxWidgets_SELECT_OPTIONS} --cxxflags
685 OUTPUT_VARIABLE wxWidgets_CXX_FLAGS
690 STRING(STRIP "${wxWidgets_CXX_FLAGS}" wxWidgets_CXX_FLAGS)
691 SEPARATE_ARGUMENTS(wxWidgets_CXX_FLAGS)
693 DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
695 # parse definitions from cxxflags; drop -D* from CXXFLAGS
696 STRING(REGEX MATCHALL "-D[^;]+"
697 wxWidgets_DEFINITIONS "${wxWidgets_CXX_FLAGS}")
698 STRING(REGEX REPLACE "-D[^;]+;" ""
699 wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
701 # parse include dirs from cxxflags; drop -I prefix
702 STRING(REGEX MATCHALL "-I[^;]+"
703 wxWidgets_INCLUDE_DIRS "${wxWidgets_CXX_FLAGS}")
704 STRING(REGEX REPLACE "-I[^;]+;" ""
705 wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
706 STRING(REPLACE "-I" ""
707 wxWidgets_INCLUDE_DIRS "${wxWidgets_INCLUDE_DIRS}")
709 DBG_MSG_V("wxWidgets_DEFINITIONS=${wxWidgets_DEFINITIONS}")
710 DBG_MSG_V("wxWidgets_INCLUDE_DIRS=${wxWidgets_INCLUDE_DIRS}")
711 DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
714 SET(wxWidgets_FOUND FALSE)
716 "${wxWidgets_CONFIG_EXECUTABLE} --cxxflags FAILED with RET=${RET}")
719 # run the wx-config program to get the libs
720 # - NOTE: wx-config doesn't verify that the libs requested exist
721 # it just produces the names. Maybe a TRY_COMPILE would
723 STRING(REPLACE ";" ","
724 wxWidgets_FIND_COMPONENTS "${wxWidgets_FIND_COMPONENTS}")
726 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
727 ${wxWidgets_SELECT_OPTIONS} --libs ${wxWidgets_FIND_COMPONENTS}
728 OUTPUT_VARIABLE wxWidgets_LIBRARIES
733 STRING(STRIP "${wxWidgets_LIBRARIES}" wxWidgets_LIBRARIES)
734 SEPARATE_ARGUMENTS(wxWidgets_LIBRARIES)
735 STRING(REPLACE "-framework;" "-framework "
736 wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
737 STRING(REPLACE "-arch;" "-arch "
738 wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
739 STRING(REPLACE "-isysroot;" "-isysroot "
740 wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
742 # extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES)
743 STRING(REGEX MATCHALL "-L[^;]+"
744 wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARIES}")
745 STRING(REPLACE "-L" ""
746 wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARY_DIRS}")
748 DBG_MSG_V("wxWidgets_LIBRARIES=${wxWidgets_LIBRARIES}")
749 DBG_MSG_V("wxWidgets_LIBRARY_DIRS=${wxWidgets_LIBRARY_DIRS}")
752 SET(wxWidgets_FOUND FALSE)
753 DBG_MSG("${wxWidgets_CONFIG_EXECUTABLE} --libs ${wxWidgets_FIND_COMPONENTS} FAILED with RET=${RET}")
755 ENDIF(wxWidgets_CONFIG_EXECUTABLE)
757 #=====================================================================
758 # Neither UNIX_FIND_STYLE, nor WIN32_FIND_STYLE
759 #=====================================================================
760 ELSE(wxWidgets_FIND_STYLE STREQUAL "unix")
761 IF(NOT wxWidgets_FIND_QUIETLY)
763 "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): \n"
764 " Platform unknown/unsupported. It's neither WIN32 nor UNIX "
767 ENDIF(NOT wxWidgets_FIND_QUIETLY)
768 ENDIF(wxWidgets_FIND_STYLE STREQUAL "unix")
769 ENDIF(wxWidgets_FIND_STYLE STREQUAL "win32")
772 DBG_MSG("wxWidgets_FOUND : ${wxWidgets_FOUND}")
773 DBG_MSG("wxWidgets_INCLUDE_DIRS : ${wxWidgets_INCLUDE_DIRS}")
774 DBG_MSG("wxWidgets_LIBRARY_DIRS : ${wxWidgets_LIBRARY_DIRS}")
775 DBG_MSG("wxWidgets_LIBRARIES : ${wxWidgets_LIBRARIES}")
776 DBG_MSG("wxWidgets_CXX_FLAGS : ${wxWidgets_CXX_FLAGS}")
777 DBG_MSG("wxWidgets_USE_FILE : ${wxWidgets_USE_FILE}")
779 #=====================================================================
780 #=====================================================================
781 INCLUDE(FindPackageHandleStandardArgs)
782 FIND_PACKAGE_HANDLE_STANDARD_ARGS(wxWidgets DEFAULT_MSG wxWidgets_FOUND)
783 # Maintain consistency with all other variables.
784 SET(wxWidgets_FOUND ${WXWIDGETS_FOUND})
786 #=====================================================================
787 # Macros for use in wxWidgets apps.
788 # - This module will not fail to find wxWidgets based on the code
789 # below. Hence, it's required to check for validity of:
791 # wxWidgets_wxrc_EXECUTABLE
792 #=====================================================================
794 # Resource file compiler.
795 FIND_PROGRAM(wxWidgets_wxrc_EXECUTABLE wxrc
796 ${wxWidgets_ROOT_DIR}/utils/wxrc/vc_msw
800 # WX_SPLIT_ARGUMENTS_ON(<keyword> <left> <right> <arg1> <arg2> ...)
802 # Sets <left> and <right> to contain arguments to the left and right,
803 # respectively, of <keyword>.
806 # FUNCTION(WXWIDGETS_ADD_RESOURCES outfiles)
807 # WX_SPLIT_ARGUMENTS_ON(OPTIONS wxrc_files wxrc_options ${ARGN})
809 # ENDFUNCTION(WXWIDGETS_ADD_RESOURCES)
811 # WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o file.C)
813 # NOTE: This is a generic piece of code that should be renamed to
814 # SPLIT_ARGUMENTS_ON and put in a file serving the same purpose as
815 # FindPackageStandardArgs.cmake. At the time of this writing
816 # FindQt4.cmake has a QT4_EXTRACT_OPTIONS, which I basically copied
817 # here a bit more generalized. So, there are already two find modules
818 # using this approach.
820 FUNCTION(WX_SPLIT_ARGUMENTS_ON _keyword _leftvar _rightvar)
821 # FIXME: Document that the input variables will be cleared.
822 #LIST(APPEND ${_leftvar} "")
823 #LIST(APPEND ${_rightvar} "")
827 SET(_doing_right FALSE)
828 FOREACH(element ${ARGN})
829 IF("${element}" STREQUAL "${_keyword}")
830 SET(_doing_right TRUE)
831 ELSE("${element}" STREQUAL "${_keyword}")
833 LIST(APPEND ${_rightvar} "${element}")
835 LIST(APPEND ${_leftvar} "${element}")
837 ENDIF("${element}" STREQUAL "${_keyword}")
840 SET(${_leftvar} ${${_leftvar}} PARENT_SCOPE)
841 SET(${_rightvar} ${${_rightvar}} PARENT_SCOPE)
842 ENDFUNCTION(WX_SPLIT_ARGUMENTS_ON)
845 # WX_GET_DEPENDENCIES_FROM_XML(
853 # FIXME: Add documentation here...
855 FUNCTION(WX_GET_DEPENDENCIES_FROM_XML
863 STRING(REGEX MATCHALL
866 "${${_xml_contents}}"
868 FOREACH(dep_file ${dep_file_list})
869 STRING(REGEX REPLACE ${_clean_patt} "" dep_file "${dep_file}")
871 # make the file have an absolute path
872 IF(NOT IS_ABSOLUTE "${dep_file}")
873 SET(dep_file "${${_depends_path}}/${dep_file}")
874 ENDIF(NOT IS_ABSOLUTE "${dep_file}")
876 # append file to dependency list
877 LIST(APPEND ${_depends} "${dep_file}")
880 SET(${_depends} ${${_depends}} PARENT_SCOPE)
881 ENDFUNCTION(WX_GET_DEPENDENCIES_FROM_XML)
884 # WXWIDGETS_ADD_RESOURCES(<sources> <xrc_files>
885 # OPTIONS <options> [NO_CPP_CODE])
887 # Adds a custom command for resource file compilation of the
888 # <xrc_files> and appends the output files to <sources>.
891 # WXWIDGETS_ADD_RESOURCES(sources xrc/main_frame.xrc)
892 # WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o altname.cxx)
894 FUNCTION(WXWIDGETS_ADD_RESOURCES _outfiles)
895 WX_SPLIT_ARGUMENTS_ON(OPTIONS rc_file_list rc_options ${ARGN})
897 # Parse files for dependencies.
898 SET(rc_file_list_abs "")
900 FOREACH(rc_file ${rc_file_list})
901 GET_FILENAME_COMPONENT(depends_path ${rc_file} PATH)
903 GET_FILENAME_COMPONENT(rc_file_abs ${rc_file} ABSOLUTE)
904 LIST(APPEND rc_file_list_abs "${rc_file_abs}")
906 # All files have absolute paths or paths relative to the location
908 FILE(READ "${rc_file_abs}" rc_file_contents)
910 # get bitmap/bitmap2 files
911 WX_GET_DEPENDENCIES_FROM_XML(
920 WX_GET_DEPENDENCIES_FROM_XML(
929 WX_GET_DEPENDENCIES_FROM_XML(
931 "<object[^>]*class=\"wxIcon\"[^<]+"
941 # If NO_CPP_CODE option specified, then produce .xrs file rather
942 # than a .cpp file (i.e., don't add the default --cpp-code option).
943 LIST(FIND rc_options NO_CPP_CODE index)
945 LIST(APPEND rc_options --cpp-code)
946 # wxrc's default output filename for cpp code.
947 SET(outfile resource.cpp)
949 LIST(REMOVE_AT rc_options ${index})
950 # wxrc's default output filename for xrs file.
951 SET(outfile resource.xrs)
952 ENDIF(index EQUAL -1)
954 # Get output name for use in ADD_CUSTOM_COMMAND.
955 # - short option scanning
956 LIST(FIND rc_options -o index)
957 IF(NOT index EQUAL -1)
958 MATH(EXPR filename_index "${index} + 1")
959 LIST(GET rc_options ${filename_index} outfile)
960 #LIST(REMOVE_AT rc_options ${index} ${filename_index})
961 ENDIF(NOT index EQUAL -1)
962 # - long option scanning
963 STRING(REGEX MATCH "--output=[^;]*" outfile_opt "${rc_options}")
965 STRING(REPLACE "--output=" "" outfile "${outfile_opt}")
967 #STRING(REGEX REPLACE "--output=[^;]*;?" "" rc_options "${rc_options}")
968 #STRING(REGEX REPLACE ";$" "" rc_options "${rc_options}")
970 IF(NOT IS_ABSOLUTE "${outfile}")
971 SET(outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
972 ENDIF(NOT IS_ABSOLUTE "${outfile}")
975 COMMAND ${wxWidgets_wxrc_EXECUTABLE} ${rc_options} ${rc_file_list_abs}
976 DEPENDS ${rc_file_list_abs} ${rc_depends}
979 # Add generated header to output file list.
980 LIST(FIND rc_options -e short_index)
981 LIST(FIND rc_options --extra-cpp-code long_index)
982 IF(NOT short_index EQUAL -1 OR NOT long_index EQUAL -1)
983 GET_FILENAME_COMPONENT(outfile_ext ${outfile} EXT)
984 STRING(REPLACE "${outfile_ext}" ".h" outfile_header "${outfile}")
985 LIST(APPEND ${_outfiles} "${outfile_header}")
986 SET_SOURCE_FILES_PROPERTIES(
987 "${outfile_header}" PROPERTIES GENERATED TRUE
989 ENDIF(NOT short_index EQUAL -1 OR NOT long_index EQUAL -1)
991 # Add generated file to output file list.
992 LIST(APPEND ${_outfiles} "${outfile}")
994 SET(${_outfiles} ${${_outfiles}} PARENT_SCOPE)
995 ENDFUNCTION(WXWIDGETS_ADD_RESOURCES)