1 # - Find a wxWidgets (a.k.a., wxWindows) installation.
2 # This module finds if wxWidgets is installed and selects a default
3 # configuration to use. wxWidgets is a modular library. To specify the
4 # modules that you will use, you need to name them as components to
7 # FIND_PACKAGE(wxWidgets COMPONENTS base core ...)
9 # There are two search branches: a windows style and a unix style. For
10 # windows, the following variables are searched for and set to
11 # defaults in case of multiple choices. Change them if the defaults
12 # are not desired (i.e., these are the only variables you should
13 # change to select a configuration):
15 # wxWidgets_ROOT_DIR - Base wxWidgets directory
16 # (e.g., C:/wxWidgets-2.6.3).
17 # wxWidgets_LIB_DIR - Path to wxWidgets libraries
18 # (e.g., C:/wxWidgets-2.6.3/lib/vc_lib).
19 # wxWidgets_CONFIGURATION - Configuration to use
20 # (e.g., msw, mswd, mswu, mswunivud, etc.)
22 # For unix style it uses the wx-config utility. You can select between
23 # debug/release, unicode/ansi, universal/non-universal, and
24 # static/shared in the QtDialog or ccmake interfaces by turning ON/OFF
25 # the following variables:
28 # wxWidgets_USE_UNICODE
29 # wxWidgets_USE_UNIVERSAL
30 # wxWidgets_USE_STATIC
32 # The following are set after the configuration is done for both
33 # windows and unix style:
35 # wxWidgets_FOUND - Set to TRUE if wxWidgets was found.
36 # wxWidgets_INCLUDE_DIRS - Include directories for WIN32
37 # i.e., where to find "wx/wx.h" and
38 # "wx/setup.h"; possibly empty for unices.
39 # wxWidgets_LIBRARIES - Path to the wxWidgets libraries.
40 # wxWidgets_LIBRARY_DIRS - compile time link dirs, useful for
41 # rpath on UNIX. Typically an empty string
42 # in WIN32 environment.
43 # wxWidgets_DEFINITIONS - Contains defines required to compile/link
44 # against WX, e.g. -DWXUSINGDLL
45 # wxWidgets_CXX_FLAGS - Include dirs and ompiler flags for
46 # unices, empty on WIN32. Esentially
47 # "`wx-config --cxxflags`".
48 # wxWidgets_USE_FILE - Convenience include file.
51 # FIND_PACKAGE(wxWidgets COMPONENTS base core gl net)
53 # INCLUDE(${wxWidgets_USE_FILE})
54 # # and for each of your dependant executable/library targets:
55 # TARGET_LINK_LIBRARIES(<YourTarget> ${wxWidgets_LIBRARIES})
56 # ENDIF(wxWidgets_FOUND)
58 # If wxWidgets is required (i.e., not an optional part):
59 # FIND_PACKAGE(wxWidgets REQUIRED base core gl net)
60 # INCLUDE(${wxWidgets_USE_FILE})
61 # # and for each of your dependant executable/library targets:
62 # TARGET_LINK_LIBRARIES(<YourTarget> ${wxWidgets_LIBRARIES})
65 # FIXME: check this and provide a correct sample usage...
66 # Remember to connect back to the upper text.
67 # Sample usage with monolithic wx build:
69 # FIND_PACKAGE(wxWidgets COMPONENTS mono)
75 # This module has been tested on the WIN32 platform with wxWidgets
76 # 2.6.2, 2.6.3, and 2.5.3. However, it has been designed to
77 # easily extend support to all possible builds, e.g., static/shared,
78 # debug/release, unicode, universal, multilib/monolithic, etc..
80 # If you want to use the module and your build type is not supported
81 # out-of-the-box, please contact me to exchange information on how
82 # your system is setup and I'll try to add support for it.
86 # Miguel A. Figueroa-Villanueva (miguelf at ieee dot org).
87 # Jan Woetzel (jw at mip.informatik.uni-kiel.de).
89 # Based on previous works of:
90 # Jan Woetzel (FindwxWindows.cmake),
91 # Jorgen Bodde and Jerry Fath (FindwxWin.cmake).
95 # (1) Option/Setting to use all available wx libs
96 # In contrast to expert developer who lists the
97 # minimal set of required libs in wxWidgets_USE_LIBS
98 # there is the newbie user:
99 # - who just wants to link against WX with more 'magic'
100 # - doesn't know the internal structure of WX or how it was built,
101 # in particular if it is monolithic or not
102 # - want to link against all available WX libs
103 # Basically, the intent here is to mimic what wx-config would do by
104 # default (i.e., `wx-config --libs`).
107 # Add a reserved keyword "std" that initializes to what wx-config
108 # would default to. If the user has not set the wxWidgets_USE_LIBS,
109 # default to "std" instead of "base core" as it is now. To implement
110 # "std" will basically boil down to a FOR_EACH lib-FOUND, but maybe
111 # checking whether a minimal set was found.
114 # FIXME: This and all the DBG_MSG calls should be removed after the
117 # Helper macro to control the debugging output globally. There are
118 # two versions for controlling how verbose your output should be.
121 # "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}")
123 MACRO(DBG_MSG_V _MSG)
125 # "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}")
128 # Clear return values in case the module is loaded more than once.
129 SET(wxWidgets_FOUND FALSE)
130 SET(wxWidgets_INCLUDE_DIRS "")
131 SET(wxWidgets_LIBRARIES "")
132 SET(wxWidgets_LIBRARY_DIRS "")
133 SET(wxWidgets_CXX_FLAGS "")
135 # DEPRECATED: This is a patch to support the DEPRECATED use of
136 # wxWidgets_USE_LIBS.
138 # If wxWidgets_USE_LIBS is set:
139 # - if using <components>, then override wxWidgets_USE_LIBS
140 # - else set wxWidgets_FIND_COMPONENTS to wxWidgets_USE_LIBS
141 IF(wxWidgets_USE_LIBS AND NOT wxWidgets_FIND_COMPONENTS)
142 SET(wxWidgets_FIND_COMPONENTS ${wxWidgets_USE_LIBS})
143 ENDIF(wxWidgets_USE_LIBS AND NOT wxWidgets_FIND_COMPONENTS)
144 DBG_MSG("wxWidgets_FIND_COMPONENTS : ${wxWidgets_FIND_COMPONENTS}")
146 # Add the convenience use file if available.
148 # Get dir of this file which may reside in:
149 # - CMAKE_MAKE_ROOT/Modules on CMake installation
150 # - CMAKE_MODULE_PATH if user prefers his own specialized version
151 SET(wxWidgets_USE_FILE "")
152 GET_FILENAME_COMPONENT(
153 wxWidgets_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
154 # Prefer an existing customized version, but the user might override
155 # the FindwxWidgets module and not the UsewxWidgets one.
156 IF(EXISTS "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
157 SET(wxWidgets_USE_FILE
158 "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
159 ELSE(EXISTS "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
160 SET(wxWidgets_USE_FILE UsewxWidgets.cmake)
161 ENDIF(EXISTS "${wxWidgets_CURRENT_LIST_DIR}/UsewxWidgets.cmake")
163 #=====================================================================
164 #=====================================================================
166 SET(WIN32_STYLE_FIND 1)
169 SET(WIN32_STYLE_FIND 0)
170 SET(UNIX_STYLE_FIND 1)
173 SET(UNIX_STYLE_FIND 1)
176 #=====================================================================
178 #=====================================================================
180 # Useful common wx libs needed by almost all components.
181 SET(wxWidgets_COMMON_LIBRARIES png tiff jpeg zlib regex expat)
183 # DEPRECATED: Use FIND_PACKAGE(wxWidgets COMPONENTS mono) instead.
184 IF(NOT wxWidgets_FIND_COMPONENTS)
185 IF(wxWidgets_USE_MONOLITHIC)
186 SET(wxWidgets_FIND_COMPONENTS mono)
187 ELSE(wxWidgets_USE_MONOLITHIC)
188 SET(wxWidgets_FIND_COMPONENTS base core) # this is default
189 ENDIF(wxWidgets_USE_MONOLITHIC)
190 ENDIF(NOT wxWidgets_FIND_COMPONENTS)
192 # Always add the common required libs.
193 LIST(APPEND wxWidgets_FIND_COMPONENTS ${wxWidgets_COMMON_LIBRARIES})
195 #-------------------------------------------------------------------
196 # WIN32: Helper MACROS
197 #-------------------------------------------------------------------
199 # Get filename components for a configuration. For example,
200 # if _CONFIGURATION = mswunivud, then _UNV=univ, _UCD=u _DBG=d
201 # if _CONFIGURATION = mswu, then _UNV="", _UCD=u _DBG=""
203 MACRO(WX_GET_NAME_COMPONENTS _CONFIGURATION _UNV _UCD _DBG)
204 STRING(REGEX MATCH "univ" ${_UNV} "${_CONFIGURATION}")
205 STRING(REGEX REPLACE "msw.*(u)[d]*$" "u" ${_UCD} "${_CONFIGURATION}")
206 IF(${_UCD} STREQUAL ${_CONFIGURATION})
208 ENDIF(${_UCD} STREQUAL ${_CONFIGURATION})
209 STRING(REGEX MATCH "d$" ${_DBG} "${_CONFIGURATION}")
210 ENDMACRO(WX_GET_NAME_COMPONENTS)
213 # Find libraries associated to a configuration.
215 MACRO(WX_FIND_LIBS _UNV _UCD _DBG)
216 DBG_MSG_V("m_unv = ${_UNV}")
217 DBG_MSG_V("m_ucd = ${_UCD}")
218 DBG_MSG_V("m_dbg = ${_DBG}")
220 # FIXME: What if both regex libs are available. regex should be
221 # found outside the loop and only wx${LIB}${_UCD}${_DBG}.
222 # Find wxWidgets common libraries.
223 FOREACH(LIB ${wxWidgets_COMMON_LIBRARIES})
224 FIND_LIBRARY(WX_${LIB}${_DBG}
226 wx${LIB}${_UCD}${_DBG} # for regex
231 MARK_AS_ADVANCED(WX_${LIB}${_DBG})
234 # Find wxWidgets multilib base libraries.
235 FIND_LIBRARY(WX_base${_DBG}
237 wxbase29${_UCD}${_DBG}
238 wxbase28${_UCD}${_DBG}
239 wxbase27${_UCD}${_DBG}
240 wxbase26${_UCD}${_DBG}
241 wxbase25${_UCD}${_DBG}
245 MARK_AS_ADVANCED(WX_base${_DBG})
246 FOREACH(LIB net odbc xml)
247 FIND_LIBRARY(WX_${LIB}${_DBG}
249 wxbase29${_UCD}${_DBG}_${LIB}
250 wxbase28${_UCD}${_DBG}_${LIB}
251 wxbase27${_UCD}${_DBG}_${LIB}
252 wxbase26${_UCD}${_DBG}_${LIB}
253 wxbase25${_UCD}${_DBG}_${LIB}
257 MARK_AS_ADVANCED(WX_${LIB}${_DBG})
260 # Find wxWidgets monolithic library.
261 FIND_LIBRARY(WX_mono${_DBG}
263 wxmsw${_UNV}29${_UCD}${_DBG}
264 wxmsw${_UNV}28${_UCD}${_DBG}
265 wxmsw${_UNV}27${_UCD}${_DBG}
266 wxmsw${_UNV}26${_UCD}${_DBG}
267 wxmsw${_UNV}25${_UCD}${_DBG}
271 MARK_AS_ADVANCED(WX_mono${_DBG})
273 # Find wxWidgets multilib libraries.
274 FOREACH(LIB core adv aui html media xrc dbgrid gl qa)
275 FIND_LIBRARY(WX_${LIB}${_DBG}
277 wxmsw${_UNV}29${_UCD}${_DBG}_${LIB}
278 wxmsw${_UNV}28${_UCD}${_DBG}_${LIB}
279 wxmsw${_UNV}27${_UCD}${_DBG}_${LIB}
280 wxmsw${_UNV}26${_UCD}${_DBG}_${LIB}
281 wxmsw${_UNV}25${_UCD}${_DBG}_${LIB}
285 MARK_AS_ADVANCED(WX_${LIB}${_DBG})
287 ENDMACRO(WX_FIND_LIBS)
290 # Clear all library paths, so that FIND_LIBRARY refinds them.
292 # Clear a lib, reset its found flag, and mark as advanced.
293 MACRO(WX_CLEAR_LIB _LIB)
294 SET(${_LIB} "${_LIB}-NOTFOUND" CACHE FILEPATH "Cleared." FORCE)
295 SET(${_LIB}_FOUND FALSE)
296 MARK_AS_ADVANCED(${_LIB})
297 ENDMACRO(WX_CLEAR_LIB)
298 # Clear all debug or release library paths (arguments are "d" or "").
299 MACRO(WX_CLEAR_ALL_LIBS _DBG)
300 # Clear wxWidgets common libraries.
301 FOREACH(LIB ${wxWidgets_COMMON_LIBRARIES})
302 WX_CLEAR_LIB(WX_${LIB}${_DBG})
305 # Clear wxWidgets multilib base libraries.
306 WX_CLEAR_LIB(WX_base${_DBG})
307 FOREACH(LIB net odbc xml)
308 WX_CLEAR_LIB(WX_${LIB}${_DBG})
311 # Clear wxWidgets monolithic library.
312 WX_CLEAR_LIB(WX_mono${_DBG})
314 # Clear wxWidgets multilib libraries.
315 FOREACH(LIB core adv aui html media xrc dbgrid gl qa)
316 WX_CLEAR_LIB(WX_${LIB}${_DBG})
318 ENDMACRO(WX_CLEAR_ALL_LIBS)
319 # Clear all wxWidgets debug libraries.
320 MACRO(WX_CLEAR_ALL_DBG_LIBS)
321 WX_CLEAR_ALL_LIBS("d")
322 ENDMACRO(WX_CLEAR_ALL_DBG_LIBS)
323 # Clear all wxWidgets release libraries.
324 MACRO(WX_CLEAR_ALL_REL_LIBS)
325 WX_CLEAR_ALL_LIBS("")
326 ENDMACRO(WX_CLEAR_ALL_REL_LIBS)
329 # Set the wxWidgets_LIBRARIES variable.
330 # Also, Sets output variable wxWidgets_FOUND to FALSE if it fails.
332 MACRO(WX_SET_LIBRARIES _LIBS _DBG)
333 DBG_MSG_V("Looking for ${${_LIBS}}")
334 IF(WX_USE_REL_AND_DBG)
335 FOREACH(LIB ${${_LIBS}})
336 DBG_MSG_V("Searching for ${LIB} and ${LIB}d")
337 DBG_MSG_V("WX_${LIB} : ${WX_${LIB}}")
338 DBG_MSG_V("WX_${LIB}d : ${WX_${LIB}d}")
339 IF(WX_${LIB} AND WX_${LIB}d)
340 DBG_MSG_V("Found ${LIB} and ${LIB}d")
341 LIST(APPEND wxWidgets_LIBRARIES
342 debug ${WX_${LIB}d} optimized ${WX_${LIB}}
344 ELSE(WX_${LIB} AND WX_${LIB}d)
345 DBG_MSG_V("- not found due to missing WX_${LIB}=${WX_${LIB}} or WX_${LIB}d=${WX_${LIB}d}")
346 SET(wxWidgets_FOUND FALSE)
347 ENDIF(WX_${LIB} AND WX_${LIB}d)
349 ELSE(WX_USE_REL_AND_DBG)
350 FOREACH(LIB ${${_LIBS}})
351 DBG_MSG_V("Searching for ${LIB}${_DBG}")
352 DBG_MSG_V("WX_${LIB}${_DBG} : ${WX_${LIB}${_DBG}}")
354 DBG_MSG_V("Found ${LIB}${_DBG}")
355 LIST(APPEND wxWidgets_LIBRARIES ${WX_${LIB}${_DBG}})
356 ELSE(WX_${LIB}${_DBG})
358 "- not found due to missing WX_${LIB}${_DBG}=${WX_${LIB}${_DBG}}")
359 SET(wxWidgets_FOUND FALSE)
360 ENDIF(WX_${LIB}${_DBG})
362 ENDIF(WX_USE_REL_AND_DBG)
365 LIST(FIND ${_LIBS} gl WX_USE_GL)
366 IF(NOT WX_USE_GL EQUAL -1)
367 DBG_MSG_V("- is required.")
368 LIST(APPEND wxWidgets_LIBRARIES opengl32 glu32)
369 ENDIF(NOT WX_USE_GL EQUAL -1)
371 LIST(APPEND wxWidgets_LIBRARIES winmm comctl32 rpcrt4 wsock32)
372 ENDMACRO(WX_SET_LIBRARIES)
374 #-------------------------------------------------------------------
375 # WIN32: Start actual work.
376 #-------------------------------------------------------------------
378 # Look for an installation tree.
379 FIND_PATH(wxWidgets_ROOT_DIR
380 NAMES include/wx/wx.h
382 $ENV{wxWidgets_ROOT_DIR}
384 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\wxWidgets_is1;Inno Setup: App Path]" # WX 2.6.x
411 DOC "wxWidgets base/installation directory?"
414 # If wxWidgets_ROOT_DIR changed, clear lib dir.
415 IF(NOT WX_ROOT_DIR STREQUAL wxWidgets_ROOT_DIR)
416 SET(WX_ROOT_DIR ${wxWidgets_ROOT_DIR}
417 CACHE INTERNAL "wxWidgets_ROOT_DIR")
418 SET(wxWidgets_LIB_DIR "wxWidgets_LIB_DIR-NOTFOUND"
419 CACHE PATH "Cleared." FORCE)
420 ENDIF(NOT WX_ROOT_DIR STREQUAL wxWidgets_ROOT_DIR)
423 # Select one default tree inside the already determined wx tree.
424 # Prefer static/shared order usually consistent with build
426 IF(BUILD_SHARED_LIBS)
427 FIND_PATH(wxWidgets_LIB_DIR
428 NAMES wxpng.lib wxpngd.lib
430 ${WX_ROOT_DIR}/lib/vc_dll # prefer shared
431 ${WX_ROOT_DIR}/lib/vc_lib
432 DOC "Path to wxWidgets libraries?"
435 ELSE(BUILD_SHARED_LIBS)
436 FIND_PATH(wxWidgets_LIB_DIR
437 NAMES wxpng.lib wxpngd.lib
439 ${WX_ROOT_DIR}/lib/vc_lib # prefer static
440 ${WX_ROOT_DIR}/lib/vc_dll
441 DOC "Path to wxWidgets libraries?"
444 ENDIF(BUILD_SHARED_LIBS)
446 # If wxWidgets_LIB_DIR changed, clear all libraries.
447 IF(NOT WX_LIB_DIR STREQUAL wxWidgets_LIB_DIR)
448 SET(WX_LIB_DIR ${wxWidgets_LIB_DIR} CACHE INTERNAL "wxWidgets_LIB_DIR")
449 WX_CLEAR_ALL_DBG_LIBS()
450 WX_CLEAR_ALL_REL_LIBS()
451 ENDIF(NOT WX_LIB_DIR STREQUAL wxWidgets_LIB_DIR)
454 SET(wxWidgets_FOUND TRUE)
456 # If building shared libs, define WXUSINGDLL to use dllimport.
457 IF(WX_LIB_DIR MATCHES ".*[dD][lL][lL].*")
458 SET(wxWidgets_DEFINITIONS "-DWXUSINGDLL")
459 DBG_MSG_V("detected SHARED/DLL tree WX_LIB_DIR=${WX_LIB_DIR}")
460 ENDIF(WX_LIB_DIR MATCHES ".*[dD][lL][lL].*")
462 # Search for available configuration types.
463 FOREACH(CFG mswunivud mswunivd mswud mswd mswunivu mswuniv mswu msw)
464 SET(WX_${CFG}_FOUND FALSE)
465 IF(EXISTS ${WX_LIB_DIR}/${CFG})
466 LIST(APPEND WX_CONFIGURATION_LIST ${CFG})
467 SET(WX_${CFG}_FOUND TRUE)
468 SET(WX_CONFIGURATION ${CFG})
469 ENDIF(EXISTS ${WX_LIB_DIR}/${CFG})
471 DBG_MSG_V("WX_CONFIGURATION_LIST=${WX_CONFIGURATION_LIST}")
474 # If the selected configuration wasn't found force the default
475 # one. Otherwise, use it but still force a refresh for
476 # updating the doc string with the current list of available
478 IF(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
479 SET(wxWidgets_CONFIGURATION ${WX_CONFIGURATION} CACHE STRING
480 "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
481 ELSE(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
482 SET(wxWidgets_CONFIGURATION ${wxWidgets_CONFIGURATION} CACHE STRING
483 "Set wxWidgets configuration (${WX_CONFIGURATION_LIST})" FORCE)
484 ENDIF(NOT WX_${wxWidgets_CONFIGURATION}_FOUND)
486 # If release config selected, and both release/debug exist.
487 IF(WX_${wxWidgets_CONFIGURATION}d_FOUND)
488 OPTION(wxWidgets_USE_REL_AND_DBG
489 "Use release and debug configurations?" TRUE)
490 SET(WX_USE_REL_AND_DBG ${wxWidgets_USE_REL_AND_DBG})
491 ELSE(WX_${wxWidgets_CONFIGURATION}d_FOUND)
492 # If the option exists (already in cache), force it false.
493 IF(wxWidgets_USE_REL_AND_DBG)
494 SET(wxWidgets_USE_REL_AND_DBG FALSE CACHE BOOL
495 "No ${wxWidgets_CONFIGURATION}d found." FORCE)
496 ENDIF(wxWidgets_USE_REL_AND_DBG)
497 SET(WX_USE_REL_AND_DBG FALSE)
498 ENDIF(WX_${wxWidgets_CONFIGURATION}d_FOUND)
500 # Get configuration parameters from the name.
501 WX_GET_NAME_COMPONENTS(${wxWidgets_CONFIGURATION} UNV UCD DBG)
503 # Set wxWidgets main include directory.
504 IF(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
505 SET(wxWidgets_INCLUDE_DIRS ${WX_ROOT_DIR}/include)
506 ELSE(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
507 DBG_MSG("wxWidgets_FOUND FALSE because WX_ROOT_DIR=${WX_ROOT_DIR} has no ${WX_ROOT_DIR}/include/wx/wx.h")
508 SET(wxWidgets_FOUND FALSE)
509 ENDIF(EXISTS ${WX_ROOT_DIR}/include/wx/wx.h)
511 # Set wxWidgets lib setup include directory.
512 IF(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
513 LIST(APPEND wxWidgets_INCLUDE_DIRS
514 ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION})
515 ELSE(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
516 DBG_MSG("WXWIDGET_FOUND FALSE because ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h does not exists.")
517 SET(wxWidgets_FOUND FALSE)
518 ENDIF(EXISTS ${WX_LIB_DIR}/${wxWidgets_CONFIGURATION}/wx/setup.h)
520 # Find wxWidgets libraries.
521 WX_FIND_LIBS("${UNV}" "${UCD}" "${DBG}")
522 IF(WX_USE_REL_AND_DBG)
523 WX_FIND_LIBS("${UNV}" "${UCD}" "d")
524 ENDIF(WX_USE_REL_AND_DBG)
526 # Settings for requested libs (i.e., include dir, libraries, etc.).
527 WX_SET_LIBRARIES(wxWidgets_FIND_COMPONENTS "${DBG}")
529 ENDIF(WX_CONFIGURATION)
533 #=====================================================================
535 #=====================================================================
536 ELSE(WIN32_STYLE_FIND)
538 #-----------------------------------------------------------------
539 # UNIX: Helper MACROS
540 #-----------------------------------------------------------------
542 # Set the default values based on "wx-config --selected-config".
544 MACRO(WX_CONFIG_SELECT_GET_DEFAULT)
546 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --selected-config
547 OUTPUT_VARIABLE _wx_selected_config
548 RESULT_VARIABLE _wx_result
551 IF(_wx_result EQUAL 0)
552 FOREACH(_opt_name debug static unicode universal)
553 STRING(TOUPPER ${_opt_name} _upper_opt_name)
554 IF(_wx_selected_config MATCHES ".*${_opt_name}.*")
555 SET(wxWidgets_DEFAULT_${_upper_opt_name} ON)
556 ELSE(_wx_selected_config MATCHES ".*${_opt_name}.*")
557 SET(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
558 ENDIF(_wx_selected_config MATCHES ".*${_opt_name}.*")
559 ENDFOREACH(_opt_name)
560 ELSE(_wx_result EQUAL 0)
561 FOREACH(_upper_opt_name DEBUG STATIC UNICODE UNIVERSAL)
562 SET(wxWidgets_DEFAULT_${_upper_opt_name} OFF)
563 ENDFOREACH(_opt_name)
564 ENDIF(_wx_result EQUAL 0)
565 ENDMACRO(WX_CONFIG_SELECT_GET_DEFAULT)
568 # Query a boolean configuration option to determine if the system
569 # has both builds available. If so, provide the selection option
572 MACRO(WX_CONFIG_SELECT_QUERY_BOOL _OPT_NAME _OPT_HELP)
574 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --${_OPT_NAME}=yes
575 RESULT_VARIABLE _wx_result_yes
580 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}" --${_OPT_NAME}=no
581 RESULT_VARIABLE _wx_result_no
585 STRING(TOUPPER ${_OPT_NAME} _UPPER_OPT_NAME)
586 IF(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
587 OPTION(wxWidgets_USE_${_UPPER_OPT_NAME}
588 ${_OPT_HELP} ${wxWidgets_DEFAULT_${_UPPER_OPT_NAME}})
589 ELSE(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
590 # If option exists (already in cache), force to available one.
591 IF(DEFINED wxWidgets_USE_${_UPPER_OPT_NAME})
592 IF(_wx_result_yes EQUAL 0)
593 SET(wxWidgets_USE_${_UPPER_OPT_NAME} ON CACHE BOOL ${_OPT_HELP} FORCE)
594 ELSE(_wx_result_yes EQUAL 0)
595 SET(wxWidgets_USE_${_UPPER_OPT_NAME} OFF CACHE BOOL ${_OPT_HELP} FORCE)
596 ENDIF(_wx_result_yes EQUAL 0)
597 ENDIF(DEFINED wxWidgets_USE_${_UPPER_OPT_NAME})
598 ENDIF(_wx_result_yes EQUAL 0 AND _wx_result_no EQUAL 0)
599 ENDMACRO(WX_CONFIG_SELECT_QUERY_BOOL)
602 # Set wxWidgets_SELECT_OPTIONS to wx-config options for selecting
603 # among multiple builds.
605 MACRO(WX_CONFIG_SELECT_SET_OPTIONS)
606 SET(wxWidgets_SELECT_OPTIONS "")
607 FOREACH(_opt_name debug static unicode universal)
608 STRING(TOUPPER ${_opt_name} _upper_opt_name)
609 IF(DEFINED wxWidgets_USE_${_upper_opt_name})
610 IF(wxWidgets_USE_${_upper_opt_name})
611 LIST(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=yes)
612 ELSE(wxWidgets_USE_${_upper_opt_name})
613 LIST(APPEND wxWidgets_SELECT_OPTIONS --${_opt_name}=no)
614 ENDIF(wxWidgets_USE_${_upper_opt_name})
615 ENDIF(DEFINED wxWidgets_USE_${_upper_opt_name})
616 ENDFOREACH(_opt_name)
617 ENDMACRO(WX_CONFIG_SELECT_SET_OPTIONS)
619 #-----------------------------------------------------------------
620 # UNIX: Start actual work.
621 #-----------------------------------------------------------------
622 # Support cross-compiling, only search in the target platform.
623 FIND_PROGRAM(wxWidgets_CONFIG_EXECUTABLE wx-config
624 ONLY_CMAKE_FIND_ROOT_PATH
627 IF(wxWidgets_CONFIG_EXECUTABLE)
628 SET(wxWidgets_FOUND TRUE)
630 # get defaults based on "wx-config --selected-config"
631 WX_CONFIG_SELECT_GET_DEFAULT()
633 # for each option: if both builds are available, provide option
634 WX_CONFIG_SELECT_QUERY_BOOL(debug "Use debug build?")
635 WX_CONFIG_SELECT_QUERY_BOOL(unicode "Use unicode build?")
636 WX_CONFIG_SELECT_QUERY_BOOL(universal "Use universal build?")
637 WX_CONFIG_SELECT_QUERY_BOOL(static "Link libraries statically?")
639 # process selection to set wxWidgets_SELECT_OPTIONS
640 WX_CONFIG_SELECT_SET_OPTIONS()
641 DBG_MSG("wxWidgets_SELECT_OPTIONS=${wxWidgets_SELECT_OPTIONS}")
643 # run the wx-config program to get cxxflags
645 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
646 ${wxWidgets_SELECT_OPTIONS} --cxxflags
647 OUTPUT_VARIABLE wxWidgets_CXX_FLAGS
652 STRING(STRIP "${wxWidgets_CXX_FLAGS}" wxWidgets_CXX_FLAGS)
653 SEPARATE_ARGUMENTS(wxWidgets_CXX_FLAGS)
655 DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
657 # parse definitions from cxxflags; drop -D* from CXXFLAGS
658 STRING(REGEX MATCHALL "-D[^;]+"
659 wxWidgets_DEFINITIONS "${wxWidgets_CXX_FLAGS}")
660 STRING(REGEX REPLACE "-D[^;]+;" ""
661 wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
663 # parse include dirs from cxxflags; drop -I prefix
664 STRING(REGEX MATCHALL "-I[^;]+"
665 wxWidgets_INCLUDE_DIRS "${wxWidgets_CXX_FLAGS}")
666 STRING(REGEX REPLACE "-I[^;]+;" ""
667 wxWidgets_CXX_FLAGS "${wxWidgets_CXX_FLAGS}")
668 STRING(REPLACE "-I" ""
669 wxWidgets_INCLUDE_DIRS "${wxWidgets_INCLUDE_DIRS}")
671 DBG_MSG_V("wxWidgets_DEFINITIONS=${wxWidgets_DEFINITIONS}")
672 DBG_MSG_V("wxWidgets_INCLUDE_DIRS=${wxWidgets_INCLUDE_DIRS}")
673 DBG_MSG_V("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}")
676 SET(wxWidgets_FOUND FALSE)
678 "${wxWidgets_CONFIG_EXECUTABLE} --cxxflags FAILED with RET=${RET}")
681 # run the wx-config program to get the libs
682 # - NOTE: wx-config doesn't verify that the libs requested exist
683 # it just produces the names. Maybe a TRY_COMPILE would
685 STRING(REPLACE ";" ","
686 wxWidgets_FIND_COMPONENTS "${wxWidgets_FIND_COMPONENTS}")
688 COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
689 ${wxWidgets_SELECT_OPTIONS} --libs ${wxWidgets_FIND_COMPONENTS}
690 OUTPUT_VARIABLE wxWidgets_LIBRARIES
695 STRING(STRIP "${wxWidgets_LIBRARIES}" wxWidgets_LIBRARIES)
696 SEPARATE_ARGUMENTS(wxWidgets_LIBRARIES)
697 STRING(REPLACE "-framework;" "-framework "
698 wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
699 STRING(REPLACE "-arch;" "-arch "
700 wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
701 STRING(REPLACE "-isysroot;" "-isysroot "
702 wxWidgets_LIBRARIES "${wxWidgets_LIBRARIES}")
704 # extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES)
705 STRING(REGEX MATCHALL "-L[^;]+"
706 wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARIES}")
707 STRING(REPLACE "-L" ""
708 wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARY_DIRS}")
710 DBG_MSG_V("wxWidgets_LIBRARIES=${wxWidgets_LIBRARIES}")
711 DBG_MSG_V("wxWidgets_LIBRARY_DIRS=${wxWidgets_LIBRARY_DIRS}")
714 SET(wxWidgets_FOUND FALSE)
715 DBG_MSG("${wxWidgets_CONFIG_EXECUTABLE} --libs ${wxWidgets_FIND_COMPONENTS} FAILED with RET=${RET}")
717 ENDIF(wxWidgets_CONFIG_EXECUTABLE)
719 #=====================================================================
720 # Neither UNIX_STYLE_FIND, nor WIN32_STYLE_FIND
721 #=====================================================================
722 ELSE(UNIX_STYLE_FIND)
723 IF(NOT wxWidgets_FIND_QUIETLY)
725 "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): \n"
726 " Platform unknown/unsupported. It's neither WIN32 nor UNIX "
729 ENDIF(NOT wxWidgets_FIND_QUIETLY)
730 ENDIF(UNIX_STYLE_FIND)
731 ENDIF(WIN32_STYLE_FIND)
734 DBG_MSG("wxWidgets_FOUND : ${wxWidgets_FOUND}")
735 DBG_MSG("wxWidgets_INCLUDE_DIRS : ${wxWidgets_INCLUDE_DIRS}")
736 DBG_MSG("wxWidgets_LIBRARY_DIRS : ${wxWidgets_LIBRARY_DIRS}")
737 DBG_MSG("wxWidgets_LIBRARIES : ${wxWidgets_LIBRARIES}")
738 DBG_MSG("wxWidgets_CXX_FLAGS : ${wxWidgets_CXX_FLAGS}")
739 DBG_MSG("wxWidgets_USE_FILE : ${wxWidgets_USE_FILE}")
741 #=====================================================================
742 #=====================================================================
743 INCLUDE(FindPackageHandleStandardArgs)
744 FIND_PACKAGE_HANDLE_STANDARD_ARGS(wxWidgets DEFAULT_MSG wxWidgets_FOUND)
745 # Maintain consistency with all other variables.
746 SET(wxWidgets_FOUND ${WXWIDGETS_FOUND})
748 #=====================================================================
749 # Macros for use in wxWidgets apps.
750 # - This module will not fail to find wxWidgets based on the code
751 # below. Hence, it's required to check for validity of:
753 # wxWidgets_wxrc_EXECUTABLE
754 #=====================================================================
756 # Resource file compiler.
757 FIND_PROGRAM(wxWidgets_wxrc_EXECUTABLE wxrc
758 ${wxWidgets_ROOT_DIR}/utils/wxrc/vc_msw
762 # WX_SPLIT_ARGUMENTS_ON(<keyword> <left> <right> <arg1> <arg2> ...)
764 # Sets <left> and <right> to contain arguments to the left and right,
765 # respectively, of <keyword>.
768 # FUNCTION(WXWIDGETS_ADD_RESOURCES outfiles)
769 # WX_SPLIT_ARGUMENTS_ON(OPTIONS wxrc_files wxrc_options ${ARGN})
771 # ENDFUNCTION(WXWIDGETS_ADD_RESOURCES)
773 # WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o file.C)
775 # NOTE: This is a generic piece of code that should be renamed to
776 # SPLIT_ARGUMENTS_ON and put in a file serving the same purpose as
777 # FindPackageStandardArgs.cmake. At the time of this writing
778 # FindQt4.cmake has a QT4_EXTRACT_OPTIONS, which I basically copied
779 # here a bit more generalized. So, there are already two find modules
780 # using this approach.
782 FUNCTION(WX_SPLIT_ARGUMENTS_ON _keyword _leftvar _rightvar)
783 # FIXME: Document that the input variables will be cleared.
784 #LIST(APPEND ${_leftvar} "")
785 #LIST(APPEND ${_rightvar} "")
789 SET(_doing_right FALSE)
790 FOREACH(element ${ARGN})
791 IF("${element}" STREQUAL "${_keyword}")
792 SET(_doing_right TRUE)
793 ELSE("${element}" STREQUAL "${_keyword}")
795 LIST(APPEND ${_rightvar} "${element}")
797 LIST(APPEND ${_leftvar} "${element}")
799 ENDIF("${element}" STREQUAL "${_keyword}")
802 SET(${_leftvar} ${${_leftvar}} PARENT_SCOPE)
803 SET(${_rightvar} ${${_rightvar}} PARENT_SCOPE)
804 ENDFUNCTION(WX_SPLIT_ARGUMENTS_ON)
807 # WX_GET_DEPENDENCIES_FROM_XML(
815 # FIXME: Add documentation here...
817 FUNCTION(WX_GET_DEPENDENCIES_FROM_XML
825 STRING(REGEX MATCHALL
828 "${${_xml_contents}}"
830 FOREACH(dep_file ${dep_file_list})
831 STRING(REGEX REPLACE ${_clean_patt} "" dep_file "${dep_file}")
833 # make the file have an absolute path
834 IF(NOT IS_ABSOLUTE "${dep_file}")
835 SET(dep_file "${${_depends_path}}/${dep_file}")
836 ENDIF(NOT IS_ABSOLUTE "${dep_file}")
838 # append file to dependency list
839 LIST(APPEND ${_depends} "${dep_file}")
842 SET(${_depends} ${${_depends}} PARENT_SCOPE)
843 ENDFUNCTION(WX_GET_DEPENDENCIES_FROM_XML)
846 # WXWIDGETS_ADD_RESOURCES(<sources> <xrc_files>
847 # OPTIONS <options> [NO_CPP_CODE])
849 # Adds a custom command for resource file compilation of the
850 # <xrc_files> and appends the output files to <sources>.
853 # WXWIDGETS_ADD_RESOURCES(sources xrc/main_frame.xrc)
854 # WXWIDGETS_ADD_RESOURCES(sources ${xrc_files} OPTIONS -e -o altname.cxx)
856 FUNCTION(WXWIDGETS_ADD_RESOURCES _outfiles)
857 WX_SPLIT_ARGUMENTS_ON(OPTIONS rc_file_list rc_options ${ARGN})
859 # Parse files for dependencies.
860 SET(rc_file_list_abs "")
862 FOREACH(rc_file ${rc_file_list})
863 GET_FILENAME_COMPONENT(depends_path ${rc_file} PATH)
865 GET_FILENAME_COMPONENT(rc_file_abs ${rc_file} ABSOLUTE)
866 LIST(APPEND rc_file_list_abs "${rc_file_abs}")
868 # All files have absolute paths or paths relative to the location
870 FILE(READ "${rc_file_abs}" rc_file_contents)
872 # get bitmap/bitmap2 files
873 WX_GET_DEPENDENCIES_FROM_XML(
882 WX_GET_DEPENDENCIES_FROM_XML(
891 WX_GET_DEPENDENCIES_FROM_XML(
893 "<object[^>]*class=\"wxIcon\"[^<]+"
903 # If NO_CPP_CODE option specified, then produce .xrs file rather
904 # than a .cpp file (i.e., don't add the default --cpp-code option).
905 LIST(FIND rc_options NO_CPP_CODE index)
907 LIST(APPEND rc_options --cpp-code)
908 # wxrc's default output filename for cpp code.
909 SET(outfile resource.cpp)
911 LIST(REMOVE_AT rc_options ${index})
912 # wxrc's default output filename for xrs file.
913 SET(outfile resource.xrs)
914 ENDIF(index EQUAL -1)
916 # Get output name for use in ADD_CUSTOM_COMMAND.
917 # - short option scanning
918 LIST(FIND rc_options -o index)
919 IF(NOT index EQUAL -1)
920 MATH(EXPR filename_index "${index} + 1")
921 LIST(GET rc_options ${filename_index} outfile)
922 #LIST(REMOVE_AT rc_options ${index} ${filename_index})
923 ENDIF(NOT index EQUAL -1)
924 # - long option scanning
925 STRING(REGEX MATCH "--output=[^;]*" outfile_opt "${rc_options}")
927 STRING(REPLACE "--output=" "" outfile "${outfile_opt}")
929 #STRING(REGEX REPLACE "--output=[^;]*;?" "" rc_options "${rc_options}")
930 #STRING(REGEX REPLACE ";$" "" rc_options "${rc_options}")
932 IF(NOT IS_ABSOLUTE "${outfile}")
933 SET(outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
934 ENDIF(NOT IS_ABSOLUTE "${outfile}")
937 COMMAND ${wxWidgets_wxrc_EXECUTABLE} ${rc_options} ${rc_file_list_abs}
938 DEPENDS ${rc_file_list_abs} ${rc_depends}
941 # Add generated header to output file list.
942 LIST(FIND rc_options -e short_index)
943 LIST(FIND rc_options --extra-cpp-code long_index)
944 IF(NOT short_index EQUAL -1 OR NOT long_index EQUAL -1)
945 GET_FILENAME_COMPONENT(outfile_ext ${outfile} EXT)
946 STRING(REPLACE "${outfile_ext}" ".h" outfile_header "${outfile}")
947 LIST(APPEND ${_outfiles} "${outfile_header}")
948 SET_SOURCE_FILES_PROPERTIES(
949 "${outfile_header}" PROPERTIES GENERATED TRUE
951 ENDIF(NOT short_index EQUAL -1 OR NOT long_index EQUAL -1)
953 # Add generated file to output file list.
954 LIST(APPEND ${_outfiles} "${outfile}")
956 SET(${_outfiles} ${${_outfiles}} PARENT_SCOPE)
957 ENDFUNCTION(WXWIDGETS_ADD_RESOURCES)