Cmake cannot find WxWidgets

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
cobralasers
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Mar 01, 2022 8:53 pm

Cmake cannot find WxWidgets

Post by cobralasers »

I know there are other posts on this topic but I haven't had any luck with them.
Using Rocky Linux 9.1
CMake-3.9.4 (it's part of a toolchain, I have had the same luck with CMake-3.25)

The curious thing is that this same setup worked just fine on CentOS-7. Tis is a summary of the top level CMakeLists.txt:

Code: Select all

set(CMAKE_MODULE_PATH  ${CMAKE_SOURCE_DIR}/cmake_modules)

# Load the expected versions of third party libraries
include(version_module)
make_minimum_required(VERSION ${CMAKE_VERSION}...3.9)
set_filename_component(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../.. REALPATH)
include(project_CMakeLists)
project_CMakeLists.cmake:

Code: Select all

project(foo)

set(wxWidgets_LIBS base core net adv webview)
if (STEP STREQUAL tools)
    add_subdirectory(tools)
else()
    add_subdirectory(foo_bar)
endif()
tools CMakeLists.txt:

Code: Select all

project(tools)

set(CMAKE_MODULE_PATH
        ${PROJECT_SOURCE_DIR}/cmake_modules
        ${CMAKE_MODULE_PATH})
        
include(wxWidgets)
I extract the wxWidgets-tar ball to non-system user directory. wxWidgets.cmake looks like this:

Code: Select all

set(WXWIDGETS_NAME wxWidgets-${WXWIDGETS_VERSION})
set(WXWIDGETS_SRC ${TOOLCHAIN_DIR}/src/${WXWIDGETS_NAME})
set(WXWIDGETS_OBJ ${TOOLCHAIN_DIR}/obj/${WXWIDGETS_NAME})

if (DEFINED test AND test MATCHES "ON")
	set(WXWIDGETS_INSTALL ${TOOLCHAIN_DIR}/bin/${WXWIDGETS_NAME}/Debug)
	set(WXWIDGETS_DEBUG "--enable-debug")
else()
	set(WXWIDGETS_INSTALL ${TOOLCHAIN_DIR}/bin/${WXWIDGETS_NAME}/Release)
	set(WXWIDGETS_DEBUG "--disable-debug")
endif()
MESSAGE(STATUS	"+++DEBUG wxWidgets_CONFIG_EXECUTABLE ${WXWIDGETS_INSTALL}/bin/wx-config")
set(wxWidgets_CONFIG_EXECUTABLE "${WXWIDGETS_INSTALL}/bin/wx-config")

find_package(wxWidgets COMPONENTS base core adv QUIET NO_DEFAULT_PATH)

if (NOT wxWidgets_FOUND)
	ExternalProject_Add(
		wxWidgets
		URL file://${ROOT_DIR}/thirdparty/${WXWIDGETS_NAME}.tar.bz2
		URL_HASH SHA256=e082460fb6bf14b7dd6e8ac142598d1d3d0b08a7b5ba402fdbf8711da7e66da8
		BINARY_DIR ${WXWIDGETS_OBJ}
		INSTALL_DIR ${WXWIDGETS_INSTALL}
		UPDATE_COMMAND ""
		PATCH_COMMAND ""
		CONFIGURE_COMMAND ${WXWIDGETS_SRC}/configure CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} --with-gtk=3 --with-gtk_prefix=/usr/share/gtk-3.0 --with-gtk_exec_prefix=/usr/lib64/gtk-3.0 --enable-graphics_ctx --enable-webkit --enable-unicode --disable-ribbon --disable-richtext --disable-xrc --disable-detect_sm --disable-mediactrl --disable-mdi --disable-gtktest --disable-sdltest ${WXWIDGETS_DEBUG} --prefix=${WXWIDGETS_INSTALL} --disable-sys-libs --without-opengl --without-libnotify --without-gtkprint
		BUILD_COMMAND make
		INSTALL_COMMAND make install
		SOURCE_DIR ${WXWIDGETS_SRC}
		BUILD_IN_SOURCE 0
	)
endif()
foo CMakeLists.txt

Code: Select all

project(foo_bar)

set(CMAKE_MODULE_PATH
        ${PROJECT_SOURCE_DIR}/cmake_modules
        ${CMAKE_MODULE_PATH})
        
include(bar_CMakeLists)
bar_CMakeLists.cmake summary:

Code: Select all

include(wxwidgets)
second wxwidgets.cmake module:

Code: Select all

set(WXWIDGETS_NAME wxWidgets-${WXWIDGETS_VERSION})
set(WXWIDGETS_INSTALL ${TOOLCHAIN_DIR}/bin/${WXWIDGETS_NAME}/Release)
set(wxWidgets_CONFIG_EXECUTABLE "${WXWIDGETS_INSTALL}/bin/wx-config")

