curl.rc: embed manifest for correct Windows version detection

* enable it in `src/Makefile.m32`
* enable it in `winbuild/MakefileBuild.vc` if a custom manifest is
  _not_ enabled via the existing `EMBED_MANIFEST` option
* enable it for all Windows CMake builds (also disable the built-in
  minimal manifest, added by CMake by default.)

For other build systems, add the `-DCURL_EMBED_MANIFEST` option to
the list of RC (Resource Compiler) flags to enable the manifest
included in `src/curl.rc`. This may require to disable whatever
automatic or other means in which way another manifest is added to
`curl.exe`.

Notice that Borland C doesn't support this method due to a
long-pending resource compiler bug. Watcom C may also not handle
it correctly when the `-zm` `wrc` option is used (this option may
be unnecessary though) and regardless of options in certain earlier
revisions of the 2.0 beta version.

Closes https://github.com/curl/curl/pull/1221
Fixes https://github.com/curl/curl/issues/2591

Viktor Szakats 6 months ago
parent
commit
ebd213270a
4 changed files with 61 additions and 5 deletions
  1. 7 1
      CMakeLists.txt
  2. 2 2
      src/Makefile.m32
  3. 49 1
      src/curl.rc
  4. 3 1
      winbuild/MakefileBuild.vc

+ 7 - 1
CMakeLists.txt

@@ -1107,12 +1107,18 @@ include(CMake/OtherTests.cmake)
1107 1107
 
1108 1108
 add_definitions(-DHAVE_CONFIG_H)
1109 1109
 
1110
-# For windows, all compilers used by cmake should support large files
1110
+# For Windows, all compilers used by CMake should support large files
1111 1111
 if(WIN32)
1112 1112
   set(USE_WIN32_LARGE_FILES ON)
1113
+
1114
+  # Use the manifest embedded in the Windows Resource
1115
+  set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
1113 1116
 endif(WIN32)
1114 1117
 
1115 1118
 if(MSVC)
1119
+  # Disable default manifest added by CMake
1120
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
1121
+
1116 1122
   add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
1117 1123
   if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
1118 1124
     string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

+ 2 - 2
src/Makefile.m32

@@ -5,7 +5,7 @@
5 5
 #                            | (__| |_| |  _ <| |___
6 6
 #                             \___|\___/|_| \_\_____|
7 7
 #
8
-# Copyright (C) 1999 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
8
+# Copyright (C) 1999 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
9 9
 #
10 10
 # This software is licensed as described in the file COPYING, which
11 11
 # you should have received as part of this distribution. The terms
@@ -107,7 +107,7 @@ CFLAGS	+= -fno-strict-aliasing
107 107
 LDFLAGS	= $(CURL_LDFLAG_EXTRAS) $(CURL_LDFLAG_EXTRAS_EXE) -s
108 108
 AR	= $(CURL_AR)
109 109
 RC	= $(CROSSPREFIX)windres
110
-RCFLAGS	= --include-dir=$(PROOT)/include -O COFF
110
+RCFLAGS	= --include-dir=$(PROOT)/include -O COFF -DCURL_EMBED_MANIFEST
111 111
 STRIP	= $(CROSSPREFIX)strip -g
112 112
 
113 113
 # We may need these someday

+ 49 - 1
src/curl.rc

@@ -5,7 +5,7 @@
5 5
  *                            | (__| |_| |  _ <| |___
6 6
  *                             \___|\___/|_| \_\_____|
7 7
  *
8
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
8
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
9 9
  *
10 10
  * This software is licensed as described in the file COPYING, which
11 11
  * you should have received as part of this distribution. The terms
@@ -61,3 +61,51 @@ BEGIN
61 61
     VALUE "Translation", 0x409, 1200
62 62
   END
63 63
 END
64
+
65
+/* Manifest */
66
+
67
+#if defined(CURL_EMBED_MANIFEST)
68
+
69
+/* String escaping rules:
70
+     https://msdn.microsoft.com/library/aa381050
71
+   Application Manifest doc, including the list of 'supportedOS Id's:
72
+     https://msdn.microsoft.com/library/aa374191 */
73
+
74
+#ifndef CREATEPROCESS_MANIFEST_RESOURCE_ID
75
+#define CREATEPROCESS_MANIFEST_RESOURCE_ID  1
76
+#endif
77
+#ifndef RT_MANIFEST
78
+#define RT_MANIFEST  24
79
+#endif
80
+
81
+#define _STR(macro)   _STR_(macro)
82
+#define _STR_(macro)  #macro
83
+
84
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST
85
+BEGIN
86
+  "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>"
87
+  "<assembly xmlns=""urn:schemas-microsoft-com:asm.v1"" manifestVersion=""1.0"">"
88
+    "<assemblyIdentity name=""The curl executable"" version="""
89
+      _STR(LIBCURL_VERSION_MAJOR) "."
90
+      _STR(LIBCURL_VERSION_MINOR) "."
91
+      _STR(LIBCURL_VERSION_PATCH) ".0"" type=""win32""/>"
92
+    "<compatibility xmlns=""urn:schemas-microsoft-com:compatibility.v1"">"
93
+      "<application>"
94
+        "<supportedOS Id=""{e2011457-1546-43c5-a5fe-008deee3d3f0}""/>"  /* Vista / Server 2008 */
95
+        "<supportedOS Id=""{35138b9a-5d96-4fbd-8e2d-a2440225f93a}""/>"  /* 7 / Server 2008 R2 */
96
+        "<supportedOS Id=""{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}""/>"  /* 8 / Server 2012 */
97
+        "<supportedOS Id=""{1f676c76-80e1-4239-95bb-83d0f6d0da78}""/>"  /* 8.1 / Server 2012 R2 */
98
+        "<supportedOS Id=""{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}""/>"  /* 10 / Server 2016 */
99
+      "</application>"
100
+    "</compatibility>"
101
+    "<trustInfo xmlns=""urn:schemas-microsoft-com:asm.v3"">"
102
+      "<security>"
103
+        "<requestedPrivileges>"
104
+          "<requestedExecutionLevel level=""asInvoker"" uiAccess=""false""/>"
105
+        "</requestedPrivileges>"
106
+      "</security>"
107
+    "</trustInfo>"
108
+  "</assembly>"
109
+END
110
+
111
+#endif

+ 3 - 1
winbuild/MakefileBuild.vc

@@ -5,7 +5,7 @@
5 5
 #                            | (__| |_| |  _ <| |___
6 6
 #                             \___|\___/|_| \_\_____|
7 7
 #
8
-# Copyright (C) 1999 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
8
+# Copyright (C) 1999 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
9 9
 #
10 10
 # This software is licensed as described in the file COPYING, which
11 11
 # you should have received as part of this distribution. The terms
@@ -352,6 +352,8 @@ GEN_PDB = true
352 352
 
353 353
 !IFDEF EMBED_MANIFEST
354 354
 MANIFESTTOOL = $(MT) -manifest $(DIRDIST)\bin\$(PROGRAM_NAME).manifest -outputresource:$(DIRDIST)\bin\$(PROGRAM_NAME);1
355
+!ELSE
356
+CURL_RC_FLAGS = $(CURL_RC_FLAGS) /dCURL_EMBED_MANIFEST
355 357
 !ENDIF
356 358
 
357 359
 # Runtime library configuration