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