# UsewxWidgets

This module serves as a convenience wrapper for using the wxWidgets library (formerly known as wxWindows) and propagates its usage requirements, such as library directories, include directories, and compiler flags, into the current directory scope for use by targets.

Load this module in a CMake project with:

    include(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)`.

## Examples

Include this module in a project after finding wxWidgets to configure its usage requirements:

`CMakeLists.txt`

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

    add_library(example example.cxx)

    if(wxWidgets_FOUND)
      include(UsewxWidgets)

      # Link wxWidgets libraries for each dependent executable/library target.
      target_link_libraries(example PRIVATE ${wxWidgets_LIBRARIES})
    endif()

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 COMPONENTS net gl core base)

    add_library(example example.cxx)

    # Link the imported target for each dependent executable/library target.
    target_link_libraries(example PRIVATE wxWidgets::wxWidgets)

## See Also

- The `FindwxWidgets` module to find wxWidgets.