Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: discord-rpc in cmake #925

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

surfaceflinger
Copy link
Contributor

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.

  • Bug fix (non-breaking change which fixes an issue)

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

  • Build with and without discord-rpc
  • Started otclient and checked status on Discord

Test Configuration:

  • Server Version: n/a
  • Client: this branch?
  • Operating System: NixOS 24.11.20241009.65d98cb

Checklist

  • My code follows the style guidelines of this project - no idea, question in description above
  • I have performed a self-review of my own code
  • I checked the PR checks reports
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

@kokekanon
Copy link
Contributor

kokekanon commented Oct 15, 2024

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
Copy link
Contributor Author

"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
Copy link
Contributor

kokekanon commented Oct 15, 2024

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
Copy link
Owner

mehah commented Oct 15, 2024

"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
Copy link
Collaborator

nekiro commented Oct 15, 2024

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

@surfaceflinger surfaceflinger force-pushed the cmake-discord-sdk branch 2 times, most recently from 968d52d to 77612f7 Compare October 16, 2024 17:14
@mehah
Copy link
Owner

mehah commented Oct 17, 2024

is it finished?

@kokekanon
Copy link
Contributor

kokekanon commented Oct 17, 2024

  1. works correctly in windows: vs solution release dx

but

  1. 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
Copy link
Contributor Author

surfaceflinger commented Oct 17, 2024

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

@surfaceflinger surfaceflinger marked this pull request as draft October 17, 2024 06:42
Copy link

sonarcloud bot commented Oct 31, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants