2

I am trying to use find_package to find wxWidgets, which is placed inside the location pointed to my CMAKE_PREFIX_PATH, however I am not succeeding.

If I set the environment variable WXWIDGETS_ROOT_DIR to the wxWidgets installation, then all works fine. However, if I set CMAKE_PREFIX_PATH to the folder containing my folder wxWidgets-3.1.4, wx is not found.

How can I fix this? Where is there documentation on the fact that WXWIDGETS_ROOT_DIR needs to be used? I only found this out through another stack overflow post.

My CMakeLists.txt:

####################
#      Global      #
####################

cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 17)



#####################
#      Project      #
#####################

# Header files (relative to "include" directory)
set(HEADERS
    app.h
)

# Source files (relative to "src" directory)
set(SOURCES
    app.cpp
)

# Compiler definitions
set(DEFINES

)

# Compiler options
set(OPTIONS

)

# Project setup
project("CPP-Sandbox"
        VERSION "0.0.1"
        DESCRIPTION "Description"
        LANGUAGES CXX)

add_executable(CPP-Sandbox)

list(TRANSFORM HEADERS PREPEND "include/")
list(TRANSFORM SOURCES PREPEND "src/")

target_include_directories(CPP-Sandbox PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_sources(CPP-Sandbox PRIVATE ${SOURCES} ${HEADERS})
target_compile_definitions(CPP-Sandbox PRIVATE ${DEFINES})
target_compile_options(CPP-Sandbox PRIVATE ${OPTIONS})

set_target_properties(CPP-Sandbox PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY "bin"
    WIN32_EXECUTABLE true
)



####################
#   Dependencies   #
####################


find_package(wxWidgets REQUIRED COMPONENTS core base)
include(${wxWidgets_USE_FILE})
target_link_libraries(CPP-Sandbox ${wxWidgets_LIBRARIES})
3
  • "Where is there documentation on the fact that WXWIDGETS_ROOT_DIR needs to be used?" - The documentation is here: cmake.org/cmake/help/latest/module/FindwxWidgets.html. If you want to find out why setting CMAKE_PREFIX_PATH is not worked, then you need to provide more details: Your code, the exact error message, the placement of WxWidgets an so. Commented Sep 18, 2021 at 19:04
  • I've added my CMakeLists.txt, but the respt I have already explained. It is simply noting that wxWidgets cannot be found. This is placed in a folder "wxWidgets-3.1.4" which is inside my folder of CMAKE_PREFIX_PATH Commented Sep 18, 2021 at 19:11
  • "This is placed in a folder "wxWidgets-3.1.4" which is inside my folder of CMAKE_PREFIX_PATH" - You probably need to add that wxWidgets-3.1.4 subdirectory to the path in the CMAKE_PREFIX_PATH variable. At least, given script doesn't search under wxWidgets-3.1.4 subdirectory. Commented Sep 18, 2021 at 20:10

1 Answer 1

1

I installed on windows wxWidgets 3.1.4 under C:/wx314_install. It contains the headers and libs file you need for using wxWidgets. After that, you need to set up the different variables for CMake to find the library.

This is my CMakeFile.txt where I say to CMake where to find wxWidgets depending on which mode the program is being compiled, debug, or release. Probably, this last bit can be done differently.

cmake_minimum_required(VERSION 3.20)

message(STATUS "Building SUN")

set(wxWidgets_USE_DEBUG ON)
set(wxWidgets_USE_UNICODE ON)

IF(CMAKE_BUILD_TYPE MATCHES Release)
    message(STATUS "Release mode" )
    set(wxWidgets_ROOT_DIR C:/wx314_install/Release)
    set(wxWidgets_LIB_DIR C:/wx314_install/Release/lib/vc_x64_lib)
    set(wxWidgets_INCLUDE_DIRS C:/wx314_install/Release/include)
ENDIF()

IF(CMAKE_BUILD_TYPE MATCHES Debug)
    message(STATUS "Debug mode" )
    set(wxWidgets_ROOT_DIR "C:/wx314_install/Debug")
    set(wxWidgets_LIB_DIR C:/wx314_install/Debug/lib/vc_x64_lib)
    set(wxWidgets_INCLUDE_DIRS C:/wx314_install/Debug/include)
ENDIF()


message(STATUS "wxWidgets location ${wxWidgets_ROOT_DIR}")
# Note that for MinGW users the order of libs is important!

find_package(wxWidgets REQUIRED net gl core base)

include(${wxWidgets_USE_FILE})

add_executable(app WIN32)

target_sources(app PRIVATE
        src/app.cpp)

target_link_libraries(app PRIVATE ${wxWidgets_LIBRARIES})

This is extracted from this minimal project.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.