Jump to content
  • Advertisement

C++ Cross-platform project structure in modules?

Recommended Posts

I've been trying to organise a small-medium sized toy game project to supports macOS, iOS and Windows simultaneously in a clean way. But I always get stuck when I cross over to the target platform. I'll try to explain,

I have organised my project in modules like so:


1. core c++ engine, platform agnostic, has a public c++ api

2. c api bindings for the c++ api, also platform agnostic, this is actually part of 1 because its such a small project

3. target platform bindings, on iOS and macOS this is in swift. Basically wraps the c api

4. target platform code. This part just calls the api. Also in swift.


So in all I have 4 modules going simultaneously, all compiled into a separate static libraries and imported into the next phase/layer. Am I even remotely close to something functional? I seem to getting stuck somewhere between 2 and 3 when I cross over to the target platform. In theory I would just need to call the game loop, but I always end up writing some logic up there anyway.


Edited by PlanetExp

Share this post

Link to post
Share on other sites

I prepared my code base for cross-platform development too when starting with last iteration of the project. This means I wrote a tool like described here

that will generate the project files for different platforms and tooling versions. This is important because different platforms need different build pipelines like Mac/iOS needs XCode for example.

I then tried different solutions but it showed that it is simplest way to just put the platform dependent files directly into your project using include guards

#include <platform.h>
#ifdef WINDOWS
  //Your Windows code here

so you could define a single header file for your platform dependent feature and multiple implementation (.cpp) files using include guards that define the code behind your "interface". I organized those files directly into a subfolder "Platform" and a subfolder for each kind of platform (I want to support Windows, Linux, Android and Non-Microsoft Consoles) that contain those platform dependent files.

This turned out to be the best solution

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!