Steven Feng
Steven Feng

Reputation: 61

CMake could not find wxWidgets on Windows

I have the following snippet in my CMakeLists.txt, as described in wxWidgets wiki

set(wxWidgets_ROOT_DIR libs/wxWidgets)
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets REQUIRED
        COMPONENTS core base adv)
include(${wxWidgets_USE_FILE})

libs/wxWidgets is a git submodule. On Ubuntu 16.04, the project builds and works. The submodule description is:

[submodule "libs/wxWidgets"]
    path = libs/wxWidgets
    url = https://github.com/wxWidgets/wxWidgets
    branch = WX_3_0_3_BRANCH

However, having the same code on Windows doesn't work, with error like:

CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
      Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
  wxWidgets_INCLUDE_DIRS)
Call Stack (most recent call first):
  C:/Program Files (x86)/CMake/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:377 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files (x86)/CMake/share/cmake-3.9/Modules/FindwxWidgets.cmake:953 (find_package_handle_standard_args)
  CMakeLists.txt:8 (find_package)

Other wxWidgets installation from official site, including zip and Windows Installer are tried, but yeilding the same error.

This question might be related, but it has no acceptable answers.

Upvotes: 4

Views: 3375

Answers (1)

Usitha Indeewara
Usitha Indeewara

Reputation: 1005

Try using the following code:

set(wxWidgets_DIR "path/to/wxWidgets/lib/cmake/wxWidgets")

find_package(wxWidgets REQUIRED core base CONFIG) #Don't forget to add this 'CONFIG'
include(UsewxWidgets)

This works for me in wxWidgets 3.2.1

Upvotes: 1

Related Questions