views:

1166

answers:

6

Hi,

I'm involved in C++ project targeted for Windows and Linux (RHEL) platforms. Till now the development was purely done on Visual Studio 2008. For Linux compilation we used 3rd party Visual Studio plugin, which read VS solution/perojects files and remotely compiled on Linux machine.

Recently the decision was to abandon the 3rd party plugin.

Now my big concern is a build system. I was looking around for cross platform build tools. This way I don't need to maintain two set of build files (e.g. vcproj/solution for Windows and make files for Linux).

I found the following candidates: a. Scons b. cmake

What do you think about the tools for cross-platfrom development?

Yet another point that bothers me is that Visual Studio (+ Visual Assist) will loose a lot functionality without vcproj files - how you handle the issue with the tools?

Thanks Dima

PS 1: Something that I like about Scons is that it (a) uses python and hence it's flexible, while cmake uses propriety language (I understand that it's not a winner feature for a build-system) (b) self contained (no need to generate makefiles on Linux as with cmake).

So why not Scons? Why in your projects the decision was to use cmake?

+7  A: 

CMake will allow you to still use Visual Studio solutions and project files. Cmake doesn't build the source code itself, rather it generated build-files for you. For Linux this can be Code::Blocks, KDevelop or plain makefiles or still other more esoteric choices . For Windows it can be among others Visual Studio project files and still others for MacOS. So Visual Studio solutions and projects are created from your CMakeLists.txt. This works for big projects just fine. E.g. current Ogre3d uses CMake for all platforms (Windows, Linux, MacOS and IPhone) and it works really well.

I don't know much about scons in that regard though, I only used to build one library and only in Linux. So I can't compare these two on fair ground. But for our multi-platform projects CMake is strong enough.

haffax
CMake is pretty good - it will *regenerate* the VS project files, so it is partially misleading to say "Allows you to still use ... project files".I would highly recommend it for a C++ project, as the only solution if one requires compatibility amongst many OS's that include windows (Windows is the only "difficult" one...), and where you also want to use Visual Studio.
Arafangion
I hope the rest of my answer clears this up. :)You're right of course. The solution files you have right now are replaced by generated ones. CMake will add a few projects to your solution itself (ALL_PROJECTS, INSTALL, ZERO_CHECK) these may feel awkward at first but are pretty handy once you leanr what they are for. Especially INSTALL. It will build all parts of the solution and copy created DLLs, EXEs and other files as specified in the CMakeFiles.txt to their target dirs so that you can just run NSIS or other package tool to create an installation package.
haffax
It's worth noting that SCons *can* generate VS project files.
Diaa Sami
+3  A: 

I haven't used Scons before, so can't say how that works, but CMake works pretty well.

It works by producing the build files needed for the platform you're targeting.

When used to target VC++, it produces solution and project files so from VS, it appears as if they were native VS projects. The only difference is, of course, that if you edit the project or solution directly through VS, the changes will be erased the next time you run CMake, as it overwrites your project/solution files.

So any changes have to be made to the CMake files instead.

jalf
A: 

Hi there,

Had to do this a lot in the past. What we did is use gnu make for virtually everything including windows at times.

You can use the project files under windows if you prefer and use gnu make for Linux.

There isn't really a nice way to write cross platform makefiles because the target file will be different among other things (and pathname issues, \ vs / etc). In general, you'll probably be tweaking the code across the various platforms to take subtle differences into account, so a tweak to a make file and checking on the other platforms would have to happen anyway.

Many OS projects maintain Makefiles for different platforms such as zlib where they are named like Makefile.win, Makefile.linux etc. You could follow their lead.

Matt H
What is the advantage over using something like CMake with your approach? With CMake you only have to manage one set of build files and still can use your favorite IDE to full advantage.
haffax
One advantage is that it may be easier to use the standard scripts for each system rather than to figure out a single cross platform script that just somehow works around any quirks for all OS's. Still a lot of duplication effort, though...
Arafangion
+1  A: 

We have a big number of core libraries and applications based on those libraries. We maintain a Makefile based build system on Linux and on Windows using the Visual Studio solution for each project or library.

We find it works well for our needs, each library or app is developed either on linux or windows with cross compilation in mind (e.g. don't use platform specific api's). We use boost for stuff like file paths, threads and so on. In specific cases we use templates/#defines to select platform specific solution (for example events). When is ready we move to the other system (linux or windows), recompile, fix warnings/errors and test.

Instead of spending time figuring out tools that can cross compile on both platforms we use system that is best for each platform and spend time fixing specific issues and making the software better.

We have GUI apps only on Windows atm. so there's no GUI to cross compile. Most of our development that is shared between Windows and Linux is server side networking (sockets, TCP/IP, UDP ...) and then client side tools on Linux and GUI apps on Windows.

Using with perforce for source code version management we find in quite many cases that the Linux Makefile system is much more flexible for what we need then Windows VS. Especially for using multiple workspaces (views of source code versions) where we need to point to common directories and so on. On Linux this can be done automatically running a script to update environment variables, on Visual Studio referencing environment variables is very inflexible because it's hard to update automatically between views/branches.

Re sync question:

I assume you are asking how to make sure that the two build systems get synchronized between linux and windows. We are actually using Hudson on Linux and CruiseControl on Windows (we had windows first with cruise control, when I went to setup linux version I figured Hudson is better so now we have mixed environment). Our systems are running all the time. When something is updated it is tested and released (either windows or linux version) so you would know right away if it does not work. During testing we make sure all the latest features are there and fully functional. I guess that's it, no dark magic involved.

Oh you mean build scripts ... Each application has it's own solution, in solution you setup up dependencies. On Linux side I have a makefile for each project and a build script in project directory that takes care of all dependencies, this mostly means build core libraries and couple of specific frameworks required for given app. As you can see this is different for each platform, it is easy to add line to build script that changes to directory and makes required project.

It helps to have projects setup in consistent way.

On Windows you open project and add dependency project. Again no magic involved. I see this kind of tasks as development related, for example you added new functionality to a project and have to link in the frameworks and headers. So from my point of view there is no reason to automate these - as they are part of what developers do when they implement features.

stefanB
I'll vote up if you say how you ensure that the various build scripts do not go out of sync. (a Continuous integration server would be one way)
Arafangion
EASILY worth the upvotes now!
Arafangion
+1  A: 

Here is an article about the decision made by KDE developers to choose CMake over SCons. However I've to point that this article is almost three years old, so scons should have improved.

Here is comparison of SCons with other building tools.

Ismael
Also note that SCons is more generic, while CMake is biased towards particular languages.
Arafangion
+2  A: 

Another options is premake. It's like cmake in that it generates solutions from definition files. It's open source and the latest version is very highly customizable using Lua scripting. We were able to add custom platform support without too much trouble. For your situation it has support for both Visual Studio and GNU makefiles standard.

See Premake 4.0 Homepage

CruiseControl is a good choice for continuous integration. We have it running on Linux using Mono with success.

Aaron Saarela
I wouldn't recommend premake because of the lack of popularity/community/support compared to CMake and SCons which are used be several major projects.
Diaa Sami