aliens

Author Topic: Building on macOS  (Read 10364 times)

Offline Golden Sectivin

  • Squaddie
  • *
  • Posts: 3
    • View Profile
Building on macOS
« on: January 20, 2018, 07:31:30 pm »

Hi All!,

I'm interested in building on, and potentially helping with, the macOS part of OpenXcom.  Are there any macOS devs active?

I had a real pain of a time trying to build OpenXcom.

From the macOS readme, it appears that "luciderous" is no longer on github, and rcreasey's fork of OpenXcom hasn't been modified for two years.

As-is you cannot build on a relatively recent macOS.  I had to do the following on my working copy:

( Install SDL, linking to the individual libs -- I think we should have the SDL2.framework included so that this step isn't needed. )

( Install yaml via MacPorts -- the example command appears to no longer be valid syntax, you have to separate each package fetch into its own command due to the +universal variant.  Otherwise MacPorts complains that yaml-cpp+universal doesn't exist. )

Open the Xcode project, update to recommended settings since the project file is so old.

   ifdef main() to remove, on macOS, const from arg ( SDL on Mac issue )
   
   comment out impl of
      - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename

   Select “OpenXcom” (target) in project navigator,

      Add SDL2.Framework to build phases, link

      Build Settings -> Header Search Paths:
               + “/Library/Frameworks/SDL2.Framework/Headers/“

      Build Settings -> Apple LLVN <vers> - Language - Modules
               Enable Modules (C and Obj-C) == NO


Thanks!


Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8617
    • View Profile
Re: Building on macOS
« Reply #1 on: January 20, 2018, 07:37:14 pm »
Here's something I wanted to try for a few weeks now, but didn't get to it yet...

Well there is a lot too it,  or you would see more OSX bundles.  :D  Someone better at this then me needs to fix the OpenXcom.xcodeproject file as it is horribly out of date and next to useless.  Instead I had to use cmake.

Step one would be to install Xcode app bundle from the App store.  Then you need to install the command line tools, by opening the Terminal.app (found in /Applications/Utilities) and entering this command "sudo xcode-select --install"  This will get you the clang compiler as with a whole other slew of apple libraries you will need.

I would also recommend finding the MacOSX10.9.sdk online, putting it in "/Developer/SDKs/" directory, and compiling against that (more on that later). Otherwise any app you build will not have any backwards compatibility with OSX earlier than 10.12!  10.9 is the earliest you can do without hitting XCode Apple imposed limitations.  You can further get around this by installing 10.6 on a VM like I do, and compiling there, but you will have to build the yaml-cpp and SDL_gfx.frameworks from scratch. The way apple works is any app and libraries built for intel x86 or x86_64 on an earlier OS will work for all the later OS with no issues.  10.5 is technically the first OS that supported intel, but 10.6 was more popular. (As oppose to PowerPC which was stopped being supported after 10.6).

Step two would be to collect the required frameworks.  Although SDL.framework, SDL_image.framework, and SDL_mixer.framework are easy to get.  SDL_gfx.framework and yaml-cpp.framework are not, especially for x86_64 10.9+ mac.  The easiest way is to simply download the openxcom 1.0 package, right click on the openxcom.app bundle, navigate to Contents -> Frameworks and take the framework libraries there.  (The ones I use in my bundles, I removed the header files which is standard practice to make the app size smaller as these are not needed for runtime).

Step three - place the .framework files either in the systemwide /Library/Frameworks or /User/Username/Library/Frameworks Technically speaking the later is better, but to get at it for 10.12, you have to hold shift, go to the Go menu in the finder, and select Library.)

Step four is to install cmake.  Easiest way is to install macports which you can seach and has it's own installer. (or homebrew if you prefer, but I don't as I think it's a big no no to mix apple tools with gnu ones, but some would disagree...Anyway...)   The macports command to install cmake is "sudo port install cmake".

Step Five. Now we can actually build the app.
Open up the terminal again type "cd /directory/to/openxcdomextended/source"

Then "mkdir build"

"cd build"

then (providing you could find the MacOSX10.9.sdk "cmake .. -DMACOS_SDLMAIN_M_PATH:/openxcom/src/root/xcode/OpenXcom/SDLMain.m -DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.9.sdk -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9"

Pay attention to the output on the terminal.  There may be one or two packages I'm forgetting that are needed for compiling. In which case, you would install them via macports "sudo port install whateverPackage"   Take a look at the macports available ports page, and search to get their exact names.

then type

"make -j#" (# being the number of cores you want to compile with to speed it along).


Cmake is smart enough to make the base app, and even will throw the frameworks in for you.  (I'd still remove the headers from the frameworks files before distributing).


Step 7  Fix the app
You still have to throw the standard, common, TFTD, and UFO folders in the resource folder.  As well as the app icon (.icns) which is in the xcode folder, unless you would like to create your own.

You then need to edit the info.plist file.  There you can edit the version number for the app to whatever you like on the CFBundleShortVersionString string.  Also make sure CFBundleIconFile has the name of the icon minus the .icns extension and CFBundleExecutable is the same as the actual executable in the MacOS folder.

Finally cmake didn't properly point the executable to the framework files inside the app bundle .  You have to do this manually or users would have to install the frameworks on their system, which no one does.  In a terminal use the command "install_name_tool -add_rpath @executable_path/../Frameworks /directory/to/OpenXcom.app/Contents/MacOS/openxcom" 


Step 8 - Distribute
Standard practive is to put the app in a .dmg compressed archive.  (This is better then zip as like .tar it preserves permissions) There are a couple ways to do it.  The usual is to throw the app in a folder, along with any documentation, go to /Applications/Utilities/Disk Utility.app.  Then File-> New Image -> Image From Folder. Navigate to the folder, then select no encryption, and set image format to compressed.  Then give it a name and press save.  The Keka app even makes it easier with a drag and drop, and I think it's compression rate is a little better.  There is also a command line way to do it with "hdiutil create -volname WhatYouWantTheDiskToBeNamed -srcfolder /path/to/the/folder/you/want/to/use -ov -format UDZO name.dmg"  if you ever plan on writing a script.

Also because the app isn't code signed, users will have to right click and select open, then press open in the dialog box.  To code sign, you would have to register as an apple developer and shell out $100.  Then there is some command you have type to sign the app with your credentials.  But I'd have to look it up.

I think that's it.  Good Luck!

Offline Golden Sectivin

  • Squaddie
  • *
  • Posts: 3
    • View Profile
Re: Building on macOS
« Reply #2 on: January 24, 2018, 07:52:16 pm »
Here's something I wanted to try for a few weeks now, but didn't get to it yet...

I have the OpenXcom macOS project building in both Debug and Release (without cmake), and seems to be fine. I've even toyed around with making some "improvements" (having statstrings in names in the transfer summary screen, changing RNG to use xoroshiro128+, etc).

Since it looks like it's just you two supporting macOS in a time-limited fashion, I would be happy to help if you'd like.


Offline tomesm

  • Squaddie
  • *
  • Posts: 3
    • View Profile
Re: Building on macOS
« Reply #3 on: February 07, 2018, 10:54:34 pm »
Hi, I am also trying to build on mac (high sierra).
Can you please tel mee what exactly you did during this step:

   ifdef main() to remove, on macOS, const from arg ( SDL on Mac issue )


I did not get it what did you in what file :)

Also, I have tried to build based on the original README using cmake. I have installed SDL with brew (based on the original README) and yaml-cpp via macports, but I am getting:
Code: [Select]
OpenXcom/src/Engine/OptionInfo.h:20:10: fatal error:
      'yaml-cpp/yaml.h' file not found
#include <yaml-cpp/yaml.h>

Any thoughts?

Offline tomesm

  • Squaddie
  • *
  • Posts: 3
    • View Profile
Re: Building on macOS
« Reply #4 on: February 10, 2018, 01:38:17 pm »
Well, I have managed to build it with cmake but I am getting linking error. What I have done:

1) install SDL library and its dependencies (mixer, image, gfx) via brew as stated in original README.
2) DO NOT INSTALL yaml_cpp via brew. Use 'sudo port install yaml-cpp' instead
3) Download OpenXcom.app 1.0 Bundle and copy all frameworks from Contents to /User/Library/Frameworks
4) cd OpenXcom and mkdir build. then CC=/usr/bin/gcc CXX=/usr/bin/g++ cmake ..
5) make

