SDL: wikiheaders.pl: add --rev= option to pass revision string

From e85206ffd8becd33321182614e2ba5a5d304a5a3 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 4 Sep 2023 18:56:00 +0200
Subject: [PATCH] wikiheaders.pl: add --rev= option to pass revision string

This way, git is not required anymore to calculate the git revision
---
 CMakeLists.txt               |  1 +
 build-scripts/wikiheaders.pl | 10 ++++++++--
 cmake/sdlmanpages.cmake      | 12 +++++++++---
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c97a3989b2fd..c9108712d5f3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3360,6 +3360,7 @@ if(NOT SDL_DISABLE_INSTALL)
     SDL_generate_manpages(
       SYMBOL "SDL_Init"
       WIKIHEADERS_PL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build-scripts/wikiheaders.pl"
+      REVISION "${SDL_REVISION}"
     )
     if(TARGET SDL3-javadoc)
       set(SDL_INSTALL_JAVADOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/javadoc" CACHE PATH "Path where to install SDL3 javadoc")
diff --git a/build-scripts/wikiheaders.pl b/build-scripts/wikiheaders.pl
index bb09faa8c00f..a2792a865a2e 100755
--- a/build-scripts/wikiheaders.pl
+++ b/build-scripts/wikiheaders.pl
@@ -31,6 +31,7 @@
 my $wikipreamble = undef;
 my $changeformat = undef;
 my $manpath = undef;
+my $gitrev = undef;
 
 foreach (@ARGV) {
     $warn_about_missing = 1, next if $_ eq '--warn-about-missing';
@@ -47,6 +48,9 @@
     } elsif (/\A--manpath=(.*)\Z/) {
         $manpath = $1;
         next;
+    } elsif (/\A--rev=(.*)\Z/) {
+        $gitrev = $1;
+        next;
     }
     $srcpath = $_, next if not defined $srcpath;
     $wikipath = $_, next if not defined $wikipath;
@@ -1437,8 +1441,10 @@ sub usage {
     close(FH);
     }
 
-    my $gitrev = `cd "$srcpath" ; git rev-list HEAD~..`;
-    chomp($gitrev);
+    if (!$gitrev) {
+        $gitrev = `cd "$srcpath" ; git rev-list HEAD~..`;
+        chomp($gitrev);
+    }
 
     # !!! FIXME
     open(FH, '<', "$srcpath/$versionfname") or die("Can't open '$srcpath/$versionfname': $!\n");
diff --git a/cmake/sdlmanpages.cmake b/cmake/sdlmanpages.cmake
index 0049de1f94a4..cc706dd709fe 100644
--- a/cmake/sdlmanpages.cmake
+++ b/cmake/sdlmanpages.cmake
@@ -2,7 +2,9 @@ include(CMakeParseArguments)
 include(GNUInstallDirs)
 
 function(SDL_generate_manpages)
-  cmake_parse_arguments(ARG "" "RESULT_VARIABLE;NAME;BUILD_DOCDIR;HEADERS_DIR;SOURCE_DIR;SYMBOL;OPTION_FILE;WIKIHEADERS_PL_PATH" "" ${ARGN})
+  cmake_parse_arguments(ARG "" "RESULT_VARIABLE;NAME;BUILD_DOCDIR;HEADERS_DIR;SOURCE_DIR;SYMBOL;OPTION_FILE;WIKIHEADERS_PL_PATH;REVISION" "" ${ARGN})
+
+  set(wikiheaders_extra_args)
 
   if(NOT ARG_NAME)
     set(ARG_NAME "${PROJECT_NAME}")
@@ -25,6 +27,10 @@ function(SDL_generate_manpages)
     message(FATAL_ERROR "Missing required SYMBOL argument")
   endif()
 
+  if(ARG_REVISION)
+    list(APPEND wikiheaders_extra_args "--rev=${ARG_REVISION}")
+  endif()
+
   if(NOT ARG_BUILD_DOCDIR)
     set(ARG_BUILD_DOCDIR "${CMAKE_CURRENT_BINARY_DIR}/docs")
   endif()
@@ -40,13 +46,13 @@ function(SDL_generate_manpages)
     add_custom_command(
       OUTPUT "${BUILD_WIKIDIR}/${ARG_SYMBOL}.md"
       COMMAND "${CMAKE_COMMAND}" -E make_directory "${BUILD_WIKIDIR}"
-      COMMAND "${PERL_EXECUTABLE}" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_SOURCE_DIR}" "${BUILD_WIKIDIR}" "--options=${ARG_OPTION_FILE}" --copy-to-wiki
+      COMMAND "${PERL_EXECUTABLE}" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_SOURCE_DIR}" "${BUILD_WIKIDIR}" "--options=${ARG_OPTION_FILE}" --copy-to-wiki ${wikiheaders_extra_args}
       DEPENDS ${HEADER_FILES} "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_OPTION_FILE}"
       COMMENT "Generating ${ARG_NAME} wiki markdown files"
     )
     add_custom_command(
       OUTPUT "${BUILD_MANDIR}/man3/${ARG_SYMBOL}.3"
-      COMMAND "${PERL_EXECUTABLE}" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_SOURCE_DIR}" "${BUILD_WIKIDIR}" "--options=${ARG_OPTION_FILE}" "--manpath=${BUILD_MANDIR}" --copy-to-manpages
+      COMMAND "${PERL_EXECUTABLE}" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_SOURCE_DIR}" "${BUILD_WIKIDIR}" "--options=${ARG_OPTION_FILE}" "--manpath=${BUILD_MANDIR}" --copy-to-manpages ${wikiheaders_extra_args}
       DEPENDS  "${BUILD_WIKIDIR}/${ARG_SYMBOL}.md" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_OPTION_FILE}"
       COMMENT "Generating ${ARG_NAME} man pages"
     )