KamikaZimon
KamikaZimon

Reputation: 65

Cmake cannot find wxWidgets on Windows

I have searched for this topic and found this and this, but it only seems to either pertain to building wxWidgets or do not contain an answer to my question.

I have built the static libs für wxWidgets on Windows successfully, but I am now struggling to correctly include the libraries to my project using Cmake. This is my CMakeLists.txt:

set(PROJECT_NAME wxapp)
project(${PROJECT_NAME})
cmake_minimum_required(VERSION 2.8)
    
set(SRC_LIST main.cpp app.cpp app.h frame.cpp frame.h)
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})
    
find_package(wxWidgets REQUIRED net gl core base)
include(${wxWidgets_USE_FILE})
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
    
set(wxWidgets_USE_LIBS ON)
set(wxWidgets_CONFIGURATION msw)

I have set the WXWIN path variable correctly. Yet, CMake throws an error with this configuration:

Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
wxWidgets_INCLUDE_DIRS net gl core base)

I have tried multiple suggestions, like using downloading prebuild dynamic libraries and adding them manually as suggested here, e.g.

set(wxWidgets_ROOT_DIR $ENV{WXWIN})
set(wxWidgets_LIBRARIES $ENV{WXWIN}/include)
set(wxWidgets_INCLUDE_DIR $ENV{WXWIN}/lib/vc14x_x64_dll)

include_directories(includes $ENV{WXWIN} $ENV{WXWIN}/include $ENV{WXWIN}/lib/vc14x_x64_dll)

link_directories($ENV{WXWIN} $ENV{WXWIN}/include $ENV{WXWIN}/lib/vc14x_x64_dll) # this seems to be a discouraged/deprecated method

but all to no avail.

Upvotes: 1

Views: 4451

Answers (1)

KamikaZimon
KamikaZimon

Reputation: 65

WORKAROUND (at least it works for me):

I changed the find_package command from the suggested statement:

find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net)

to

find_package(wxWidgets 3.1 REQUIRED)

A user in this post had this included in his/her CMake file and out of deperation, I tried this and it actually worked. Seems like the configuration of CMake under certain unknown circumstances won't function correctly with the statement provided in the instructions. If I change the command to the new statement my static build as well as self- and precompiled dlls are flawlessly identifed by CMake.

I also cleared the CMake cache, inspired by this post. According to this post, there seems to be an issue with Windows and the CMake cache in some situations, but the reasons escape me. I could replicate the behaviour observed by the user there:

Under Windows, you have to point to the installation directory, e.g.

set(wxWidgets_ROOT_DIR "C:/wxWidgets-3.1.3") set(wxWidgets_LIB_DIR "C:/wxWidgets-3.1.3/lib/vc14x_x64_dll")

But then the behavior is still strange. When i use CMake GUI (3.16, latest), behavior is like this

  1. delete cache (just to be consistent)
  2. press 'configure' button --> fail: CMake Error at C:/Program Files/CMake/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message): Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS core base qa adv net html gl propgrid richtext)
  3. press 'configure' button again --> success

I also have observed some inconsistent behaviour of CMake within the IDEs CLion and CodeBlocks when clearing the cache and reloading the project.

So, exactly how the cache clearing plays into the resolution of my issue, I don't know. But if I merely clear the cache, reload my project and leave the CMake instruction at find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net), CMake won't find my installation despite the WXWIN path being set correctly.

If you know more about this, I am happy to be corrected.

Upvotes: 3

Related Questions