than I am getting error:

[  1%] Linking CXX executable ../openxcom.app/Contents/MacOS/openxcom
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
     (maybe you meant: _SDL_main)
ld: symbol(s) not found for architecture x86_64

--- posts merged ---

I DID IT!!! I just forgot to specify -DMACOS_SDLMAIN_M_PATH=/path/to/your/SDLMain.m

So again the whole step by step for cmake is:

1) install SDL library and its dependencies (mixer, image, gfx) via brew as stated in original README.
2) DO NOT INSTALL yaml_cpp via brew. Use 'sudo port install yaml-cpp' instead
3)wnload OpenXcom.app 1.0 Bundle and copy all frameworks from Contents to /User/Library/Frameworks
4) cd OpenXcom and mkdir build. then CC=/usr/bin/gcc CXX=/usr/bin/g++ cmake .. -DMACOS_SDLMAIN_M_PATH=/path/to/your/SDLMain.m
5) make
« Last Edit: February 10, 2018, 09:57:41 pm by Solarius Scorch »

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8617
    • View Profile
Re: Building on macOS
« Reply #5 on: February 10, 2018, 11:07:53 pm »
So I tried to follow your steps, but I still get this error:

Code: [Select]
MacBook-Air:build martin$ CC=/usr/bin/gcc CXX=/usr/bin/g++ cmake .. -DMACOS_SDLMAIN_M_PATH=/Users/martin/repo/oxce/OpenXcom/xcode/OpenXcom/SDLMain.m
-- The C compiler identification is AppleClang 9.0.0.9000039
-- The CXX compiler identification is AppleClang 9.0.0.9000039
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/usr/bin/gcc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/usr/bin/g++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at CMakeLists.txt:423 (add_definitions):
  Policy CMP0005 is not set: Preprocessor definition values are now escaped
  automatically.  Run "cmake --help-policy CMP0005" for policy details.  Use
  the cmake_policy command to set the policy and suppress this warning.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at CMakeLists.txt:435 (install):
  install TARGETS given no RUNTIME DESTINATION for executable target
  "openxcom".


