Browse Source

FindwxWidgets: Add wxWidgets_VERSION

This deprecates the wxWidgets_VERSION_STRING result variable.

Issue: #27088
Peter Kokot 3 months ago
parent
commit
559500bede

+ 4 - 0
Help/release/dev/find-modules.rst

@@ -94,3 +94,7 @@ Find Modules
 
 * The :module:`FindTIFF` module now provides a ``TIFF_VERSION`` result
   variable.  The ``TIFF_VERSION_STRING`` result variable is deprecated.
+
+* The :module:`FindwxWidgets` module now provides a ``wxWidgets_VERSION``
+  result variable.  The ``wxWidgets_VERSION_STRING`` result variable is
+  deprecated.

+ 20 - 7
Modules/FindwxWidgets.cmake

@@ -92,8 +92,8 @@ This module defines the following variables:
   Boolean indicating whether (the requested version of) wxWidgets and all
   its requested components are found.
 
-``wxWidgets_VERSION_STRING``
-  .. versionadded:: 3.4
+``wxWidgets_VERSION``
+  .. versionadded:: 4.2
 
   The version of the wxWidgets found.
 
@@ -190,6 +190,19 @@ ON/OFF the following variables:
 
     set(wxWidgets_CONFIG_OPTIONS --toolkit=base --prefix=/usr)
 
+Deprecated Variables
+^^^^^^^^^^^^^^^^^^^^
+
+The following variables are provided for backward compatibility:
+
+``wxWidgets_VERSION_STRING``
+  .. deprecated:: 4.2
+    Use ``wxWidgets_VERSION``, which has the same value.
+
+  .. versionadded:: 3.4
+
+  The version of the wxWidgets found.
+
 Examples
 ^^^^^^^^
 
@@ -365,12 +378,12 @@ macro(wx_extract_version)
   string(REGEX REPLACE "^(.*\n)?#define +wxSUBRELEASE_NUMBER +([0-9]+).*"
     "\\2" wxWidgets_VERSION_TWEAK "${_wx_version_h}" )
 
-  set(wxWidgets_VERSION_STRING
-    "${wxWidgets_VERSION_MAJOR}.${wxWidgets_VERSION_MINOR}.${wxWidgets_VERSION_PATCH}" )
+  set(wxWidgets_VERSION
+    "${wxWidgets_VERSION_MAJOR}.${wxWidgets_VERSION_MINOR}.${wxWidgets_VERSION_PATCH}")
   if(${wxWidgets_VERSION_TWEAK} GREATER 0)
-    string(APPEND wxWidgets_VERSION_STRING ".${wxWidgets_VERSION_TWEAK}")
+    string(APPEND wxWidgets_VERSION ".${wxWidgets_VERSION_TWEAK}")
   endif()
-  dbg_msg("wxWidgets_VERSION_STRING:    ${wxWidgets_VERSION_STRING}")
+  set(wxWidgets_VERSION_STRING "${wxWidgets_VERSION}")
 endmacro()
 
 #=====================================================================
@@ -1132,7 +1145,7 @@ endif()
 
 find_package_handle_standard_args(wxWidgets
   REQUIRED_VARS wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS
-  VERSION_VAR   wxWidgets_VERSION_STRING
+  VERSION_VAR wxWidgets_VERSION
   ${wxWidgets_HANDLE_COMPONENTS}
   )
 unset(wxWidgets_HANDLE_COMPONENTS)

+ 2 - 0
Tests/CMakeOnly/AllFindModules/CMakeLists.txt

@@ -105,6 +105,7 @@ foreach(
     PERL PKG_CONFIG PNG PostgreSQL
     SDL
     TIFF
+    wxWidgets
     ZLIB
 )
   check_version_string(${VTEST} ${VTEST}_VERSION_STRING)
@@ -127,6 +128,7 @@ foreach(
     Ruby RUBY
     SDL SWIG
     TIFF
+    wxWidgets
     ZLIB
 )
   check_version_string(${VTEST} ${VTEST}_VERSION)

+ 2 - 0
Tests/FindwxWidgets/Test/CMakeLists.txt

@@ -4,6 +4,8 @@ include(CTest)
 
 find_package(wxWidgets REQUIRED)
 
+add_compile_definitions(CMAKE_EXPECTED_WXWIDGETS_VERSION="${wxWidgets_VERSION}")
+
 add_executable(test_tgt main.cpp)
 target_link_libraries(test_tgt wxWidgets::wxWidgets)
 add_test(NAME test_tgt COMMAND test_tgt)

+ 18 - 1
Tests/FindwxWidgets/Test/main.cpp

@@ -1,7 +1,24 @@
+#include <cstring>
+#include <iostream>
+#include <string>
+
 #include <wx/filefn.h>
+#include <wx/version.h>
 
 int main()
 {
   wxGetCwd();
-  return 0;
+
+  std::string found_version = std::to_string(wxMAJOR_VERSION) + "." +
+    std::to_string(wxMINOR_VERSION) + "." + std::to_string(wxRELEASE_NUMBER);
+
+#if wxSUBRELEASE_NUMBER > 0
+  found_version += "." + std::to_string(wxSUBRELEASE_NUMBER);
+#endif
+
+  std::cout << "Found wxWidgets version " << found_version
+            << ", expected version " << CMAKE_EXPECTED_WXWIDGETS_VERSION
+            << "\n";
+
+  return std::strcmp(found_version.c_str(), CMAKE_EXPECTED_WXWIDGETS_VERSION);
 }