Skip to content

Commit

Permalink
Enable GDAL for Microsoft Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
ojwb committed Dec 23, 2024
1 parent 0748a58 commit 1a79173
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 6 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,8 @@ jobs:
wxwidgets3.2-msw:p
gdb:p
ntldd:p
# Build with GDAL broke somewhere between 1.4.9 and 1.4.10 releases.
# Rebuilding 1.4.9 now has the problem. Unresolved as of 2024-10-19.
# gdal:p
gdal:p
pkgconf:p
- name: Install CCache
uses: hendrikmuhs/ccache-action@v1
with:
Expand Down
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ mingw_iss : survex.iss
cp -a $(PROJ_PREFIX)/share/proj iss_tmp/proj
: # Include required non-system DLLs.
[ -z "$(NTLDD)" ] || cp -a $$($(NTLDD) --recursive src/aven.exe 2>/dev/null|sed -n 's!\\!/!g;s!.*msys64\(/ucrt64/bin/[^ ]*\).*!\1!p') iss_tmp
: # libpodofo triggers openssl to dynamically load its legacy.dll at startup.
: # Looks like this may get fixed in libpodofo 1.0
cp /ucrt64/lib/ossl-modules/legacy.dll iss_tmp
$(STRIP) iss_tmp/*.dll
$(RUN_EXE) "c:/Program Files (x86)/Inno Setup 6/ISCC.exe" iss_tmp/survex.iss
mv iss_tmp/Output/*.exe .
Expand Down
7 changes: 7 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ aven_LDADD += avenrc.o

avenrc.o: $(srcdir)/aven.rc ../lib/icons/aven.ico
cd $(srcdir) && `$(WX_CONFIG) --rescomp` --include-dir '$(abs_top_builddir)/lib/icons' -o '$(abs_builddir)/avenrc.o' aven.rc

bin_PROGRAMS += wrapaven wrapsurvexport

wrapaven_SOURCES = wrapaven.c
wrapaven_LDFLAGS = -mwindows -municode

wrapsurvexport_SOURCES = wrapsurvexport.c
endif

AM_CFLAGS += $(PROJ_CFLAGS)
Expand Down
70 changes: 70 additions & 0 deletions src/wrapaven.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* wrapaven.c
* Set OPENSSL_MODULES to .exe's directory and run real .exe
*
* Copyright (C) 2002,2010,2014,2024 Olly Betts
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <stdlib.h>
#include <string.h>
#include <windows.h>

int APIENTRY
wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpCmdLine, int nCmdShow)
{
DWORD len = 256;
wchar_t *buf = NULL;
(void)hInst; /* suppress compiler warning */
(void)hPrevInst; /* suppress compiler warning */
while (1) {
DWORD got;
buf = realloc(buf, len * sizeof(wchar_t));
if (!buf) return 1;
got = GetModuleFileNameW(NULL, buf, len);
if (got < len) {
/* Strange Microsoft nastiness - skip prefix "\\?\" if present. */
if (wcsncmp(buf, L"\\\\?\\", 4) == 0) {
buf += 4;
got -= 4;
}
wchar_t *p = wcsrchr(buf, L'\\');
wchar_t *e_val = buf;
size_t e_len;
if (p) {
e_len = p - buf;
} else {
e_val = L".";
e_len = 1;
}
wchar_t *e = malloc((e_len + strlen("OPENSSL_MODULES=") + 1) * sizeof(wchar_t));
if (!e) return 1;
wcscpy(e, L"OPENSSL_MODULES=");
memcpy(e + strlen("OPENSSL_MODULES="), e_val, e_len * sizeof(wchar_t));
e[strlen("OPENSSL_MODULES=") + e_len] = L'\0';
_wputenv(e);
buf[got - 5] = L'_';
break;
}
len += len;
}
/* ShellExecute returns an HINSTANCE for some strange reason - the docs say
* the only valid operation is to convert it to "INT_PTR" (which seems to
* actually be an integer type. Marvellous. */
if ((INT_PTR)ShellExecuteW(NULL, NULL, buf, lpCmdLine, NULL, nCmdShow) <= 32) {
return 1;
}
return 0;
}
77 changes: 77 additions & 0 deletions src/wrapsurvexport.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* wrapsurvexport.c
* Set OPENSSL_MODULES to .exe's directory and run real .exe
*
* Copyright (C) 2002,2010,2014,2024 Olly Betts
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <process.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main(int argc, char **argv)
{
const char *p = strrchr(argv[0], '\\');
const char *e_val = argv[0];
size_t e_len;
size_t a_len;
(void)argc;
if (p) {
e_len = p - argv[0];
a_len = e_len + 1;
} else {
e_val = ".";
e_len = 1;
a_len = 0;
}
char *e = malloc(e_len + strlen("OPENSSL_MODULES=") + 1);
if (!e) return 1;
strcpy(e, "OPENSSL_MODULES=");
memcpy(e + strlen("OPENSSL_MODULES="), e_val, e_len);
e[strlen("OPENSSL_MODULES=") + e_len] = '\0';
putenv(e);
char *a = malloc(a_len + strlen("survexpor_.exe") + 1);
if (!a) return 1;
memcpy(a, argv[0], a_len);
strcpy(a + a_len, "survexpor_.exe");
const char *real_argv0 = argv[0];
// Behind the scenes it appears Microsoft's _execv() actually takes the
// argv passed and crudely glues it together into a command line string
// with spaces in between but *WITHOUT ANY ESCAPING*, and then it gets
// split back up into arguments at spaces, so an argument containing a
// space gets split into two arguments. Coupled with the default
// installation directory path containing a space (C:\Program Files) this
// doesn't work out well. Words fail me.
//
// Apparently putting quotes around the argument is necessary.
for (int i = 0; i < argc; ++i) {
const char *arg = argv[i];
if (arg[strcspn(arg, " \t\n\r\v")]) {
// Argument contains whitespace.
char *newarg = malloc(strlen(arg) + 3);
if (!newarg) return 1;
newarg[0] = '"';
strcpy(newarg + 1, arg);
strcat(newarg + 1, "\"");
argv[i] = newarg;
}
}
_execv(a, (const char * const*)argv);
printf("%s: %s\n", real_argv0, strerror(errno));
return 1;
}
12 changes: 9 additions & 3 deletions survex.iss.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ Name: "{app}\proj"
Type: files; Name: "{app}\cad3d.exe"

