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