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
427 DOC "wxWidgets base/installation directory?"
430 # If wxWidgets_ROOT_DIR changed, clear lib dir.
431 IF(NOT WX_ROOT_DIR STREQUAL wxWidgets_ROOT_DIR)
432 SET(WX_ROOT_DIR ${wxWidgets_ROOT_DIR}
433 CACHE INTERNAL "wxWidgets_ROOT_DIR")
434 SET(wxWidgets_LIB_DIR "wxWidgets_LIB_DIR-NOTFOUND"
435 CACHE PATH "Cleared." FORCE)
436 ENDIF(NOT WX_ROOT_DIR STREQUAL wxWidgets_ROOT_DIR)
439 # Select one default tree inside the already determined wx tree.
440 # Prefer static/shared order usually consistent with build
443 SET(WX_LIB_DIR_PREFIX gcc)
445 SET(WX_LIB_DIR_PREFIX vc)
447 IF(BUILD_SHARED_LIBS)
448 FIND_PATH(wxWidgets_LIB_DIR
449 NAMES msw/build.cfg mswd/build.cfg
451 ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_dll # prefer shared
452 ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_lib
453 DOC "Path to wxWidgets libraries?"
456 ELSE(BUILD_SHARED_LIBS)
457 FIND_PATH(wxWidgets_LIB_DIR
458 NAMES msw/build.cfg mswd/build.cfg
460 ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_lib # prefer static
461 ${WX_ROOT_DIR}/lib/${WX_LIB_DIR_PREFIX}_dll
462 DOC "Path to wxWidgets libraries?"
465 ENDIF(BUILD_SHARED_LIBS)
467 # If wxWidgets_LIB_DIR changed, clear all libraries.
468 IF(NOT WX_LIB_DIR STREQUAL wxWidgets_LIB_DIR)
469 SET(WX_LIB_DIR ${wxWidgets_LIB_DIR} CACHE INTERNAL "wxWidgets_LIB_DIR")
470 WX_CLEAR_ALL_DBG_LIBS()
471 WX_CLEAR_ALL_REL_LIBS()
472 ENDIF(NOT WX_LIB_DIR STREQUAL wxWidgets_LIB_DIR)
475 SET(wxWidgets_FOUND TRUE)
477 # If building shared libs, define WXUSINGDLL to use dllimport.
478 IF(WX_LIB_DIR MATCHES ".*[dD][lL][lL].*")
479 SET(wxWidgets_DEFINITIONS "-DWXUSINGDLL")
480 DBG_MSG_V("detected SHARED/DLL tree WX_LIB_DIR=${WX_LIB_DIR}")
481 ENDIF(WX_LIB_DIR MATCHES ".*[dD][lL][lL].*")
483 # Search for available configuration types.
484 FOREACH(CFG mswunivud mswunivd mswud mswd mswunivu mswuniv mswu msw)
485 SET(WX_${CFG}_FOUND FALSE)
486 IF(EXISTS ${WX_LIB_DIR}/${CFG})
487 LIST(APPEND WX_CONFIGURATION_LIST ${CFG})
488 SET(WX_${CFG}_FOUND TRUE)
489 SET(WX_CONFIGURATION ${CFG})
490 ENDIF(EXISTS ${WX_LIB_DIR}/${CFG})
492 DBG_MSG_V("WX_CONFIGURATION_LIST=${WX_CONFIGURATION_LIST}")
495 # If the selected configuration wasn't found force the default
496 # one. Otherwise, use it but still force a refresh for
497 # updating the doc string with the current list of available
499 IF(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
500 SET(wxWidgets_CONFIGURATION ${WX_CONFIGURATION} CACHE STRING
501 "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
502 ELSE(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
503 SET(wxWidgets_CONFIGURATION ${wxWidgets_CONFIGURATION} CACHE STRING
504 "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
505 ENDIF(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
507 # If release config selected, and both release/debug exist.
508 IF(WX_${wxWidgets_CONFIGURATION}d_FOUND)
509 OPTION(wxWidgets_USE_REL_AND_DBG
510 "Use release and debug configurations?" TRUE)
511 SET(WX_USE_REL_AND_DBG ${wxWidgets_USE_REL_AND_DBG})
512 ELSE(WX_${wxWidgets_CONFIGURATION}d_FOUND)
513 # If the option exists (already in cache), force it false.
514 IF(wxWidgets_USE_REL_AND_DBG)
515 SET(wxWidgets_USE_REL_AND_DBG FALSE CACHE BOOL
516 "No ${wxWidgets_CONFIGURATION}d found." FORCE)
517 ENDIF(wxWidgets_USE_REL_AND_DBG)
518 SET(WX_USE_REL_AND_DBG FALSE)
519 ENDIF(WX_${wxWidgets_CONFIGURATION}d_FOUND)
521 # Get configuration parameters from the name.
522 WX_GET_NAME_COMPONENTS(${wxWidgets_CONFIGURATION} UNV UCD DBG)
524 # Set wxWidgets main include directory.
525 IF(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
526 SET(wxWidgets_INCLUDE_DIRS ${WX_ROOT_DIR}/include)
527 ELSE(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
528 DBG_MSG("wxWidgets_FOUND FALSE because WX_ROOT_DIR=${WX_ROOT_DIR} has no ${WX_ROOT_DIR}/include/wx/wx.h")
529 SET(wxWidgets_FOUND FALSE)
530 ENDIF(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
532 # Set wxWidgets lib setup include directory.
533 IF(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
534 LIST(APPEND wxWidgets_INCLUDE_DIRS
535 ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION})
536 ELSE(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
537 DBG_MSG("WXWIDGET_FOUND FALSE because ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h does not exists.")
538 SET(wxWidgets_FOUND FALSE)
539 ENDIF(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
541 # Find wxWidgets libraries.
542 WX_FIND_LIBS("${UNV}" "${UCD}" "${DBG}")
543 IF(WX_USE_REL_AND_DBG)
544 WX_FIND_LIBS("${UNV}" "${UCD}" "d")
545 ENDIF(WX_USE_REL_AND_DBG)
547 # Settings for requested libs (i.e., include dir, libraries, etc.).
548 WX_SET_LIBRARIES(wxWidgets_FIND_COMPONENTS "${DBG}")
550 ENDIF(WX_CONFIGURATION)
554 #=====================================================================
556 #=====================================================================
557 ELSE(wxWidgets_FIND_STYLE STREQUAL "win32")
558 IF(wxWidgets_FIND_STYLE STREQUAL "unix")
559 #-----------------------------------------------------------------
560 # UNIX: Helper MACROS
561 #-----------------------------------------------------------------
563 # Set the default values based on "wx-config --selected-config".
565 MACRO(WX_CONFIG_SELECT_GET_DEFAULT)
567 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --selected-config
568 OUTPUT_VARIABLE _wx_selected_config
569 RESULT_VARIABLE _wx_result
572 IF(_wx_result EQUAL 0)
573 FOREACH(_opt_name debug static unicode universal)
574 STRING(TOUPPER ${_opt_name} _upper_opt_name)
575 IF(_wx_selected_config MATCHES ".*${_opt_name}.*")
576 SET(wxWidgets_DEFAULT_${_upper_opt_name} ON)
577 ELSE(_wx_selected_config MATCHES ".*${_opt_name}.*")
578 SET(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
579 ENDIF(_wx_selected_config MATCHES ".*${_opt_name}.*")
580 ENDFOREACH(_opt_name)
581 ELSE(_wx_result EQUAL 0)
582 FOREACH(_upper_opt_name DEBUG STATIC UNICODE UNIVERSAL)
583 SET(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
584 ENDFOREACH(_upper_opt_name)
585 ENDIF(_wx_result EQUAL 0)
586 ENDMACRO(WX_CONFIG_SELECT_GET_DEFAULT)
589 # Query a boolean configuration option to determine if the system
590 # has both builds available. If so, provide the selection option
593 MACRO(WX_CONFIG_SELECT_QUERY_BOOL _OPT_NAME _OPT_HELP)
595 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --${_OPT_NAME}=yes
596 RESULT_VARIABLE _wx_result_yes
601 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --${_OPT_NAME}=no
602 RESULT_VARIABLE _wx_result_no
606 STRING(TOUPPER ${_OPT_NAME} _UPPER_OPT_NAME)
607 IF(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
608 OPTION(wxWidgets_USE_${_UPPER_OPT_NAME}
609 ${_OPT_HELP} ${wxWidgets_DEFAULT_${_UPPER_OPT_NAME}})
610 ELSE(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
611 # If option exists (already in cache), force to available one.
612 IF(DEFINED wxWidgets_USE_${_UPPER_OPT_NAME})
613 IF(_wx_result_yes EQUAL 0)
614 SET(wxWidgets_USE_${_UPPER_OPT_NAME} ON CACHE BOOL ${_OPT_HELP} FORCE)
615 ELSE(_wx_result_yes EQUAL 0)
616 SET(wxWidgets_USE_${_UPPER_OPT_NAME} OFF CACHE BOOL ${_OPT_HELP} FORCE)
617 ENDIF(_wx_result_yes EQUAL 0)
618 ENDIF(DEFINED wxWidgets_USE_${_UPPER_OPT_NAME})
619 ENDIF(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
620 ENDMACRO(WX_CONFIG_SELECT_QUERY_BOOL)
623 # Set wxWidgets_SELECT_OPTIONS to wx-config options for selecting
624 # among multiple builds.
626 MACRO(WX_CONFIG_SELECT_SET_OPTIONS)
627 SET(wxWidgets_SELECT_OPTIONS "")
628 FOREACH(_opt_name debug static unicode universal)
629 STRING(TOUPPER ${_opt_name} _upper_opt_name)
630 IF(DEFINED wxWidgets_USE_${_upper_opt_name})
631 IF(wxWidgets_USE_${_upper_opt_name})
632 LIST(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=yes)
633 ELSE(wxWidgets_USE_${_upper_opt_name})
634 LIST(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=no)
635 ENDIF(wxWidgets_USE_${_upper_opt_name})
636 ENDIF(DEFINED wxWidgets_USE_${_upper_opt_name})
637 ENDFOREACH(_opt_name)
638 ENDMACRO(WX_CONFIG_SELECT_SET_OPTIONS)
640 #-----------------------------------------------------------------
641 # UNIX: Start actual work.
642 #-----------------------------------------------------------------
643 # Support cross-compiling, only search in the target platform.
644 FIND_PROGRAM(wxWidgets_CONFIG_EXECUTABLE wx-config
645 ONLY_CMAKE_FIND_ROOT_PATH
648 IF(wxWidgets_CONFIG_EXECUTABLE)
649 SET(wxWidgets_FOUND TRUE)
651 # get defaults based on "wx-config --selected-config"
652 WX_CONFIG_SELECT_GET_DEFAULT()
654 # for each option: if both builds are available, provide option
655 WX_CONFIG_SELECT_QUERY_BOOL(debug "Use debug build?")
656 WX_CONFIG_SELECT_QUERY_BOOL(unicode "Use unicode build?")
657 WX_CONFIG_SELECT_QUERY_BOOL(universal "Use universal build?")
658 WX_CONFIG_SELECT_QUERY_BOOL(static "Link libraries statically?")
660 # process selection to set wxWidgets_SELECT_OPTIONS
661 WX_CONFIG_SELECT_SET_OPTIONS()
662 DBG_MSG("wxWidgets_SELECT_OPTIONS=${wxWidgets_SELECT_OPTIONS}")
664 # run the wx-config program to get cxxflags
666 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
667 ${wxWidgets_SELECT_OPTIONS} --cxxflags
668 OUTPUT_VARIABLE wxWidgets_CXX_FLAGS
673 STRING(STRIP "${wxWidgets_CXX_FLAGS}" wxWidgets_CXX_FLAGS)
674 SEPARATE_ARGUMENTS(wxWidgets_CXX_FLAGS)
676 DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
678 # parse definitions from cxxflags; drop -D* from CXXFLAGS
679 STRING(REGEX MATCHALL "-D[^;]+"
680 wxWidgets_DEFINITIONS "${wxWidgets_CXX_FLAGS}")
681 STRING(REGEX REPLACE "-D[^;]+;" ""
682 wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
684 # parse include dirs from cxxflags; drop -I prefix
685 STRING(REGEX MATCHALL "-I[^;]+"
686 wxWidgets_INCLUDE_DIRS "${wxWidgets_CXX_FLAGS}")
687 STRING(REGEX REPLACE "-I[^;]+;" ""
688 wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
689 STRING(REPLACE "-I" ""
690 wxWidgets_INCLUDE_DIRS "${wxWidgets_INCLUDE_DIRS}")
692 DBG_MSG_V("wxWidgets_DEFINITIONS=${wxWidgets_DEFINITIONS}")
693 DBG_MSG_V("wxWidgets_INCLUDE_DIRS=${wxWidgets_INCLUDE_DIRS}")
694 DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
697 SET(wxWidgets_FOUND FALSE)
699 "${wxWidgets_CONFIG_EXECUTABLE} --cxxflags FAILED with RET=${RET}")
702 # run the wx-config program to get the libs
703 # - NOTE: wx-config doesn't verify that the libs requested exist
704 # it just produces the names. Maybe a TRY_COMPILE would
706 STRING(REPLACE ";" ","
707 wxWidgets_FIND_COMPONENTS "${wxWidgets_FIND_COMPONENTS}")
709 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
710 ${wxWidgets_SELECT_OPTIONS} --libs ${wxWidgets_FIND_COMPONENTS}
711 OUTPUT_VARIABLE wxWidgets_LIBRARIES
716 STRING(STRIP "${wxWidgets_LIBRARIES}" wxWidgets_LIBRARIES)
717 SEPARATE_ARGUMENTS(wxWidgets_LIBRARIES)
718 STRING(REPLACE "-framework;" "-framework "
719 wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
720 STRING(REPLACE "-arch;" "-arch "
721 wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
722 STRING(REPLACE "-isysroot;" "-isysroot "
723 wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
725 # extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES)
726 STRING(REGEX MATCHALL "-L[^;]+"
727 wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARIES}")
728 STRING(REPLACE "-L" ""
729 wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARY_DIRS}")
731 DBG_MSG_V("wxWidgets_LIBRARIES=${wxWidgets_LIBRARIES}")
732 DBG_MSG_V("wxWidgets_LIBRARY_DIRS=${wxWidgets_LIBRARY_DIRS}")
735 SET(wxWidgets_FOUND FALSE)
736 DBG_MSG("${wxWidgets_CONFIG_EXECUTABLE} --libs ${wxWidgets_FIND_COMPONENTS} FAILED with RET=${RET}")
738 ENDIF(wxWidgets_CONFIG_EXECUTABLE)
740 #=====================================================================
741 # Neither UNIX_FIND_STYLE, nor WIN32_FIND_STYLE
742 #=====================================================================
743 ELSE(wxWidgets_FIND_STYLE STREQUAL "unix")
744 IF(NOT wxWidgets_FIND_QUIETLY)
746 "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): \n"
747 " Platform unknown/unsupported. It's neither WIN32 nor UNIX "
750 ENDIF(NOT wxWidgets_FIND_QUIETLY)
751 ENDIF(wxWidgets_FIND_STYLE STREQUAL "unix")
752 ENDIF(wxWidgets_FIND_STYLE STREQUAL "win32")
755 DBG_MSG("wxWidgets_FOUND : ${wxWidgets_FOUND}")
756 DBG_MSG("wxWidgets_INCLUDE_DIRS : ${wxWidgets_INCLUDE_DIRS}")
757 DBG_MSG("wxWidgets_LIBRARY_DIRS : ${wxWidgets_LIBRARY_DIRS}")
758 DBG_MSG("wxWidgets_LIBRARIES : ${wxWidgets_LIBRARIES}")
759 DBG_MSG("wxWidgets_CXX_FLAGS : ${wxWidgets_CXX_FLAGS}")
760 DBG_MSG("wxWidgets_USE_FILE : ${wxWidgets_USE_FILE}")
762 #=====================================================================
763 #=====================================================================
764 INCLUDE(FindPackageHandleStandardArgs)
765 FIND_PACKAGE_HANDLE_STANDARD_ARGS(wxWidgets DEFAULT_MSG wxWidgets_FOUND)
766 # Maintain consistency with all other variables.
767 SET(wxWidgets_FOUND ${WXWIDGETS_FOUND})
769 #=====================================================================
770 # Macros for use in wxWidgets apps.
771 # - This module will not fail to find wxWidgets based on the code
772 # below. Hence, it's required to check for validity of:
774 # wxWidgets_wxrc_EXECUTABLE
775 #=====================================================================
777 # Resource file compiler.
778 FIND_PROGRAM(wxWidgets_wxrc_EXECUTABLE wxrc
779 ${wxWidgets_ROOT_DIR}/utils/wxrc/vc_msw
783 # WX_SPLIT_ARGUMENTS_ON(<keyword> <left> <right> <arg1> <arg2> ...)
785 # Sets <left> and <right> to contain arguments to the left and right,
786 # respectively, of <keyword>.
789 # FUNCTION(WXWIDGETS_ADD_RESOURCES outfiles)
790 # WX_SPLIT_ARGUMENTS_ON(OPTIONS wxrc_files wxrc_options ${ARGN})
792 # ENDFUNCTION(WXWIDGETS_ADD_RESOURCES)
794 # WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o file.C)
796 # NOTE: This is a generic piece of code that should be renamed to
797 # SPLIT_ARGUMENTS_ON and put in a file serving the same purpose as
798 # FindPackageStandardArgs.cmake. At the time of this writing
799 # FindQt4.cmake has a QT4_EXTRACT_OPTIONS, which I basically copied
800 # here a bit more generalized. So, there are already two find modules
801 # using this approach.
803 FUNCTION(WX_SPLIT_ARGUMENTS_ON _keyword _leftvar _rightvar)
804 # FIXME: Document that the input variables will be cleared.
805 #LIST(APPEND ${_leftvar} "")
806 #LIST(APPEND ${_rightvar} "")
810 SET(_doing_right FALSE)
811 FOREACH(element ${ARGN})
812 IF("${element}" STREQUAL "${_keyword}")
813 SET(_doing_right TRUE)
814 ELSE("${element}" STREQUAL "${_keyword}")
816 LIST(APPEND ${_rightvar} "${element}")
818 LIST(APPEND ${_leftvar} "${element}")
820 ENDIF("${element}" STREQUAL "${_keyword}")
823 SET(${_leftvar} ${${_leftvar}} PARENT_SCOPE)
824 SET(${_rightvar} ${${_rightvar}} PARENT_SCOPE)
825 ENDFUNCTION(WX_SPLIT_ARGUMENTS_ON)
828 # WX_GET_DEPENDENCIES_FROM_XML(
836 # FIXME: Add documentation here...
838 FUNCTION(WX_GET_DEPENDENCIES_FROM_XML
846 STRING(REGEX MATCHALL
849 "${${_xml_contents}}"
851 FOREACH(dep_file ${dep_file_list})
852 STRING(REGEX REPLACE ${_clean_patt} "" dep_file "${dep_file}")
854 # make the file have an absolute path
855 IF(NOT IS_ABSOLUTE "${dep_file}")
856 SET(dep_file "${${_depends_path}}/${dep_file}")
857 ENDIF(NOT IS_ABSOLUTE "${dep_file}")
859 # append file to dependency list
860 LIST(APPEND ${_depends} "${dep_file}")
863 SET(${_depends} ${${_depends}} PARENT_SCOPE)
864 ENDFUNCTION(WX_GET_DEPENDENCIES_FROM_XML)
867 # WXWIDGETS_ADD_RESOURCES(<sources> <xrc_files>
868 # OPTIONS <options> [NO_CPP_CODE])
870 # Adds a custom command for resource file compilation of the
871 # <xrc_files> and appends the output files to <sources>.
874 # WXWIDGETS_ADD_RESOURCES(sources xrc/main_frame.xrc)
875 # WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o altname.cxx)
877 FUNCTION(WXWIDGETS_ADD_RESOURCES _outfiles)
878 WX_SPLIT_ARGUMENTS_ON(OPTIONS rc_file_list rc_options ${ARGN})
880 # Parse files for dependencies.
881 SET(rc_file_list_abs "")
883 FOREACH(rc_file ${rc_file_list})
884 GET_FILENAME_COMPONENT(depends_path ${rc_file} PATH)
886 GET_FILENAME_COMPONENT(rc_file_abs ${rc_file} ABSOLUTE)
887 LIST(APPEND rc_file_list_abs "${rc_file_abs}")
889 # All files have absolute paths or paths relative to the location
891 FILE(READ "${rc_file_abs}" rc_file_contents)
893 # get bitmap/bitmap2 files
894 WX_GET_DEPENDENCIES_FROM_XML(
903 WX_GET_DEPENDENCIES_FROM_XML(
912 WX_GET_DEPENDENCIES_FROM_XML(
914 "<object[^>]*class=\"wxIcon\"[^<]+"
924 # If NO_CPP_CODE option specified, then produce .xrs file rather
925 # than a .cpp file (i.e., don't add the default --cpp-code option).
926 LIST(FIND rc_options NO_CPP_CODE index)
928 LIST(APPEND rc_options --cpp-code)
929 # wxrc's default output filename for cpp code.
930 SET(outfile resource.cpp)
932 LIST(REMOVE_AT rc_options ${index})
933 # wxrc's default output filename for xrs file.
934 SET(outfile resource.xrs)
935 ENDIF(index EQUAL -1)
937 # Get output name for use in ADD_CUSTOM_COMMAND.
938 # - short option scanning
939 LIST(FIND rc_options -o index)
940 IF(NOT index EQUAL -1)
941 MATH(EXPR filename_index "${index} + 1")
942 LIST(GET rc_options ${filename_index} outfile)
943 #LIST(REMOVE_AT rc_options ${index} ${filename_index})
944 ENDIF(NOT index EQUAL -1)
945 # - long option scanning
946 STRING(REGEX MATCH "--output=[^;]*" outfile_opt "${rc_options}")
948 STRING(REPLACE "--output=" "" outfile "${outfile_opt}")
950 #STRING(REGEX REPLACE "--output=[^;]*;?" "" rc_options "${rc_options}")
951 #STRING(REGEX REPLACE ";$" "" rc_options "${rc_options}")
953 IF(NOT IS_ABSOLUTE "${outfile}")
954 SET(outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
955 ENDIF(NOT IS_ABSOLUTE "${outfile}")
958 COMMAND ${wxWidgets_wxrc_EXECUTABLE} ${rc_options} ${rc_file_list_abs}
959 DEPENDS ${rc_file_list_abs} ${rc_depends}
962 # Add generated header to output file list.
963 LIST(FIND rc_options -e short_index)
964 LIST(FIND rc_options --extra-cpp-code long_index)
965 IF(NOT short_index EQUAL -1 OR NOT long_index EQUAL -1)
966 GET_FILENAME_COMPONENT(outfile_ext ${outfile} EXT)
967 STRING(REPLACE "${outfile_ext}" ".h" outfile_header "${outfile}")
968 LIST(APPEND ${_outfiles} "${outfile_header}")
969 SET_SOURCE_FILES_PROPERTIES(
970 "${outfile_header}" PROPERTIES GENERATED TRUE
972 ENDIF(NOT short_index EQUAL -1 OR NOT long_index EQUAL -1)
974 # Add generated file to output file list.
975 LIST(APPEND ${_outfiles} "${outfile}")
977 SET(${_outfiles} ${${_outfiles}} PARENT_SCOPE)
978 ENDFUNCTION(WXWIDGETS_ADD_RESOURCES)