[Files]
Source: "*.exe"; DestDir: "{app}"
Source: "*.exe"; Excludes: "aven.exe,survexport.exe,wrapaven.exe,wrapsurvexport.exe"; DestDir: "{app}"
; Install aven.exe as ave_.exe and survexport.exe as survexpor_.exe.
Source: "aven.exe"; DestDir: "{app}"; DestName: "ave_.exe"
Source: "survexport.exe"; DestDir: "{app}"; DestName: "survexpor_.exe"
; Install wrapper versions under real name.
Source: "wrapaven.exe"; DestDir: "{app}"; DestName: "aven.exe"
Source: "wrapsurvexport.exe"; DestDir: "{app}"; DestName: "survexport.exe"
; Also install wrapsurvexport.exe as 3dtopos.exe so existing Tunnel releases work.
Source: "wrapsurvexport.exe"; DestDir: "{app}"; DestName: "3dtopos.exe"
Source: "*.dll"; DestDir: "{app}"; Flags: skipifsourcedoesntexist
Source: "*.svx"; DestDir: "{app}"
Source: "*.ico"; DestDir: "{app}"
Expand All @@ -84,8 +92,6 @@ Source: "proj\*"; DestDir: "{app}\proj"
Source: "manual\*.*"; DestDir: "{app}\manual"
; Generate iss file for including the wxstd.mo files
#include "i18nfiles.iss"
; Also install survexport.exe as 3dtopos.exe so existing Tunnel releases work.
Source: "survexport.exe"; DestDir: "{app}"; DestName: "3dtopos.exe"

; FIXME This should be translated (think there's a standard custommessage)
;[Run]
Expand Down

0 comments on commit 1a79173

Please sign in to comment.