CMake Warning (dev) at CMakeLists.txt:456 (target_link_libraries):
  Link library type specifier "debug" is followed by specifier "optimized"
  instead of a library name.  The first specifier will be ignored.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at CMakeLists.txt:456 (target_link_libraries):
  The "optimized" argument must be followed by a library.


CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.10)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring incomplete, errors occurred!
See also "/Users/martin/repo/oxce/OpenXcom/src/build/CMakeFiles/CMakeOutput.log".
MacBook-Air:build martin$

Any ideas?
« Last Edit: February 24, 2018, 10:11:31 pm by Meridian »

Offline tomesm

  • Squaddie
  • *
  • Posts: 3
    • View Profile
Re: Building on macOS
« Reply #6 on: February 11, 2018, 10:33:20 am »
Try to build as a release version and specify the install destination for the app. Just add following to your cmake command:

Code: [Select]
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/bin/OpenXcom
Perhaps this will help.

I did not experience this error at all. Don't you have your own CmakeLists.txt? Have you tried to compile it with vanilla CmakeLists? I understood your version of OpenXcom different from the vanilla.


btw I am not able to run the built app after compiling anyway.

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8617
    • View Profile
Re: Building on macOS
« Reply #7 on: February 24, 2018, 10:16:22 pm »
So, I was able to compile after adding X11 (for opengl?) and boost (for yaml-cpp)...
... but just like you, I cannot run the application, crashes immediately.

Just FYI, I added:

Code: [Select]
include_directories ( /opt/X11/include )
include_directories ( /usr/local/Cellar/boost/1.66.0/include )

after:

Code: [Select]
set ( DEPS_DIR "${default_deps_dir}" CACHE STRING "Dependencies directory" )

in CMakeLists.txt

Otherwise, I couldn't even cmake.

If anyone could help, I'll gladly remote-share my MacBook Air to learn how to do this magic...

Offline ivandogovich

  • Commander
  • *****
  • Posts: 2381
  • X-Com Afficionado
    • View Profile
    • Ivan Dogovich Youtube
Re: Building on macOS
« Reply #8 on: February 24, 2018, 10:20:24 pm »
Not sure if any of this helps: https://bitbucket.org/grrussel/openxcomosx

Offline polarpsi

  • Squaddie
  • *
  • Posts: 1
    • View Profile
Re: Building on macOS
« Reply #9 on: April 14, 2018, 10:55:49 pm »
Hey -

I just underwent the (ridiculously arduous) registration process for these forums in order to let you know that I was able to build the app successfully on High Sierra (10.13) by following the README in the xcode directory.

Basically:

- Installed all the dependencies via Homebrew as instructed (no Macports necessary)
- Cloned the repository
- Opened the xcode/OpenXcom.xcodeproj file in XCode
- Added the src directory to the XCode project (the README mentions options, but there were no options or prompts and it Just Worked)
- Went to the menu and ran Project -> Build
- Located the binary in the Finder
- Copied in the original XCOM resources

