Skip to content

Commit 0359c2f

Browse files
committed
Merge branch 'windows-resource-removal'
Updates #308.
2 parents 17ec956 + 134acf6 commit 0359c2f

13 files changed

+629
-98
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ macro(_add_exec _name)
210210
add_executable(${_name}
211211
EXCLUDE_FROM_ALL
212212
${ARGN})
213-
target_link_libraries(${_name} libui ${_LIBUI_STATIC_RES})
213+
target_link_libraries(${_name} libui)
214214
_target_link_options_private(${_name}
215215
_COMMON_LDFLAGS)
216216
# make shared-linked executables PIC too

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This README is being written.<br>
55

66
## Announcements
77

8+
* **2 May 2018**
9+
* On Windows, you no longer need to carry around a `libui.res` file with static builds. You do need to link in the appropriate manifest file, such as the one in the `windows/` folder (I still need to figure out exactly what is needed apart from the Common Controls v6 dependency, or at least to create a complete-ish template), or at least include it alongside your executables. This also means you should no longer see random cmake errors when building the static libraries.
10+
811
* **18 April 2018**
912
* Introduced a new `uiTimer()` function for running code on a timer on the main thread. (Thanks to @cody271.)
1013

windows/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,27 @@ list(APPEND _LIBUI_SOURCES
5656
windows/window.cpp
5757
windows/winpublic.cpp
5858
windows/winutil.cpp
59-
windows/resources.rc
6059
)
60+
# resources.rc only contains the libui manifest.
61+
# For a DLL, we have to include this directly, so we do so.
62+
# Windows won't link resources in static libraries, so including this would have no effect.
63+
# In those cases, we just need them to include the manifest with the executable (or link it directly into the output executable themselves); they can also customize the manifest as they see fit (assuming nothing breaks in the process).
64+
# TODO make sure this gets added to both binary-only archives and install rules in this case
65+
if(BUILD_SHARED_LIBS)
66+
list(APPEND _LIBUI_SOURCES
67+
windows/resources.rc
68+
)
69+
endif()
6170
set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE)
6271

6372
list(APPEND _LIBUI_INCLUDEDIRS
6473
windows
6574
)
6675
set(_LIBUI_INCLUDEDIRS _LIBUI_INCLUDEDIRS PARENT_SCOPE)
6776

