在MacOS M1处理器平台编译ygopro的过程

声明:本教程好像没啥卵用,我忙活了半天才发现萌卡已经原生支持ygopro了。但是作为一种摸索过程还是挺有趣的。

Ygopro支持premake和cmake生成makefile,但是我无法用premake编译出能使用的irrlicht。

由于本教程使用的是homebrew自带的irrlicht包所以不支持中文输入。irrlicht在M1平台编译成静态库之后,在最后编译app时候会出现若干错误:
Symbol not found: _inflateValidate on macOS ...
所以权衡之下只能用homebrew自带的包了。

irrKlang不支持arm64架构,所以默认无法使用。

主要的流程大致与mercury233写的mac编译教程差不多,但是如果直接按照教程走会出现各种问题(M1平台的mac更改了库的路径)。

Clone the repo

Clone the ygopro repo along with submodules to local:

git clone git@github.com:Fluorohydride/ygopro.git --recursive
cd ygopro
git submodule update --init
cd ocgcore/
git checkout master 
cd ..
cd script/
git checkout master 
cd ..

Install dependencies through Homebrew

The following dependencies should be installed by homebrew:

  • freetype
  • libevent
  • libx11
  • sqlite
  • zlib

Download Source Code of Lua and extract it to ygopro folder. Rename it as lua. You should have a folder named lua in ygopro directory.

By default lua is compiled with c compiler in MacOS. We need to modify the makefile in ygopro/lua/src/Makefile and set CC= clang++ in 9th line.

Now run command make macosx in lua folder to generate lua library.

The next step is to tell cmake to find the lua lib:

go to

cmake/macros/FindLua.cmake

and change the first two code blocks into:

FIND_PATH(LUA_INCLUDE_DIR lua.h
  HINTS
  ./lua/src
  $ENV{LUA_DIR}
  PATH_SUFFIXES include/lua53 include/lua5.3 include/lua include
  PATHS
  ~/Library/Frameworks
  /Library/Frameworks
  /sw # Fink
  /opt/homebrew
  /opt/local # DarwinPorts
  /opt/csw # Blastwave
  /opt
)

FIND_LIBRARY(LUA_LIBRARY 
  NAMES lua53-c++ lua5.3-c++ lua-5.3-c++ lua-c++ lua
  HINTS
  ./lua/src
  $ENV{LUA_DIR}
  PATH_SUFFIXES lib64 lib
  PATHS
  ~/Library/Frameworks
  /Library/Frameworks
  /sw
  /opt/homebrew
  /opt/local
  /opt/csw
  /opt
)

go back to ygopro folder and run:

ccmake .

This should toggle an interface and you should type c to configure the cmake setting (you should see Configuring done in the last line after the configuration is done). type e to exit the interface and type q to exit ccmake.

run

cmake .

to generate the Makefile.

run

make

to build the project.

M1 cpu has 8 cores so I strongly recommend using make -j8 to accelerate the process.

You should see an file named ygopro in the bin folder. Now run the following command in ygopro folder to generate an app bundle in MacOS platform.

mkdir -p ./ygopro.app/Contents/MacOS/
cp ./bin/ygopro ./ygopro.app/Contents/MacOS/ygopro

The app may have problem when running in high resolution. The solution is to create a file under ./ygopro.app/Contents/ and copy/paste the following code to the file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSHighResolutionCapable</key>
	<false/>
	<key>CFBundleIdenfier</key>
	<string>com.ygopro.1app</string>
</dict>
</plist>

Open the app and enjoy the game!

MyCard 发行的 Mac YGOPro 是 x86 Mac 和 M1 Mac 双兼容的,而且 MyCard 客户端也同时支持 x86 和 M1 的 Mac。

我发现了哈哈,所以我说这是个摸索过程。

沪ICP备14034452号-1