Everything seems to be working perfectly so far.

If someone wants to automate that process and make nightly binaries available on a more regular basis, I for one would be grateful.

UPDATE:  Nope, Geoscape and base manager run just fine.  Battlescape crashes with no errors logged.

NEW UPDATE: I'd just missed a folder copying in the original files.
« Last Edit: April 15, 2018, 06:15:51 pm by polarpsi »

Offline rcreasey

  • Squaddie
  • *
  • Posts: 2
    • View Profile
Re: Building on macOS
« Reply #10 on: July 29, 2018, 01:35:06 am »
I've gone and updated the build instructions that work on OSX 10.13.6 and Xcode 9.4.1.

https://goo.gl/U2y7ik

Note, that if you don't want to build with Xcode, you can still build it with make.  Just omit the '-G Xcode' generator off the make command and build normally with 'make -j4'.

I'll work on getting these added to the nightly builds as well.

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8617
    • View Profile
Re: Building on macOS
« Reply #11 on: September 21, 2018, 12:13:38 pm »
I've gone and updated the build instructions that work on OSX 10.13.6 and Xcode 9.4.1.

https://goo.gl/U2y7ik

Note, that if you don't want to build with Xcode, you can still build it with make.  Just omit the '-G Xcode' generator off the make command and build normally with 'make -j4'.

I'll work on getting these added to the nightly builds as well.

I can confirm this works!

It didn't work for me for a long time, because I've installed tons of junk trying to make it work earlier... but after a cleanup, it works fine. What I did:
- uninstalled all macport ports
- uninstalled all homebrew packages
- I think this step was the most important: deleted all content of /Users/<my user>/Library/Frameworks/
- updated homebrew
- installed only what is written in the instructions above: "brew install cmake yaml-cpp --with-static-lib sdl sdl_gfx sdl_image sdl_mixer --with-flac --with-libmikmod --with-libvorbis --with-static-lib"
- ran "cmake . -DCMAKE_BUILD_TYPE="Release"
- ran "make -j4"

Thank you very much @rcreasey
« Last Edit: September 21, 2018, 12:16:31 pm by Meridian »

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8617
    • View Profile
Re: Building on macOS
« Reply #12 on: October 14, 2018, 07:22:50 pm »
Me, again... so I updated to glorious MacOS 10.14 Mojave... compilation still works... but OpenXcom itself doesn't... it just shows black screen.

After a full day of messing around, it looks like SDK 10.14 is the reason.
I managed to download SDK 10.9 (don't remember the link) and compile OpenXcom against that SDK... and it works again.
I needed to specify path to the SDK for cmake like this "-DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.9.sdk -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9"
So the full cmake command looks like this:

Code: [Select]
cmake . -DCMAKE_BUILD_TYPE="Release" -DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.9.sdk -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9

Of course, replace the path to the SDK with whatever path you will use.
« Last Edit: November 12, 2018, 10:55:11 am by Meridian »

Offline SupSuper

  • Lazy Developer
  • Administrator
  • Commander
  • *****
  • Posts: 2159
    • View Profile
Re: Building on macOS
« Reply #13 on: October 21, 2018, 08:15:17 pm »
Me, again... so I updated to glorious MacOS 10.14 Mojave... compilation still works... but OpenXcom itself doesn't... it just shows black screen.
Seems Mojave broke all SDL applications: https://discourse.libsdl.org/t/macos-10-14-mojave-issues/25060
You can try disabling OpenGL to see if it fixes it. Otherwise, we might have to bump SDL sooner rather than later.

Offline Stoddard

  • Colonel
  • ****
  • Posts: 485
  • in a fey mood
    • View Profile
    • Linux builds & stuff
Re: Building on macOS
« Reply #14 on: October 21, 2018, 09:15:15 pm »
It's even more hilarious than usual:

https://appleinsider.com/articles/18/06/04/opengl-opencl-deprecated-in-favor-of-metal-2-in-macos-1014-mojave

So we can count on 1) apple not fixing anything 2) sdl1 not growing a Metal backend suddenly.

Couldn't have been better timing for me to make the android/sdl2 port work on PCs  ;) At least there a Metal backend is not that much work.

For now I guess it's better to stick to old SDKs, if that works / until it doesn't.

EDIT: more lols at https://mjtsai.com/blog/2018/06/07/removed-in-macos-10-14-mojave/
« Last Edit: October 21, 2018, 09:19:52 pm by Stoddard »