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 scintilla lexilla).

对于 Unix 风格,它使用 wx-config 工具。您可以在 QtDialog 或 ccmake 界面中,通过开启/关闭以下变量来选择调试/发布、Unicode/ANSI、通用/非通用以及静态/共享。

wxWidgets_USE_DEBUG
wxWidgets_USE_UNICODE
wxWidgets_USE_UNIVERSAL
wxWidgets_USE_STATIC

还有一个 wxWidgets_CONFIG_OPTIONS 变量,用于传递给 wx-config 工具的其他所有选项。例如,要使用在 /usr/local 路径中找到的 base 工具包,请(在调用 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_CONFIGWXRC_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})

导入的目标

在 3.27 版本中新增。

此模块定义了以下 IMPORTED 目标:

wxWidgets::wxWidgets

一个提供已找到组件使用要求的接口库。