1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
# Lagrange - A Beautiful Gemini Client
# Copyright: 2020 Jaakko Keränen <jaakko.keranen@iki.fi>
#
# Notes:
# - Required dependencies: SDL 2, OpenSSL 1.1.1, libpcre,
# GNU libunistring, zlib.
# - the_Foundation is built as a static library from 'lib/the_Foundation',
# if it exists in that location. The Git repository has it as a submodule.
# - Windows builds require MSYS2. In theory, Clang could be set up on
# Windows for compiling everything, but the_Foundation still lacks
# native Win32 implementations for the Socket and Process classes.
# - Windows builds should use the SDL 2 library precompiled for native
# Windows (MSVC variant) instead the version from MSYS2 (get it from
# https://libsdl.org/). To make configuration easier, consider writing
# for your personal use a pkg-config sdl2.pc file that uses the Windows
# version of the library.
# - `cat` is relied upon for merging all the resource files together.
cmake_minimum_required (VERSION 3.9)
project (Lagrange
VERSION 0.5.0
DESCRIPTION "Beautiful Gemini Client"
LANGUAGES C
)
set (COPYRIGHT_YEAR 2020)
# Build configuration.
option (ENABLE_X11_SWRENDER "Use software rendering under X11" OFF)
option (ENABLE_KERNING "Enable kerning in font renderer (slower)" ON)
option (ENABLE_RESOURCE_EMBED "Embed resources inside the executable" OFF)
option (ENABLE_WINDOWPOS_FIX "Set position after showing window (workaround for SDL bug)" OFF)
include (BuildType.cmake)
include (Embed.cmake)
if (NOT EXISTS ${CMAKE_SOURCE_DIR}/lib/the_Foundation/CMakeLists.txt)
set (INSTALL_THE_FOUNDATION YES)
find_package (the_Foundation REQUIRED)
else ()
set (INSTALL_THE_FOUNDATION NO)
set (TFDN_STATIC_LIBRARY ON CACHE BOOL "")
set (TFDN_ENABLE_INSTALL OFF CACHE BOOL "")
set (TFDN_ENABLE_TESTS OFF CACHE BOOL "")
set (TFDN_ENABLE_WEBREQUEST OFF CACHE BOOL "")
add_subdirectory (lib/the_Foundation)
add_library (the_Foundation::the_Foundation ALIAS the_Foundation)
endif ()
find_package (PkgConfig REQUIRED)
pkg_check_modules (SDL2 REQUIRED sdl2)
# Embedded resources are written to a generated source file.
message (STATUS "Preparing embedded resources...")
# Fonts are too large to comfortably embed as a C source.
set (EMBED_RESOURCES
res/about/help.gmi
res/about/lagrange.gmi
res/about/license.gmi
res/about/version.gmi
res/fonts/EBGaramond-Regular.ttf
res/fonts/EBGaramond-Medium.ttf
res/fonts/EBGaramond-Italic.ttf
res/fonts/EBGaramond-Bold.ttf
res/fonts/FiraMono-Regular.ttf
res/fonts/FiraSans-Bold.ttf
res/fonts/FiraSans-Italic.ttf
res/fonts/FiraSans-Light.ttf
res/fonts/FiraSans-Regular.ttf
res/fonts/KosugiMaru-Regular.ttf
res/fonts/Literata-Regular-opsz=14.ttf
res/fonts/Literata-Bold-opsz=36.ttf
res/fonts/Literata-ExtraLight-opsz=18.ttf
res/fonts/Literata-LightItalic-opsz=14.ttf
res/fonts/NotoEmoji-Regular.ttf
res/fonts/Nunito-ExtraBold.ttf
res/fonts/Nunito-ExtraLight.ttf
res/fonts/Nunito-LightItalic.ttf
res/fonts/Nunito-Regular.ttf
res/fonts/SourceSansPro-Regular.ttf
res/fonts/Symbola.ttf
)
if (UNIX AND NOT APPLE)
list (APPEND EMBED_RESOURCES res/lagrange-64.png)
endif ()
embed_make (${EMBED_RESOURCES})
set (EMB_BIN ${CMAKE_CURRENT_BINARY_DIR}/resources.binary)
set_source_files_properties (${EMB_BIN} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
# Source files.
set (SOURCES
src/main.c
src/app.c
src/app.h
src/bookmarks.c
src/bookmarks.h
src/gmcerts.c
src/gmcerts.h
src/gmdocument.c
src/gmdocument.h
src/gmrequest.c
src/gmrequest.h
src/gmutil.c
src/gmutil.h
src/history.c
src/history.h
src/lookup.c
src/lookup.h
src/media.c
src/media.h
src/prefs.c
src/prefs.h
src/stb_image.h
src/stb_truetype.h
src/visited.c
src/visited.h
# Audio playback:
src/audio/buf.c
src/audio/buf.h
src/audio/player.c
src/audio/player.h
src/audio/stb_vorbis.c
# User interface:
src/ui/color.c
src/ui/color.h
src/ui/command.c
src/ui/command.h
src/ui/documentwidget.c
src/ui/documentwidget.h
src/ui/listwidget.c
src/ui/listwidget.h
src/ui/lookupwidget.c
src/ui/lookupwidget.h
src/ui/keys.h
src/ui/metrics.c
src/ui/metrics.h
src/ui/paint.c
src/ui/paint.h
src/ui/scrollwidget.c
src/ui/scrollwidget.h
src/ui/sidebarwidget.c
src/ui/sidebarwidget.h
src/ui/text.c
src/ui/text.h
src/ui/util.c
src/ui/util.h
src/ui/visbuf.c
src/ui/visbuf.h
src/ui/window.c
src/ui/window.h
# Widgets:
src/ui/widget.c
src/ui/widget.h
src/ui/inputwidget.c
src/ui/inputwidget.h
src/ui/labelwidget.c
src/ui/labelwidget.h
# Resources:
res/about/help.gmi
res/about/lagrange.gmi
res/about/version.gmi
${CMAKE_CURRENT_BINARY_DIR}/resources.binary
${CMAKE_CURRENT_BINARY_DIR}/embedded.c
${CMAKE_CURRENT_BINARY_DIR}/embedded.h
)
if (IOS)
elseif (APPLE)
list (APPEND SOURCES src/macos.m src/macos.h)
list (APPEND RESOURCES "res/Lagrange.icns")
endif ()
if (MSYS)
set (WINRC_FILE_VERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0)
set (WINRC_PRODUCT_VERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},0,0)
configure_file (res/lagrange.rc.in ${CMAKE_CURRENT_BINARY_DIR}/lagrange.rc NEWLINE_STYLE WIN32)
list (APPEND SOURCES src/win32.c src/win32.h ${CMAKE_CURRENT_BINARY_DIR}/lagrange.rc)
endif ()
set_source_files_properties (${RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
# Target.
add_executable (app ${SOURCES} ${RESOURCES})
set_target_properties (app PROPERTIES OUTPUT_NAME lagrange)
target_include_directories (app PUBLIC
src
${CMAKE_CURRENT_BINARY_DIR}
${SDL2_INCLUDE_DIRS}
)
target_compile_options (app PUBLIC
-Werror=implicit-function-declaration
-Werror=incompatible-pointer-types
${SDL2_CFLAGS}
-DSTB_VORBIS_NO_STDIO=1
-DSTB_VORBIS_NO_INTEGER_CONVERSION=1
)
target_compile_definitions (app PUBLIC LAGRANGE_APP_VERSION="${PROJECT_VERSION}")
if (ENABLE_X11_SWRENDER)
target_compile_definitions (app PUBLIC LAGRANGE_ENABLE_X11_SWRENDER=1)
endif ()
if (ENABLE_KERNING)
target_compile_definitions (app PUBLIC LAGRANGE_ENABLE_KERNING=1)
endif ()
if (ENABLE_WINDOWPOS_FIX)
target_compile_definitions (app PUBLIC LAGRANGE_ENABLE_WINDOWPOS_FIX=1)
endif ()
target_link_libraries (app PUBLIC the_Foundation::the_Foundation)
target_link_libraries (app PUBLIC ${SDL2_LDFLAGS})
if (APPLE)
if (IOS)
target_link_libraries (app PUBLIC "-framework UIKit")
else ()
target_link_libraries (app PUBLIC "-framework AppKit")
endif ()
if (CMAKE_OSX_DEPLOYMENT_TARGET)
target_compile_options (app PUBLIC -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET})
target_link_options (app PUBLIC -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET})
endif ()
set_target_properties (app PROPERTIES
OUTPUT_NAME "Lagrange"
BUILD_RPATH ${SDL2_LIBRARY_DIRS}
MACOSX_BUNDLE YES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/res/MacOSXBundleInfo.plist.in"
MACOSX_BUNDLE_BUNDLE_NAME "Lagrange"
MACOSX_BUNDLE_INFO_STRING "${PROJECT_VERSION}"
MACOSX_BUNDLE_ICON_FILE "Lagrange.icns"
MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}"
MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_VERSION}"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
MACOSX_BUNDLE_GUI_IDENTIFIER "fi.skyjake.Lagrange"
MACOSX_BUNDLE_COPYRIGHT "© ${COPYRIGHT_YEAR} Jaakko Keränen"
)
endif ()
if (MSYS)
target_link_libraries (app PUBLIC d2d1 uuid) # querying DPI
endif ()
if (UNIX)
target_link_libraries (app PUBLIC m)
endif ()
# Deployment.
if (MSYS)
install (TARGETS app DESTINATION .)
if (NOT ENABLE_RESOURCE_EMBED)
install (FILES ${EMB_BIN} DESTINATION .)
endif ()
install (PROGRAMS
${SDL2_LIBDIR}/SDL2.dll
res/urlopen.bat
DESTINATION .
)
if (INSTALL_THE_FOUNDATION)
install (PROGRAMS $<TARGET_FILE:the_Foundation::the_Foundation> DESTINATION .)
endif ()
elseif (UNIX AND NOT APPLE)
set_target_properties (app PROPERTIES
INSTALL_RPATH_USE_LINK_PATH YES
)
set (desktop ${CMAKE_CURRENT_BINARY_DIR}/fi.skyjake.lagrange.desktop)
file (WRITE ${desktop} "[Desktop Entry]
Name=Lagrange
Comment=${PROJECT_DESCRIPTION}
Categories=Network
Exec=${CMAKE_INSTALL_PREFIX}/bin/lagrange %U
Terminal=false
Type=Application
Icon=fi.skyjake.lagrange
MimeType=x-scheme-handler/gemini;
")
install (TARGETS app DESTINATION bin)
install (FILES ${desktop} DESTINATION share/applications)
install (FILES res/lagrange-256.png
DESTINATION share/icons/hicolor/256x256/apps
RENAME fi.skyjake.lagrange.png
)
if (NOT ENABLE_RESOURCE_EMBED)
install (FILES ${EMB_BIN} DESTINATION share/lagrange)
endif ()
endif ()
|