• Create Account

## Setting up a project for cross-platform development

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1jwezorek  Members

2544
Like
0Likes
Like

Posted 08 March 2012 - 02:14 PM

What's the standard way of doing this? Basically I have some code that will be common between the various platforms and then will have platform-specific code for each platform. So should I have a common directory and then directories for each platform, for example?

### #2e‍dd  Members

2109
Like
0Likes
Like

Posted 08 March 2012 - 02:43 PM

There's no "one true way", but my projects tend to look something like this as far as directory layout is concerned, assuming there are platform-specific components for Mac, POSIX and Windows:

<project-name>/
include/
<project_name>/
# client headers go here

src/
# portable source and private headers go here

mac/
# mac-specific source and private headers
posix/
# posix-specific source and private headers
windows/
# windows-specific source and private headers

docs/
# docs go here.


I've never felt the need for anything more complicated. To some extent, the layout might depend on the particulars of your build system. I can do things like this in my build scripts, which makes this layout convenient in my case:

sources = here/'src/*.cpp' + here/'src'/cfg.platform/'*.cpp'
# etc


### #3jwezorek  Members

2544
Like
0Likes
Like

Posted 08 March 2012 - 02:59 PM

There's no "one true way", but my projects tend to look something like this as far as directory layout is concerned, assuming there are platform-specific components for Mac, POSIX and Windows:

<project-name>/
include/
<project_name>/
# client headers go here

src/
# portable source and private headers go here

mac/
# mac-specific source and private headers
posix/
# posix-specific source and private headers
windows/
# windows-specific source and private headers

docs/
# docs go here.


I've never felt the need for anything more complicated. To some extent, the layout might depend on the particulars of your build system. I can do things like this in my build scripts, which makes this layout convenient in my case:

sources = here/'src/*.cpp' + here/'src'/cfg.platform/'*.cpp'
# etc


I don't really have a build system per se ... just use VS2010 for Windows and plan on using XCode for Mac/iOS. I take it you build from the command line. Is there an advantage to doing this in the case of cross-platform?

### #4Caanon  Members

102
Like
1Likes
Like

Posted 08 March 2012 - 03:28 PM

I'd suggest getting familiar with CMAKE. It's a bit convoluted to learn, but once you get it up and running it can automatically generate VS project files on Windows and Linux. I haven't used it with Mac, but I would imagine it would be able to do the same.

### #5e‍dd  Members

2109
Like
1Likes
Like

Posted 08 March 2012 - 03:51 PM

I don't really have a build system per se ... just use VS2010 for Windows and plan on using XCode for Mac/iOS. I take it you build from the command line. Is there an advantage to doing this in the case of cross-platform?

Having to maintain multiple project files for various IDEs is a pain, especially if you don't have access to all the supported systems. For that reason, I have a platform/toolchain agnostic build system written as a DSL in Python. Sane people would probably use CMake instead, as Caanon suggests.

Of course, if you still use multiple IDEs, you'll have to maintain multiple project files just to make sure they all know about the new source files you add, unless they support filename globbing of some sort. I switched to Vim a few years ago and simply use sub-directories to organise 'projects' (and I now wish I had taken the time to learn it sooner, FWIW).

EDIT: I should also say that the system allows me to build my projects in a variety of ways:
• Compilers: Visual C++ 2005, 2008, 2010. MinGW 4.2, 4.5, 4.6. Apple GCC 4.0.1, 4.2.1. Apple LLVM-GCC 4.2.1.
• SDKs: 3 Platform SDKs each on OSX on Windows.
• Build configurations: debug, optimized, release.
• Architectures: x86, x64.
• + any combinations configuration options available for the project in question
The build variants that arise from the combinatorial product of these 'axes' can number in the thousands(!) for some projects. I wouldn't be able to build and test all of that anywhere near as easily without having simple, platform-agnostic build descriptions. So I count that as a pretty big advantage!

### #6jwezorek  Members

2544
Like
0Likes
Like

Posted 08 March 2012 - 04:05 PM

Yes, I see what you are saying in that it will be a pain to manually maintain multiple project files. However, I'm probably going to end up working mostly on Windows and testing on other platforms, once I have platform dependent frameworks developed for them. If I'm working on Windows I'd like to be using VS2010. Is there a tool that parses a Visual Studio project and generates make files for other platforms?

### #7e‍dd  Members

2109
Like
0Likes
Like

Posted 08 March 2012 - 04:22 PM

It wouldn't surprise me if there is, but most people use things like CMake or premake, which do things the other way around i.e. generate project files of various kinds (including for Visual Studio) from an platform agnostic project description. I'd imagine it would be worth investing a few hours in learning to use one of these tools.

### #8wqking  Members

756
Like
0Likes
Like

Posted 09 March 2012 - 12:21 AM

Even you are mostly working in IDE, some cross platform build system is quite helpful.
I use CMake.
The build system can not only build your project, but also generate project files for IDE.
Want to work in VS? Ask CMake to generate project for VS 2010.
Want to work in Code::Block, then CMake generate the project for C::B for you.

Try to learn a build system, I prefer CMake. The hours you spend on learning the build system should be quite lower than the time you spend on manipulate different project files on different platforms for different IDEs.

http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.