# 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

//Your Windows code here

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

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
15

• 14
• 9
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
632912
• Total Posts
3009197
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!