# 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 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

#endif

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

## Create an account

Register a new account

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013441
×

## Important Information

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!