johnbakers
johnbakers

Reputation: 24750

Sharing code files between Qt projects

I'm working on some general purpose math libraries that I will want to use in multiple projects. Obviously, it makes sense for all the project to reference the same code files so if I fix something it affects all projects.

One way to do this would be to simply have them all use an INCLUDEPATH and DEPENDPATH that points to the same directory of code files.

But I was reading this: http://qt-project.org/wiki/IncludingProFiles And I'm wondering if it is better to create a .pri Qt project for purposes of inclusion only. Would this be better? Do you have to then manually change the extension from .pro to .pri?

What's the best setup for sharing code between projects?

Upvotes: 3

Views: 1877

Answers (2)

user2672165
user2672165

Reputation: 3049

The best way is to create a versioned repo of the source in e.g. git. Make it possible to build a versioned SDK (containing lib*.so/lib*.a and *.h) from the source to share. Most sucessful projects grow over time and then this investment will pay off. Learning how to do this once you can do re-use easier in the future across several platforms. Re-use is very important.

Upvotes: 3

Nicholas Smith
Nicholas Smith

Reputation: 11754

Obviously you know the way of including them with INCLUDEPATH and DEPENDPATH, which is fairly easy to setup but a bit annoying. Using a pri file does alleviate some of the headaches, and it makes it easier to add them into a new project as you go along with any additional customisation you like to have on projects. Or if you're working on a large multi-application project and need to keep similar build settings.

The third option is building them as a library file and just including them, the same as you would any library. Trickier to setup initially than just using a pri or the include directives, but it does mean the code is kept as it's own separate unit.

If it's a small amount of code, but you plan on using it often I'd use a pri, if it's a reasonably large amount of code I'd go for library, and if you only plan on using it rarely I'd use the include directives.

Upvotes: 5

Related Questions