Skip to content

Build from source on Mac

Toni Fadjukoff edited this page Jun 16, 2013 · 2 revisions

1. Install command line tools from xcode:

  • Install Xcode from the Mac App store
  • Go to preferences, downloads and click install next to command line tools

2. Install homebrew (personally, this is my package manager of choice). If you know how to use other package managers well (macports) please skip this step. I have not tested this guide for macports
http://mxcl.github.io/homebrew/

3. Install qmake:
Homebrew: brew install qt
Macports: sudo port install qt4-mac

4. Install libzip:
brew install libzip

5. Install qt5 for mac from: http://qt-project.org/downloads

6. Upgrade gcc
XCode should come with 4.2 version. PO has not complete support for clang on Mountain Lion so you’ll be warned.
Homebrew: brew install gcc --enable-cxx --enable-objc --enable-objcxx
Macports: http://www.ficksworkshop.com/blog/14-coding/65-installing-gcc-on-mac

7. Clone the github repo

8. cd to the pokemon-online directory. Open PokemonOnline.pro in your favorite editor and make sure the config for po_server has src/BattleManager in it. It should look something like this when you are done:

CONFIG {
SUBDIRS += src/Server \
src/BattleManager \
src/QJson \
src/QtWebsocket \#git://gitorious.org/qtwebsocket/qtwebsocket.git
src/RelayStation
}

9. cd to the pokemon-online directory and run the following command in your terminal:
qmake CONFIG+=po_server

10. Step 9 created a bunch of makefiles. However, they are a bit buggy on a mac. Here are the following things you must do for EVERY makefile:

  • if you used the first guide to update your gcc, you have actually isolated the two (which has its advantages). If you followed the guide and called the new g++, my-g++, please change every CXX and LINK line to be equal my-g++ and not g++
  • If you install libzip with homebrew, libzip is in a different place than where the make files expect it. Add the following piece to the INCPATH:
    -I{PATH TO LIBZIP}libzip/{VERSION#}/include -I{PATH TO LIBZIP}libzip/{VERSION#}lib/libzip/include
    where the path is where it is, for me it was /usr/local/Cellar/ and verion # is the version number.

11. Now run make from the pokemon-online directory. If you are getting an error that the -arch and the -Xarch options cannot be found, remove them everywhere they appear in all of the make files.

Alternative step 9/10/11.
You can specify correct parameters for qmake right away to avoid editing generated files:

GCC_PREFIX=`brew --prefix gcc`
LIBZIP_PREFIX=`brew --prefix libzip`
QR_PREFIX=`brew --prefix qrencode`
qmake -spec macx-g++ QMAKE_CC=${GCC_PREFIX}/bin/gcc-4.7 QMAKE_CXX=${GCC_PREFIX}/bin/g++-4.7 QMAKE_OBJECTIVE_CC=/usr/bin/clang++ QMAKE_OBJECTIVE_CXX=/usr/bin/clang++ CONFIG+='po_server x86_64' QMAKE_CFLAGS_X86_64 -=-Xarch_x86_64 QMAKE_CXXFLAGS_X86_64-=-Xarch_x86_64 QMAKE_CFLAGS_X86_64-='-arch x86_64' QMAKE_CXXFLAGS_X86_64-='-arch x86_64' QMAKE_OBJECTIVE_CFLAGS_X86_64-=-Xarch_x86_64 QMAKE_OBJECTIVE_CXXFLAGS_X86_64-=-Xarch_x86_64 QMAKE_OBJECTIVE_CFLAGS_X86_64 -='-arch x86_64' QMAKE_OBJECTIVE_CXXFLAGS_X86_64-='-arch x86_64' INCLUDEPATH+=#{LIBZIP_PREFIX}/lib/libzip/include LIBS+=-L${    LIBZIP_PREFIX}/lib INCLUDEPATH+=${LIBZIP_PREFIX}/include INCLUDEPATH+=${GCC_PREFIX}/gcc/include LIBS+=-L${GCC_PREFIX}/gcc/lib INCLUDEPATH+=${QR_PREFIX}/include LIBS+=-L${QR_PREFIX}/lib"

QR Prefix is only important when compiling the client. What you get from this very long command is Makefiles with sane defauls on your Mac. Explanation: Apple’s GCC 4.2 supports those -Xarch and -arch switches but vanilla GCC 4.7 does not. You need to go around the defaults of your platform.

12. If everything before ran smoothly, try to open the application called Server.app in pokemon-online/bin. If that works, then congrats: you have a server

  • if you are getting an error, please run the following command from your command line from within pokemon-online/bin
    Server.app/Contents/MacOS/Server

This will run the server on the command line so you can see the error for yourself. If you get an error about connecting to a database, please perform the following steps:

  • Find your qt plugins
    your plugin folder will probably be in the following place if you installed from homebrew:
    /usr/local/Cellar/qt/4.8.2
  • create a directory within Server.app/Contents called PlugIns
    copy all of the plugins from your qt plugins into the folder you just created

Now you should be able to run the server.