Skip to content

Commit f1c2fa6

Browse files
committed
feat: add newer discord-social-sdk as dependency instead of the older game-sdk
1 parent 12240a1 commit f1c2fa6

File tree

4 files changed

+158
-29
lines changed

4 files changed

+158
-29
lines changed

src/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if build_application
1313
subdir('ui')
1414
subdir('lobby')
1515

16-
if have_discord_sdk
16+
if have_discord_social_sdk
1717
subdir('discord')
1818
endif
1919

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[wrap-file]
2+
directory = discord_social_sdk
3+
source_url = https://oopetris.totto.lt/static/assets/discord/DiscordSocialSdk-1.1.8318.zip
4+
source_filename = DiscordSocialSdk-1.1.8318.zip
5+
source_hash = e78ac5c6462d74917b74d2511ed88876f59dbe00d31186590a98ea7953099e31
6+
patch_directory = discord_social_sdk
7+
8+
[provide]
9+
discord-social-sdk = discord_social_sdk_dep
10+
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
project(
2+
'discord-social-sdk',
3+
'cpp',
4+
'c',
5+
version: '1.1.8318',
6+
meson_version: '>=1.4.0',
7+
default_options: {
8+
'cpp_std': ['c++17'],
9+
},
10+
)
11+
12+
inc_dirs = include_directories('include')
13+
14+
header_files = files('include' / 'cdiscord.h', 'include' / 'discordpp.h')
15+
16+
install_headers(header_files, subdir: 'discord')
17+
18+
lib_base_dir = ''
19+
20+
if host_machine.system() == 'darwin'
21+
if host_machine.cpu_family() in ['aarch64', 'x86_64']
22+
lib_base_dir = 'lib'
23+
else
24+
error(
25+
'unsupported architecture for macos: ' + host_machine.cpu_family(),
26+
)
27+
endif
28+
29+
elif host_machine.system() == 'linux'
30+
if host_machine.cpu_family() == 'x86_64'
31+
lib_base_dir = 'lib'
32+
33+
cat = find_program('cat')
34+
35+
os_release_info = run_command(
36+
cat,
37+
'/etc/os-release',
38+
check: true,
39+
).stdout().strip().split('\n')
40+
41+
linux_distro = ''
42+
43+
foreach line : os_release_info
44+
line_detail = line.split('=')
45+
46+
if line_detail[0] == 'ID'
47+
linux_distro = line_detail[1]
48+
endif
49+
50+
endforeach
51+
52+
if linux_distro == ''
53+
warning('Couldn\'t detect the linux distro')
54+
endif
55+
56+
if linux_distro == 'alpine'
57+
error('unsupported libc for linux: musl')
58+
endif
59+
60+
else
61+
error(
62+
'unsupported architecture for linux: ' + host_machine.cpu_family(),
63+
)
64+
endif
65+
elif host_machine.system() == 'windows'
66+
if host_machine.cpu_family() == 'x86_64'
67+
lib_base_dir = get_option('default_library') == 'static' ? 'bin' : 'lib'
68+
else
69+
error(
70+
'unsupported architecture for windows: ' + host_machine.cpu_family(),
71+
)
72+
endif
73+
else
74+
error('unsupported system: ' + host_machine.system())
75+
endif
76+
77+
lib_dir = (
78+
lib_base_dir / (get_option('buildtype') == 'release' ? 'release' : 'debug')
79+
)
80+
81+
c = meson.get_compiler('c')
82+
83+
discord_partner_sdk = c.find_library(
84+
'discord_partner_sdk',
85+
dirs: [meson.project_source_root() / lib_dir],
86+
required: true,
87+
)
88+
89+
discord_lib = library(
90+
'discord_partner_sdk',
91+
header_files,
92+
include_directories: inc_dirs,
93+
dependencies: discord_partner_sdk,
94+
install: true,
95+
)
96+
97+
discord_social_sdk_dep = declare_dependency(
98+
include_directories: inc_dirs,
99+
version: meson.project_version(),
100+
link_with: discord_lib,
101+
)
102+
103+
meson.override_dependency('discord-social-sdk', discord_social_sdk_dep)

tools/dependencies/meson.build

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ if meson.is_cross_build()
6767
foreach native_dependency_tuple : map_native_dependencies
6868
native_dep_lib_name = native_dependency_tuple[0]
6969

70-
native_dep_name = native_dependency_tuple.length() == 2 ? native_dependency_tuple[1] : native_dep_lib_name
70+
native_dep_name = (
71+
native_dependency_tuple.length() == 2 ? native_dependency_tuple[1] : native_dep_lib_name
72+
)
7173

7274
native_dep = cpp.find_library(native_dep_lib_name, required: true)
7375

@@ -102,13 +104,12 @@ if meson.is_cross_build()
102104

