Clone wiki

codetrainer / New wxWidgets project with cmake

One way of creating a new wxWidgets project is to start by compiling a wxWidgets sample and moving it into a new folder. This may not represent a fresh start but it's a solution.

Creating a new wxWidgets project might not be just as easy as it is for other GUI frameworks like QT and MFC but with the help of cmake this may prove pretty simple.

Here you'll be offered the steps needed to use a cmake for your wxWidgets project.

  1. Make sure you've compiled wxWidgets and installed cmake as specified in the prerequisites. This means that wxWidgets is compiled and WXWIN variable is set.
  2. Let's get the minimal.cpp file from samples\minimal and place it in a folder (without spaces for simplicity). I am using C:\Code\MywxProject
  3. In the same folder create a file called CMakeLists.txt with the following contents:
    PROJECT (minmal)
    FIND_PACKAGE(wxWidgets COMPONENTS base core base adv REQUIRED) # other components can be added
    ADD_EXECUTABLE(minimal WIN32 minimal.cpp)

Compiling your project

  1. Now you'll have these files in the folder where you've placed minimal.cpp: CMakeLists.txt, minimal.cpp
  2. Open cmake-gui and select the source code to point to the location where you've placed minimal.cpp (C:\Code\MywxProject in my case). See the image below for details: wxwidgets_cmake.png We've selected the build directory to be out of the source tree (C:\Code\MywxProject-build in my case). The folder can be anywhere but many times it's good practice to put it outside the source tree.
  3. Click Configure, select the Visual Studio you've used to build wxWidgets and then click Generate
  4. Go to the build directory (C:\Code\MywxProject-build in this example) and open minimal.sln with Visual Studio version you've used to build wxWidgets
  5. Build the solution and check if Debug / Release folder was created and if it contains minimal.exe
  6. To run your executable: make sure to copy the wxWidgets DLLs where your executable is or add the wxWidgets DLL folder to the PATH environment variable. This is explained in the tutorial for compiling a wxWidgets sample