mehah / otclient

An alternative tibia client for otserv written in C++20 and Lua, made with a modular system that uses lua scripts for ingame interface and functionality, making otclient flexible and easy to customize
Other
269 stars 209 forks source link

fix: discord-rpc in cmake #925

Open surfaceflinger opened 1 month ago

surfaceflinger commented 1 month ago

Description

Right now otclient with Discord Rich Presence support can be built with only vc17, not cmake, this PR fixes that. Since Discord isn't needed for otclient to work and also I don't think OSS projects should depend on proprietary services in any way, let's make it optional, enable it automatically if available during build. Let me know if a manual switch would be preferred, personally I like it like this.

No idea if this works on macOS/Windows 😕

Behavior

Actual

otclient built using cmake doesn't use Discord Rich Presence

Expected

If discord-rpc is available, enable it in code.

Type of change

Please delete options that are not relevant.

How Has This Been Tested

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Test Configuration:

Checklist

kokekanon commented 1 month ago

test pr in windows: cmaker

image

image image

my knowledge of cmaker is very poor, but is this always on? maybe there should be an option here to enable or disable it?

image


test pr in windows: vs solution release dx

image

more than someone will ask how to do it now. attach this picture

image

surfaceflinger commented 1 month ago

"cmaker" and "vs release" in RPC, huh? Did you add it yourself for test? :)

my knowledge of cmaker is very poor, but is this always on? maybe there should be an option here to enable or disable it?

Yes it's always on and is available when discord-rpc library is found, otherwise it's not available. Let me know if you'd prefer a toggle and failing when the library isn't there

kokekanon commented 1 month ago

I was just testing PR.

No idea if this works on macOS/Windows 😕

to confirm that it works on windows

Yes it's always on and is available when discord-rpc library is found, otherwise it's not available. Let me know if you'd prefer a toggle and failing when the library isn't there

I don't use cmaker.

mehah commented 1 month ago

"cmaker" and "vs release" in RPC, huh? Did you add it yourself for test? :)

my knowledge of cmaker is very poor, but is this always on? maybe there should be an option here to enable or disable it?

Yes it's always on and is available when discord-rpc library is found, otherwise it's not available. Let me know if you'd prefer a toggle and failing when the library isn't there

@surfaceflinger

The library is always installed, so even if the developer doesn't want discord, it will always be activated. https://github.com/mehah/otclient/blob/8cf226d73dfeb8461ac90964259e089c03ac1c13/vcpkg.json#L7C9-L7C11

nekiro commented 1 month ago

Imo should be option with default false. I don't want this enabled in my test build or local one.

mehah commented 1 month ago

is it finished?

kokekanon commented 1 month ago

1) works correctly in windows: vs solution release dx

but

2) in cmaker + windows if I use

#ifndef TOGGLE_DISCORD_RPC
    #define TOGGLE_DISCORD_RPC 1 // 1 to enable | 0 to disable
#endif

and

option(TOGGLE_DISCORD_RPC "Use Discord Rich Presence" ON)