103105
native_dep_with_version = declare_dependency(
104106
dependencies: native_dep,
105-
version: major_version
106-
+ '.'
107-
+ minor_version
108-
+ '.'
109-
+ patch_version,
107+
version: major_version + '.' + minor_version + '.' + patch_version,
108+
)
109+
meson.override_dependency(
110+
native_dep_name,
111+
native_dep_with_version,
110112
)
111-
meson.override_dependency(native_dep_name, native_dep_with_version)
112113
else
113114
meson.override_dependency(native_dep_name, native_dep)
114115

@@ -146,7 +147,8 @@ fmt_use_header_only = false
146147

147148
if (
148149
meson.is_cross_build()
149-
and (host_machine.system() == 'switch' or host_machine.system() == '3ds')
150+
and (host_machine.system() == 'switch'
151+
or host_machine.system() == '3ds')
150152
)
151153
fmt_use_header_only = true
152154
endif
@@ -350,7 +352,10 @@ if build_application
350352

351353
if (meson.is_cross_build() and host_machine.system() == '3ds')
352354
graphics_lib += {
353-
'compile_args': [graphics_lib.get('compile_args'), '-DSPDLOG_NO_TLS'],
355+
'compile_args': [
356+
graphics_lib.get('compile_args'),
357+
'-DSPDLOG_NO_TLS',
358+
],
354359
}
355360
endif
356361

@@ -407,8 +412,16 @@ if build_application
407412

408413
endif
409414

410-
if host_machine.system() == 'linux' or (meson.is_cross_build() and host_machine.system() == 'android')
411-
keyutils_dep = dependency('keyutils', required: true, allow_fallback: true)
415+
if (
416+
host_machine.system() == 'linux'
417+
or (meson.is_cross_build()
418+
and host_machine.system() == 'android')
419+
)
420+
keyutils_dep = dependency(
421+
'keyutils',
422+
required: true,
423+
allow_fallback: true,
424+
)
412425
graphics_lib += {'deps': [graphics_lib.get('deps'), keyutils_dep]}
413426
elif host_machine.system() == 'windows'
414427
c = meson.get_compiler('c')
@@ -425,8 +438,8 @@ if build_application
425438
if build_installer
426439
if get_option('buildtype') != 'release'
427440
error(
428-
'buildtype needs to be \'release\', when building the installer, but was: '
429-
+ get_option('buildtype'),
441+
'buildtype needs to be \'release\', when building the installer, but was: ' +
442+
get_option('buildtype'),
430443
)
431444
endif
432445

@@ -435,16 +448,15 @@ if build_application
435448
is_flatpak_build = true
436449
else
437450
error(
438-
'only support flatpak builds, when building the installer for linux',
451+
'only support flatpak builds, when building the installer for linux',
439452
)
440453
endif
441454
elif host_machine.system() == 'windows'
442455
message('Adding a windows installer target: \'windows_installer\'')
443456
else
444457
# TODO: create a proper installer for macOS : https://mesonbuild.com/Creating-OSX-packages.html
445458
error(
446-
'unsupported system for building the installer: '
447-
+ host_machine.system(),
459+
'unsupported system for building the installer: ' + host_machine.system(),
448460
)
449461

450462
endif
@@ -466,7 +478,7 @@ if build_application
466478
endif
467479

468480
have_file_dialogs = false
469-
have_discord_sdk = false
481+
have_discord_social_sdk = false
470482

471483
nfde_dep = dependency(
472484
'nativefiledialog-extended',
@@ -489,29 +501,33 @@ if build_application
489501

490502
c = meson.get_compiler('c')
491503

492-
discord_dep_required = not meson.is_cross_build() and get_option('build_installer')
504+
discord_dep_required = (
505+
not meson.is_cross_build()
506+
and get_option('build_installer')
507+
)
493508

494-
if host_machine.system() == 'linux' and host_machine.cpu_family() == 'aarch64'
509+
if (
510+
host_machine.system() == 'linux'
511+
and host_machine.cpu_family() == 'aarch64'
512+
)
495513
# not supported on aarch64 linux :(
496514
discord_dep_required = false
497515
endif
498516

499-
discord_sdk_dep = dependency(
500-
'discord-game-sdk',
517+
discord_social_sdk_dep = dependency(
518+
'discord-social-sdk',
501519
allow_fallback: true,
502520
required: discord_dep_required,
503-
# only with msvc we need a static library, all others work without adding __declspec() everywhere
504-
static: c.get_id() == 'msvc',
505-
default_options: c.get_id() != 'msvc' ? {} : {'default_library': 'static'},
506521
)
507-
if discord_sdk_dep.found()
508-
have_discord_sdk = true
522+
523+
if discord_social_sdk_dep.found()
524+
have_discord_social_sdk = true
509525
graphics_lib += {
510526
'compile_args': [
511527
graphics_lib.get('compile_args'),
512-
'-D_HAVE_DISCORD_SDK',
528+
'-D_HAVE_DISCORD_SOCIAL_SDK',
513529
],
514-
'deps': [graphics_lib.get('deps'), discord_sdk_dep],
530+
'deps': [graphics_lib.get('deps'), discord_social_sdk_dep],
515531
}
516532
endif
517533

0 commit comments

Comments
 (0)