Making a program cross-platform

Started by
4 comments, last by mdias 10 years, 7 months ago

Hi all,

I have a couple simple applications built with OpenGL and SDL respectively. I built them in VS2010, and would like them to work on the mac and unix OS.

I'm following the CMake tutorial on this site, but so far it seems like CMake is more for programmers sharing code across different platforms - am I wrong in this assumption? How can I use CMake to make a release build work on an OS other than Windows?

Advertisement

There are undoubtedly hackish ways to code for Mac OS X without having a Mac OS X machine, but in general you need a Mac OS X machine and Xcode. You would make an Xcode project and add all the same files to it and build the same way as you do on Windows with Visual Studio.

I can’t answer in any specific manner for Unix, but it will basically be the same story with different tools.

You can’t release anything without testing it on the target platform anyway, so you will always need access to the target platform no matter what in the end, so you may as well just play it safe and simple and develop on the target machines. It’s just more sane and allows you to find bugs progressively rather than all at once at the end of development.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

For linux, the first step is to use a VM (eg virtual box), install linux into it (along with g++, the dev libs you need, make/scons, etc). Set up a shared folder (to point to your source directory), and start compiling the app a lib at a time from within your VM (which will inevitably require lots of compile error fixes). Once that's complete, you'll need a round of QA testing on the game to iron out any bugs. Having done all of that, there's a good chance that porting to Mac will be slightly easier (just set up a project in XCode). CMake may help to simplify this process somewhat (since it's possible to generate the makfiles for linux, xcode projects for mac, and VCProjs for Windows), but then again, it might not.

CMake actually makes it relatively easy to cross-compile programs, since it does all the toolchain shenanigans for you (just tell it what toolchain to use). Sadly many libraries use something else and generally seem to be hard to cross-compile, so unless you have prebuilt binaries for them that you can just drop in the relevant folders, it's going to be troublesome.

Using CMake is still going to save you the headache if you just build on the target platform directly, since you'd still use the same files, so in either case stick with it. You're going in the right direction.

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

I'm following the CMake tutorial on this site, but so far it seems like CMake is more for programmers sharing code across different platforms - am I wrong in this assumption? How can I use CMake to make a release build work on an OS other than Windows?

There are two ways to achieve what you want :

  1. You work on windows, wants to stay on windows, and build a binary for another platform (Linux, Mac, ...) : you MUST build a cross-compiler toolchain (compiler, linker, libraries), and use this toolchain to compile others libraries (SDL), and then you can use all of this (this is called cross-compile). Hopefully, you'll find some prebuild package for popular target platform.
  2. If your target platform can host a compiler and the required libraries, copy your source code, put it on your target platform and build the platform specific binaries.

The first method is very tedious though, if there is no prebuilt binaries available on internet.

Space Zig-Zag, a casual game of skill for Android by Sporniket-Studio.com

How can I use CMake to make a release build work on an OS other than Windows?

You want to have a machine running the other OS to avoid problems.

Then, on that machine, execute CMake and it will generate the project files / build scripts needed to compile for that platform. Then you need to compile it and it's done.

Keep using and learning CMake. It's a very powerful tool that can save you tons of time if used correctly.

This topic is closed to new replies.

Advertisement