UsewxWidgets

This module calls include_directories() and link_directories(), sets compile definitions for the current directory and appends some compile flags to use wxWidgets library after calling the find_package(wxWidgets).

範例

Include UsewxWidgets module in project's CMakeLists.txt:

# Note that for MinGW users the order of libraries is important.
find_package(wxWidgets REQUIRED net gl core base)

# Above also sets the wxWidgets_USE_FILE variable that points to this module.
include(${wxWidgets_USE_FILE})

# Link wxWidgets libraries for each dependent executable/library target.
target_link_libraries(<ProjectTarget> ${wxWidgets_LIBRARIES})

As of CMake 3.27, a better approach is to link only the wxWidgets::wxWidgets IMPORTED target to specific targets that require it, rather than including this module. Imported targets provide better control of the package usage properties, such as include directories and compile flags, by applying them only to the targets they are linked to, avoiding unnecessary propagation to all targets in the current directory.

# CMakeLists.txt
find_package(wxWidgets)

# Link the imported target for each dependent executable/library target.
target_link_libraries(<ProjectTarget> wxWidgets::wxWidgets)