68-
# Windows won't link resources in static libraries; we need to provide the libui.res file in this case.
6977
set(_LIBUINAME libui PARENT_SCOPE)
70-
if(NOT BUILD_SHARED_LIBS)
71-
set(_LIBUI_STATIC_RES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libui.res PARENT_SCOPE)
72-
endif()
7378
macro(_handle_static)
74-
# TODO this full path feels hacky
75-
add_custom_command(
76-
TARGET libui POST_BUILD
77-
COMMAND
78-
${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:libui,BINARY_DIR>/CMakeFiles/libui.dir/windows/resources.rc.* ${_LIBUI_STATIC_RES}
79-
COMMENT "Copying libui.res")
79+
# do nothing
8080
endmacro()
8181

8282
# TODO prune this list

windows/_rc2bin/build.bat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@rem 2 may 2018
2+
@echo off
3+
4+
cl /nologo /TP /GR /EHsc /MDd /Ob0 /Od /RTC1 /W4 /wd4100 /bigobj /RTC1 /RTCs /RTCu /FS -c main.cpp
5+
if errorlevel 1 goto out
6+
rc -foresources.res resources.rc
7+
if errorlevel 1 goto out
8+
link /nologo main.obj resources.res /out:main.exe /LARGEADDRESSAWARE /NOLOGO /INCREMENTAL:NO /MANIFEST:NO /debug user32.lib kernel32.lib gdi32.lib comctl32.lib uxtheme.lib msimg32.lib comdlg32.lib d2d1.lib dwrite.lib ole32.lib oleaut32.lib oleacc.lib uuid.lib
9+
10+
:out

windows/_rc2bin/libui.manifest

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
3+
<assemblyIdentity
4+
version="1.0.0.0"
5+
processorArchitecture="*"
6+
name="CompanyName.ProductName.YourApplication"
7+
type="win32"
8+
/>
9+
<description>Your application description here.</description>
10+
<dependency>
11+
<dependentAssembly>
12+
<assemblyIdentity
13+
type="win32"
14+
name="Microsoft.Windows.Common-Controls"
15+
version="6.0.0.0"
16+
processorArchitecture="*"
17+
publicKeyToken="6595b64144ccf1df"
18+
language="*"
19+
/>
20+
</dependentAssembly>
21+
</dependency>
22+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
23+
<application>
24+
<!--The ID below indicates application support for Windows Vista -->
25+
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
26+
<!--The ID below indicates application support for Windows 7 -->
27+
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
28+
</application>
29+
</compatibility>
30+
</assembly>
31+

windows/_rc2bin/main.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// 2 may 2018
2+
#include "winapi.hpp"
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include "resources.hpp"
6+
7+
// TODO make sure there are no CRs in the output
8+
9+
void die(const char *f, const char *constname)
10+
{
11+
DWORD le;
12+
13+
le = GetLastError();
14+
fprintf(stderr, "error calling %s for %s: %I32d\n", f, constname, le);
15+
exit(1);
16+
}
17+
18+
void dumpResource(const char *constname, const WCHAR *name, const WCHAR *type)
19+
{
20+
HRSRC hrsrc;
21+
HGLOBAL res;
22+
uint8_t *b, *bp;
23+
DWORD i, n;
24+
DWORD j;
25+
26+
hrsrc = FindResourceW(NULL, name, type);
27+
if (hrsrc == NULL)
28+
die("FindResourceW()", constname);
29+
n = SizeofResource(NULL, hrsrc);
30+
if (n == 0)
31+
die("SizeofResource()", constname);
32+
res = LoadResource(NULL, hrsrc);
33+
if (res == NULL)
34+
die("LoadResource()", constname);
35+
b = (uint8_t *) LockResource(res);
36+
if (b == NULL)
37+
die("LockResource()", constname);
38+
39+
printf("static const uint8_t %s[] = {\n", constname);
40+
bp = b;
41+
j = 0;
42+
for (i = 0; i < n; i++) {
43+
if (j == 0)
44+
printf("\t");
45+
printf("0x%02I32X,", (uint32_t) (*bp));
46+
bp++;
47+
if (j == 7) {
48+
printf("\n");
49+
j = 0;
50+
} else {
51+
printf(" ");
52+
j++;
53+
}
54+
}
55+
if (j != 0)
56+
printf("\n");
57+
printf("};\n");
58+
printf("static_assert(ARRAYSIZE(%s) == %I32d, \"wrong size for resource %s\");\n", constname, n, constname);
59+
printf("\n");
60+
}
61+
62+
int main(void)
63+
{
64+
#define d(c, t) dumpResource(#c, MAKEINTRESOURCEW(c), t)
65+
d(rcTabPageDialog, RT_DIALOG);
66+
d(rcFontDialog, RT_DIALOG);
67+
d(rcColorDialog, RT_DIALOG);
68+
return 0;
69+
}

windows/_rc2bin/resources.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// 30 may 2015
2+
3+
#define rcTabPageDialog 29000
4+
#define rcFontDialog 29001
5+
#define rcColorDialog 29002
6+
7+
// TODO normalize these
8+
9+
#define rcFontFamilyCombobox 1000
10+
#define rcFontStyleCombobox 1001
11+
#define rcFontSizeCombobox 1002
12+
#define rcFontSamplePlacement 1003
13+
14+
#define rcColorSVChooser 1100
15+
#define rcColorHSlider 1101
16+
#define rcPreview 1102
17+
#define rcOpacitySlider 1103
18+
#define rcH 1104
19+
#define rcS 1105
20+
#define rcV 1106
21+
#define rcRDouble 1107
22+
#define rcRInt 1108
23+
#define rcGDouble 1109
24+
#define rcGInt 1110
25+
#define rcBDouble 1111
26+
#define rcBInt 1112
27+
#define rcADouble 1113
28+
#define rcAInt 1114
29+
#define rcHex 1115
30+
#define rcHLabel 1116
31+
#define rcSLabel 1117
32+
#define rcVLabel 1118
33+
#define rcRLabel 1119
34+
#define rcGLabel 1120
35+
#define rcBLabel 1121
36+
#define rcALabel 1122
37+
#define rcHexLabel 1123

windows/_rc2bin/resources.rc

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// 30 may 2015
2+
#include "winapi.hpp"
3+
#include "resources.hpp"
4+
5+
// this is a UTF-8 file
6+
#pragma code_page(65001)
7+
8+
// this is the Common Controls 6 manifest
9+
// we only define it in a shared build; static builds have to include the appropriate parts of the manifest in the output executable
10+
// LONGTERM set up the string values here
11+
#ifndef _UI_STATIC
12+
ISOLATIONAWARE_MANIFEST_RESOURCE_ID RT_MANIFEST "libui.manifest"
13+
#endif
14+
15+
// this is the dialog template used by tab pages; see windows/tabpage.c for details
16+
rcTabPageDialog DIALOGEX 0, 0, 100, 100
17+
STYLE DS_CONTROL | WS_CHILD | WS_VISIBLE
18+
EXSTYLE WS_EX_CONTROLPARENT
19+
BEGIN
20+
// nothing
21+
END
22+
23+
// this is for our custom DirectWrite-based font dialog (see fontdialog.cpp)
24+
// this is based on the "New Font Dialog with Syslink" in Microsoft's font.dlg
25+
// LONGTERM look at localization
26+
// LONGTERM make it look tighter and nicer like the real one, including the actual heights of the font family and style comboboxes
27+
rcFontDialog DIALOGEX 13, 54, 243, 200
28+
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_3DLOOK
29+
CAPTION "Font"
30+
FONT 9, "Segoe UI"
31+
BEGIN
32+
LTEXT "&Font:", -1, 7, 7, 98, 9
33+
COMBOBOX rcFontFamilyCombobox, 7, 16, 98, 76,
34+
CBS_SIMPLE | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL |
35+
CBS_SORT | WS_VSCROLL | WS_TABSTOP | CBS_HASSTRINGS
36+
37+
LTEXT "Font st&yle:", -1, 114, 7, 74, 9
38+
COMBOBOX rcFontStyleCombobox, 114, 16, 74, 76,
39+
CBS_SIMPLE | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL |
40+
WS_VSCROLL | WS_TABSTOP | CBS_HASSTRINGS
41+
42+
LTEXT "&Size:", -1, 198, 7, 36, 9
43+
COMBOBOX rcFontSizeCombobox, 198, 16, 36, 76,
44+
CBS_SIMPLE | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL |
45+
CBS_SORT | WS_VSCROLL | WS_TABSTOP | CBS_HASSTRINGS
46+
47+
GROUPBOX "Sample", -1, 7, 97, 227, 70, WS_GROUP
48+
CTEXT "AaBbYyZz", rcFontSamplePlacement, 9, 106, 224, 60, SS_NOPREFIX | NOT WS_VISIBLE
49+
50+
DEFPUSHBUTTON "OK", IDOK, 141, 181, 45, 14, WS_GROUP
51+
PUSHBUTTON "Cancel", IDCANCEL, 190, 181, 45, 14, WS_GROUP
52+
END
53+
54+
rcColorDialog DIALOGEX 13, 54, 344, 209
55+
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_3DLOOK
56+
CAPTION "Color"
57+
FONT 9, "Segoe UI"
58+
BEGIN
59+
// this size should be big enough to get at least 256x256 on font sizes >= 8 pt
60+
CTEXT "AaBbYyZz", rcColorSVChooser, 7, 7, 195, 195, SS_NOPREFIX | SS_BLACKRECT
61+
62+
// width is the suggested slider height since this is vertical
63+
CTEXT "AaBbYyZz", rcColorHSlider, 206, 7, 15, 195, SS_NOPREFIX | SS_BLACKRECT
64+
65+
LTEXT "Preview:", -1, 230, 7, 107, 9, SS_NOPREFIX
66+
CTEXT "AaBbYyZz", rcPreview, 230, 16, 107, 20, SS_NOPREFIX | SS_BLACKRECT
67+
68+
LTEXT "Opacity:", -1, 230, 45, 107, 9, SS_NOPREFIX
69+
CTEXT "AaBbYyZz", rcOpacitySlider, 230, 54, 107, 15, SS_NOPREFIX | SS_BLACKRECT
70+
71+
LTEXT "&H:", rcHLabel, 230, 81, 8, 8
72+
EDITTEXT rcH, 238, 78, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE
73+
LTEXT "&S:", rcSLabel, 230, 95, 8, 8
74+
EDITTEXT rcS, 238, 92, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE
75+
LTEXT "&V:", rcVLabel, 230, 109, 8, 8
76+
EDITTEXT rcV, 238, 106, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE
77+
78+
LTEXT "&R:", rcRLabel, 277, 81, 8, 8
79+
EDITTEXT rcRDouble, 285, 78, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE
80+
EDITTEXT rcRInt, 315, 78, 20, 14, ES_LEFT | ES_AUTOHSCROLL | ES_NUMBER | WS_TABSTOP, WS_EX_CLIENTEDGE
81+
LTEXT "&G:", rcGLabel, 277, 95, 8, 8
82+
EDITTEXT rcGDouble, 285, 92, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE
83+
EDITTEXT rcGInt, 315, 92, 20, 14, ES_LEFT | ES_AUTOHSCROLL | ES_NUMBER | WS_TABSTOP, WS_EX_CLIENTEDGE
84+
LTEXT "&B:", rcBLabel, 277, 109, 8, 8
85+
EDITTEXT rcBDouble, 285, 106, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE
86+
EDITTEXT rcBInt, 315, 106, 20, 14, ES_LEFT | ES_AUTOHSCROLL | ES_NUMBER | WS_TABSTOP, WS_EX_CLIENTEDGE
87+
LTEXT "&A:", rcALabel, 277, 123, 8, 8
88+
EDITTEXT rcADouble, 285, 120, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE
89+
EDITTEXT rcAInt, 315, 120, 20, 14, ES_LEFT | ES_AUTOHSCROLL | ES_NUMBER | WS_TABSTOP, WS_EX_CLIENTEDGE
90+
91+
LTEXT "He&x:", rcHexLabel, 269, 146, 16, 8
92+
EDITTEXT rcHex, 285, 143, 50, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE
93+
94+
DEFPUSHBUTTON "OK", IDOK, 243, 188, 45, 14, WS_GROUP
95+
PUSHBUTTON "Cancel", IDCANCEL, 292, 188, 45, 14, WS_GROUP
96+
END

windows/_rc2bin/winapi.hpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// 31 may 2015
2+
#define UNICODE
3+
#define _UNICODE
4+
#define STRICT
5+
#define STRICT_TYPED_ITEMIDS
6+
7+
// see https://github.com/golang/go/issues/9916#issuecomment-74812211
8+
// TODO get rid of this
9+
#define INITGUID
10+
11+
// for the manifest
12+
#ifndef _UI_STATIC
13+
#define ISOLATION_AWARE_ENABLED 1
14+
#endif
15+
16+
// get Windows version right; right now Windows Vista
17+
// unless otherwise stated, all values from Microsoft's sdkddkver.h
18+
// TODO is all of this necessary? how is NTDDI_VERSION used?
19+
// TODO plaform update sp2
20+
#define WINVER 0x0600 /* from Microsoft's winnls.h */
21+
#define _WIN32_WINNT 0x0600
22+
#define _WIN32_WINDOWS 0x0600 /* from Microsoft's pdh.h */
23+
#define _WIN32_IE 0x0700
24+
#define NTDDI_VERSION 0x06000000
25+
26+
// The MinGW-w64 header has an unverified IDWriteTypography definition.
27+
// TODO I can confirm this myself, but I don't know how long it will take for them to note my adjustments... Either way, I have to confirm this myself.
28+
// TODO change the check from _MSC_VER to a MinGW-w64-specific check
29+
// TODO keep track of what else is guarded by this
30+
#ifndef _MSC_VER
31+
#define __MINGW_USE_BROKEN_INTERFACE
32+
#endif
33+
34+
#include <windows.h>
35+
36+
// Microsoft's resource compiler will segfault if we feed it headers it was not designed to handle
37+
#ifndef RC_INVOKED
38+
#include <commctrl.h>
39+
#include <uxtheme.h>
40+
#include <windowsx.h>
41+
#include <shobjidl.h>
42+
#include <d2d1.h>
43+
#include <d2d1helper.h>
44+
#include <dwrite.h>
45+
46+
#include <stdint.h>
47+
#include <string.h>
48+
#include <wchar.h>
49+
#include <stdarg.h>
50+
#include <stdio.h>
51+
#include <math.h>
52+
#include <float.h>
53+
#include <inttypes.h>
54+
55+
#include <vector>
56+
#include <map>
57+
#include <unordered_map>
58+
#include <sstream>
59+
#include <functional>
60+
#endif

0 commit comments

Comments
 (0)