CMake allows building wxWidgets on various platforms with your preferred build system.
Most linux distributions contain CMake as a package on Windows and macOS you can download an installer at the CMake Page.
cmake -G "Unix Makefiles" path_to_wxWidgets_root
cmake --build .
to start the build process or directly use your chosen build system.Run cmake --help
to see a list of available generators on your platform. These can than be specified using the -G command line option. On Windows it is recommended to use Visual Studio and on macOS Xcode is recommended. Various build options can be specified using -D see available options.
Building with tests using Ninja:
Building the minimal sample:
Installing static libraries to some path:
The following list of build options can either be configured in the CMake UI or specified via the -D command line option when running the cmake command.
Option Name | Type | Default | Description |
---|---|---|---|
wxBUILD_SHARED | BOOL | ON | Build shared or static libraries |
wxBUILD_TESTS | STRING | OFF | CONSOLE_ONLY, ALL or OFF |
wxBUILD_SAMPLES | STRING | OFF | SOME, ALL or OFF |
wxBUILD_DEMOS | BOOL | OFF | Build demo applications |
wxUSE_GUI | BOOL | ON | Build the UI libraries |
wxBUILD_COMPATIBILITY | STRING | 3.2 | Enable API compatibility with 3.0, 3.2 or neither ("NONE") |
wxBUILD_PRECOMP | BOOL | ON | Use precompiled headers |
wxBUILD_MONOLITHIC | BOOL | OFF | Build a single library |
Note that on macOS, the option CMAKE_OSX_ARCHITECTURES
is used to specify which architecture(s) to build. For example, the following will build a "universal binary 2" (i.e., ARM64 and Intel x86_64) library.
A complete list of options and advanced options can be found when using the CMake GUI.
While CMake in wxWidgets aims to support most generators available in CMake, the following generators are recommended:
CMake 3.10 or newer is recommended. The minimum tested version is 3.5.
If you are using CMake with your own application, there are various ways to use wxWidgets:
find_package()
You can use find_package(wxWidgets)
to use a compiled version of wxWidgets. Have a look at the CMake Documentation for detailed instructions. wxWidgets also provides an example CMake file in the minimal sample folder.
WARNING: Please note that CMake findwxWidgets
module unfortunately doesn't detect wxWidgets 3.2.0 in versions of CMake older than 3.24. You may copy the latest version of FindwxWidgets.cmake
from CMake sources to your system to fix this or, if you build wxWidgets itself using CMake, use CONFIG
mode of find_package()
which works even with older CMake versions.
Your CMakeLists.txt would look like this:
You can use wxWidgets as a subdirectory in your application's build tree e.g. as a git submodule. This way the wxWidgets libraries will be part of your applications build process.
Your CMakeLists.txt would look like this:
Note that you can predefine the build options before using add_subdirectory()
by either defining them on command line with e.g. -DwxBUILD_SHARED=OFF
, or by adding
to your CMakeLists.txt if you want to always use static wxWidgets libraries.
To embed XRC resources into your application, you need to define a custom command to generate a source file using wxrc
. When using an installed version of wxWidgets you can just use wxrc
directly, but when using wxWidgets from a subdirectory you need to ensure that it is built first and use the correct path to it, e.g.: