Addresses https://trac.macports.org/ticket/62855

--- Source/cmSystemTools.cxx.orig	2023-03-08 20:04:09.000000000 +0100
+++ Source/cmSystemTools.cxx	2023-07-25 11:24:23.000000000 +0200
@@ -2570,6 +2570,8 @@
     exe_dir = cmSystemTools::GetFilenamePath(exe_dir);
     if (cmSystemTools::FileExists(exe_dir + CMAKE_BIN_DIR "/cmake")) {
       exe_dir += CMAKE_BIN_DIR;
+    } else if (cmSystemTools::FileExists("__PREFIX__" CMAKE_BIN_DIR "/cmake")) {
+        exe_dir = cmSystemTools::GetFilenamePath("__PREFIX__" CMAKE_BIN_DIR "/cmake");
     } else {
       exe_dir = cmSystemTools::GetFilenamePath(exe_dir);
       exe_dir = cmSystemTools::GetFilenamePath(exe_dir);