find_package(wxWidgets ${WXWIDGETS_VERSION} EXACT REQUIRED ${wxWidgets_LIBS})
With all the above, CMake cannot find wxWidgets.

Code: Select all

CMake Error at /home/u_name/temp/toolchain/bin/cmake-3.9.4/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
  wxWidgets_INCLUDE_DIRS) (Required is exact version "3.1.0")
Again I note this same setup works just fine on CentOS-7, can't imagine what the difference would be. From what I understand, on Unix like system wx uses the wx-config tool. I added this in the top CMakeLists.txt file for debugging:

Code: Select all

set(WXWIDGETS_NAME wxWidgets-${WXWIDGETS_VERSION})
set(WXWIDGETS_INSTALL ${TOOLCHAIN_DIR}/bin/${WXWIDGETS_NAME}/Release)
set(wxWidgets_CONFIG_EXECUTABLE "${WXWIDGETS_INSTALL}/bin/wx-config")

set(ENV{WX_CONFIG} ${wxWidgets_CONFIG_EXECUTABLE})
execute_process(
        COMMAND sh ${wxWidgets_CONFIG_EXECUTABLE} --version
        OUTPUT_VARIABLE WX_VERSION
        OUTPUT_STRIP_TRAILING_WHITESPACE)

if("${WX_VERSION}" VERSION_LESS "3.1.0")
    message(
            FATAL_ERROR
            "I'm afraid your wxWidgets version is too old.\nBuilding CodeLite requires at least wxWidgets-3.1.0"
    )
else()
    MESSAGE(STATUS  "WX_VERSION found: ${WX_VERSION}")
endif()
execute_process(
        COMMAND ${wxWidgets_CONFIG_EXECUTABLE} --selected_config
        OUTPUT_VARIABLE WX_GTK_VERSION
        OUTPUT_STRIP_TRAILING_WHITESPACE)
string(SUBSTRING "${WX_GTK_VERSION}" "3" "1" GTK_VERSION)
message("-- gtk version is: ${GTK_VERSION}")
if(wxWidgets_FOUND)
    message("+++DEBUG FOUND Widgets")
    include(${wxWidgets_USE_FILE})
endif()

And you can see from the output it found and used the wx-config tool:

Code: Select all

-- WX_VERSION found: 3.1.0
-- gtk version is: 3
Any ideas what might be misconfigured?
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Cmake cannot find WxWidgets

Post by DavidHart »

Hi,

I don't know anything about Rocky (indeed I had to look it up) and you don't mention what you're trying to build. However the error message :
I'm afraid your wxWidgets version is too old.\nBuilding CodeLite requires at least wxWidgets-3.1.0"
makes it look as if it's CodeLite.

If so I suggest you have a look at the srpm section of the CodeLite unofficial download page and see what you're doing that's different.

Regards,

David
cobralasers
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Mar 01, 2022 8:53 pm

Re: Cmake cannot find WxWidgets

Post by cobralasers »

I'm afraid your wxWidgets version is too old.\nBuilding CodeLite requires at least wxWidgets-3.1.0
This is just sloppy copy/paste. Looking for possible configuration solutions I found a post (which i cannot seem to relocate...) that mentioned that CodeLite 'finds wxwidgets manually". So navigating here: https://github.com/eranif/codelite/blob ... eLists.txt I borrowed the relavant code chunck to see what I would find. Using that code snippet, you can see in the output it uses wx-config to output the version of wx installed.

THe project structure looks a bit complicated because there are actually many other projects being built. In this case however, I am just trying to compile a small application that uses wxWidgets. I compile and install wx into a toolchain location and then compile the app against it. I cannot get to the compiling the app part because CMake cannot find wxwidgets.
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Cmake cannot find WxWidgets

Post by DavidHart »

OK. Then I don't know why you have that problem, especially if it's only on one distro. However a couple of suggestions (which you've probably already tried, but still...)

1) Check (on Rocky) that the wxWidgets samples build and run, and that they find the correct wx headers and libs. You can confirm this for any program built against wxWidgets by setting focus to that program, and then doing Ctrl-Alt-Middleclick.

2) If that succeeds you know thatyour wx is available, so it's a question of why your CMakeLists.txt fails to find it. I can only suggest you put more debugging MESSAGEs in your CMakeLists.txt to find what it's looking for, and where. If you have a separate 'Find wxWidgets' module, add some there too.
As a sanity-check, you could also try hard-coding the correct paths.

I'm sorry I can't be of more help.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Cmake cannot find WxWidgets

Post by ONEEYEMAN »

Hi,
Please update to the latest and greatest CMake-thingy.
There was a bug that prevented it to find wxWidgets latest version and it should be already fixed upstream.

If this is not the case - please try to build with the defaultt "configure + make" way and wit for the nexdt release of CMake-thingy in order to build your project.

Thank you.
Post Reply