4

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.

Steven Feng
  • 61
  • 2
  • 5
  • did you build the libraries on Windows? Which compiler do you use? – Igor Oct 04 '17 at 02:30
  • I didn't build it manually, just add wxWidgets as a submodule. On ubuntu, CMake could automatically handle the build for me, as described in the wiki. I hope it could work on windows. The compiler is VS 2017. – Steven Feng Oct 04 '17 at 03:28
  • 1
    wxWidgets is not (and hopefully never be) CMake ready. On Linux it is covered by gcc Automake and friends build system. Windows is different. Just build the libraries. Open c:\wxWidgets\build\msw\wx.sln, then select "Build->Batch Build..." and build everything. Then try to build your software again. – Igor Oct 04 '17 at 03:32
  • 2
    @Igor "and hopefully never be CMake ready" Why do you say hopefully never? – legalize Oct 05 '17 at 20:12
  • @legalize He apparently had bad times with CMake. – Nahiyan Apr 05 '21 at 04:29

1 Answers1

1

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

Usitha Indeewara
  • 870
  • 3
  • 10
  • 21
  • What dose the text CONFIG used for? Can you explain it? Thanks. – ollydbg23 Dec 04 '22 at 14:48
  • I actually don't know what it does, xD. I found the solution from an [issue at the wxWidgets GitHub repository](https://github.com/wxWidgets/wxWidgets/issues/22861). The issue creator says `...Open CMakeLists.txt in that directory and add these lines before **find_package(wxWidgets 3.3 COMPONENTS core base REQUIRED CONFIG)** so that Findwxwidgets looks for wxWidgets in...` and I tried adding `CONFIG`. Then it works without any errors. xD @ollydbg23 – Usitha Indeewara Dec 05 '22 at 12:30
  • Hi, @Usitha Indeewara, thanks for the response, by some Google search, I found that the keyword `CONFIG` means the config file is supplied by the package, see this link: [cmake-packages(7) — CMake 3.25.1 Documentation](https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html), but I'm not sure why wxWidgets supply a config file or not, since many compilers can build wxWidgets. – ollydbg23 Dec 09 '22 at 04:04
  • 1
    In the wx's cmake document webpage: [wxWidgets: CMake Overview](https://docs.wxwidgets.org/3.2.0/overview_cmake.html), it said: `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.`, so it looks like when you build with `CMake`, you should add the `CONFIG` option. – ollydbg23 Dec 09 '22 at 04:14