Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to build wxWidgets program using CMake

📅 2014-Jul-21 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

Configuring a project that uses wxWidgets to build on Windows is quite simple. However, on Linux the same task is a bit more involved and requires using the wx-config program.

CMake has support for wxWidgets, but requires knowing the right incantations to build. A minimal CMakeLists.txt for building a wxWidgets program is given below:

project(helloapp)

cmake_minimum_required(VERSION 2.8)

find_package(wxWidgets COMPONENTS core base REQUIRED)

include( "${wxWidgets_USE_FILE}" )

add_executable(
    ${PROJECT_NAME}
    helloapp.cpp
    )

target_link_libraries(
    ${PROJECT_NAME}
    ${wxWidgets_LIBRARIES}
    )

This includes the core and base wxWidgets libraries. If you use any other wxWidgets modules, like wxGLCanvas for example, then include the relevant modules, like gl in the find_package command.

Tried with: wxWidgets 3.0, CMake 2.8.12.2 and Ubuntu 14.04