FindwxWidgets¶
查找 wxWidgets(又名 wxWindows)安装。
该模块查找是否安装了 wxWidgets 并选择要使用的默认配置。 wxWidgets 是一个模块化的库。要指定您将使用的模块,您需要将它们命名为包的组件:
find_package(wxWidgets COMPONENTS core base ... OPTIONAL_COMPONENTS net ...)
在 3.4 版本加入: 支持 find_package() 版本参数; webview 组件。
在 3.14 版本加入: OPTIONAL_COMPONENTS 支持。
有两个搜索分支:windows 风格和 unix 风格。对于 windows,在多选的情况下,搜索以下变量并设置为默认值。如果不需要默认值,请更改它们(即,这些是您应该更改以选择配置的唯一变量):
wxWidgets_ROOT_DIR - Base wxWidgets directory
(e.g., C:/wxWidgets-3.2.0).
wxWidgets_LIB_DIR - Path to wxWidgets libraries
(e.g., C:/wxWidgets-3.2.0/lib/vc_x64_lib).
wxWidgets_CONFIGURATION - Configuration to use
(e.g., msw, mswd, mswu, mswunivud, etc.)
wxWidgets_EXCLUDE_COMMON_LIBRARIES
- Set to TRUE to exclude linking of
commonly required libs (e.g., png tiff
jpeg zlib regex expat).
对于 unix 风格,它使用 wx-config 实用程序。您可以通过打开/关闭以下变量在 QtDialog 或 ccmake 界面中的调试/发布、unicode/ansi、通用/非通用和静态/共享之间进行选择:
wxWidgets_USE_DEBUG
wxWidgets_USE_UNICODE
wxWidgets_USE_UNIVERSAL
wxWidgets_USE_STATIC
对于需要传递给 wx-config 实用程序的所有其他选项,还有一个 wxWidgets_CONFIG_OPTIONS 变量。例如,要使用在 /usr/local 路径中找到的基本工具包,请将变量(在调用 FIND_PACKAGE 命令之前)设置为:
set(wxWidgets_CONFIG_OPTIONS --toolkit=base --prefix=/usr)
windows和unix风格配置完成后设置如下:
wxWidgets_FOUND - Set to TRUE if wxWidgets was found.
wxWidgets_INCLUDE_DIRS - Include directories for WIN32
i.e., where to find "wx/wx.h" and
"wx/setup.h"; possibly empty for unices.
wxWidgets_LIBRARIES - Path to the wxWidgets libraries.
wxWidgets_LIBRARY_DIRS - compile time link dirs, useful for
rpath on UNIX. Typically an empty string
in WIN32 environment.
wxWidgets_DEFINITIONS - Contains defines required to compile/link
against WX, e.g. WXUSINGDLL
wxWidgets_DEFINITIONS_DEBUG- Contains defines required to compile/link
against WX debug builds, e.g. __WXDEBUG__
wxWidgets_CXX_FLAGS - Include dirs and compiler flags for
unices, empty on WIN32. Essentially
"`wx-config --cxxflags`".
wxWidgets_USE_FILE - Convenience include file.
在 3.11 版本加入: 以下环境变量可用作提示:WX_CONFIG、WXRC_CMD。
示例用法:
# Note that for MinGW users the order of libs is important!
find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net)
if(wxWidgets_FOUND)
include(${wxWidgets_USE_FILE})
# and for each of your dependent executable/library targets:
target_link_libraries(<YourTarget> ${wxWidgets_LIBRARIES})
endif()
如果需要 wxWidgets(即,不是可选部分):
find_package(wxWidgets REQUIRED gl core base OPTIONAL_COMPONENTS net)
include(${wxWidgets_USE_FILE})
# and for each of your dependent executable/library targets:
target_link_libraries(<YourTarget> ${wxWidgets_LIBRARIES})