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