compilation is broken (without that compiles correctly)

  [19/21] Building CXX object src\CMakeFiles\otclient.dir\Unity\unity_2_cxx.cxx.obj
  [20/21] Building CXX object src\CMakeFiles\otclient.dir\Unity\unity_8_cxx.cxx.obj
  [21/21] Linking CXX executable D:\github\otclient.readme\otclient.exe
  FAILED: D:/github/otclient.readme/otclient.exe 
  C:\Windows\system32\cmd.exe /C "cd . && "D:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=src\CMakeFiles\otclient.dir --rc="D:\Windows Kits\10\bin\10.0.22621.0\x64\rc.exe" --mt="D:\Windows Kits\10\bin\10.0.22621.0\x64\mt.exe" --manifests  -- "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\bin\Hostx64\x64\link.exe" /nologo src\CMakeFiles\otclient.dir\cmake_pch.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_19_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_18_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_17_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_16_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_15_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_14_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_13_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_12_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_11_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_10_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_9_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_8_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_7_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_6_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_5_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_4_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_3_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_2_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_1_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_0_cxx.cxx.obj src\CMakeFiles\otclient.dir\__\cmake\icon\otcicon.rc.res  /out:D:\github\otclient.readme\otclient.exe /implib:src\otclient.lib /pdb:D:\github\otclient.readme\otclient.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console /SUBSYSTEM:CONSOLE  /INCREMENTAL:NO /LTCG  vcpkg_installed\x64-windows-static\lib\lua51.lib  vcpkg_installed\x64-windows-static\lib\physfs-static.lib  vcpkg_installed\x64-windows-static\lib\zlib.lib  vcpkg_installed\x64-windows-static\lib\libprotobuf.lib  glu32.lib  opengl32.lib  vcpkg_installed\x64-windows-static\lib\ogg.lib  vcpkg_installed\x64-windows-static\lib\vorbisfile.lib  vcpkg_installed\x64-windows-static\lib\vorbis.lib  vcpkg_installed\x64-windows-static\lib\libssl.lib  vcpkg_installed\x64-windows-static\lib\libcrypto.lib  crypt32.lib  ws2_32.lib  dbghelp.lib  vcpkg_installed\x64-windows-static\lib\glew32.lib  vcpkg_installed\x64-windows-static\lib\OpenAL32.lib  vcpkg_installed\x64-windows-static\lib\lzma.lib  winmm.lib  glu32.lib  opengl32.lib  vcpkg_installed\x64-windows-static\lib\pugixml.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && C:\Windows\system32\cmd.exe /C "cd /D D:\github\otclient.readme\build\windows-release\src && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file "D:/Program Files/Microsoft Visual Studio/2022/Community/VC/vcpkg/scripts/buildsystems/msbuild/applocal.ps1" -targetBinary D:/github/otclient.readme/otclient.exe -installedDir D:/github/otclient.readme/build/windows-release/vcpkg_installed/x64-windows-static/bin -OutVariable out""
  LINK: command "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\bin\Hostx64\x64\link.exe /nologo src\CMakeFiles\otclient.dir\cmake_pch.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_19_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_18_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_17_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_16_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_15_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_14_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_13_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_12_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_11_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_10_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_9_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_8_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_7_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_6_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_5_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_4_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_3_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_2_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_1_cxx.cxx.obj src\CMakeFiles\otclient.dir\Unity\unity_0_cxx.cxx.obj src\CMakeFiles\otclient.dir\__\cmake\icon\otcicon.rc.res /out:D:\github\otclient.readme\otclient.exe /implib:src\otclient.lib /pdb:D:\github\otclient.readme\otclient.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console /SUBSYSTEM:CONSOLE /INCREMENTAL:NO /LTCG vcpkg_installed\x64-windows-static\lib\lua51.lib vcpkg_installed\x64-windows-static\lib\physfs-static.lib vcpkg_installed\x64-windows-static\lib\zlib.lib vcpkg_installed\x64-windows-static\lib\libprotobuf.lib glu32.lib opengl32.lib vcpkg_installed\x64-windows-static\lib\ogg.lib vcpkg_installed\x64-windows-static\lib\vorbisfile.lib vcpkg_installed\x64-windows-static\lib\vorbis.lib vcpkg_installed\x64-windows-static\lib\libssl.lib vcpkg_installed\x64-windows-static\lib\libcrypto.lib crypt32.lib ws2_32.lib dbghelp.lib vcpkg_installed\x64-windows-static\lib\glew32.lib vcpkg_installed\x64-windows-static\lib\OpenAL32.lib vcpkg_installed\x64-windows-static\lib\lzma.lib winmm.lib glu32.lib opengl32.lib vcpkg_installed\x64-windows-static\lib\pugixml.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST:EMBED,ID=1" failed (exit code 1120) with the following output:
     Creating library src\otclient.lib and object src\otclient.exp
D:\github\otclient.readme\build\windows-release\unity_2_cxx.cxx.obj : error LNK2001: unresolved external symbol Discord_Initialize
D:\github\otclient.readme\build\windows-release\unity_2_cxx.cxx.obj : error LNK2001: unresolved external symbol Discord_UpdatePresence

D:\github\otclient.readme\otclient.exe : fatal error LNK1120: 2 unresolved externals

  ninja: build stopped: subcommand failed.

I’m not used to using CMake; I don’t know if these are the correct steps to enable RPC in CMake

The only way I got it to work was by renaming the flag. image

surfaceflinger commented 1 month ago

I'll get a Windows VM and I'll check that. I have no idea how it works on Windows or how vs solution interacts with cmake so I tried to make both approaches available, as in, you can pass -DTOGGLE_DISCORD_RPC=1 to cmake as a flag OR change it directly in that #define in source code like it was explained in README before

sonarcloud[bot] commented 3 weeks ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud