开发者

Get version of wxWidgets in CMake

开发者 https://www.devze.com 2023-03-02 05:04 出处:网络
I am trying to determine if the version of wxWidgets found by CMake is >= 2.9. I tried this: find_package(wxWidgets 2.9 COMPONENTS core base REQUIRED)

I am trying to determine if the version of wxWidgets found by CMake is >= 2.9. I tried this:

find_package(wxWidgets 2.9 COMPONENTS core base REQUIRED)
if(wxWidgets_FOUND)
  message("wxWidgets found successfully.")
  include( ${wxWidgets_USE_FILE} )
else()
  message(FATAL_ERROR "wxWidgets was not found!")
endif()

if(wxWidgets_VERSION LESS 2.9)
  message(FATAL_ERROR "wxWidgets is not a high enough version!")
else()
  message("wxWidgets Version ${wxWidgets_VERSION}")
  message("wxWidgets Major version ${wxMAJOR_VERSION}")
  message("release number ${wxRELEASE_NUMBER}")
  message("check version ${wxCHECK_VERSION}")
  message("wxWidgets version ${WX_WIDGETS_VERSION}")
  message("wxWidgets major version ${WX_MAJOR_VERSION}")
  message("wxWidgets version string ${WX_VERSION_STRING}")
endif()

(My system has wx2.8, so th开发者_开发知识库is should fail).

The if(wxWidgets_FOUND) returns TRUE, so so far so good. However, the if(wxWidgets_VERSION LESS 2.9) fails, but it is not because wxWidgets_VERSION is < 2.9. It is because wxWidgets_VERSION is empty. In fact, the whole output is:

wxWidgets Version 
wxWidgets Major version 
release number 
check version 
wxWidgets version 
wxWidgets major version 
wxWidgets version string 

(i.e. all of the variables are empty)

Does anyone know the correct way to check for the wxWidgets version through CMake?

Thanks,

David


On my Ubuntu 18.04.2 LTS CMake command:

find_package(wxWidgets REQUIRED)

calls macro:

/usr/share/cmake-3.10/Modules/FindwxWidgets.cmake

which sets following variables:

wxWidgets_VERSION_STRING   # 3.0.4
wxWidgets_VERSION_MAJOR    # 3
wxWidgets_VERSION_MINOR    # 0
wxWidgets_VERSION_PATCH    # 4

So following code checks the version:

find_package(wxWidgets REQUIRED)
include(${wxWidgets_USE_FILE})

if (wxWidgets_VERSION_STRING LESS 2.9)
    message("Version < 2.9")
endif()

# Or
if (wxWidgets_VERSION_STRING GREATER_EQUAL 2.9)
    message("Version >= 2.9")
endif()


Someone suggested a project named wxArt2d that has a bit better wxWidgets cmake. It is unfortunate that these things are not easier/better maintained :(


Open terminal and write

wx-config --version
0

精彩评论

暂无评论...
验证码 换一张
取 消