What is the best way to share Delphi source files among projects?
Clarification: We want to use a single source file in multiple Delphi projects. We've been using our SCM tool to put the same file into multiple folders, but this is not a super-elegant experience and we are also considering migrating to a tool that doesn't support this.
As I’ve been investigating this question, I’ve considered a few different approaches, but I’d like to know what you’re doing and how you find your approach.
Important Scenarios:
- Code-time
- Adding a new sharing dependency should require explicit declaration, so that sharing is managed.
- Adding a new sharing dependency should still be relatively simple; it should not require a complicated process.
- One file which lists all of the project’s “imported” files (from externally) would be nice.
- Compile-time
- All projects should always build with the one current version (current as of the source sync state plus local edits).
- (Maintaining different versions in different locations should use file branching, which is not the topic, here.)
- Whether each project should be able to affect the shared file’s compilation with different compiler settings (including flags) is arguable.
- It’s arguably easier to maintain (i.e. long-term) source code that is always built consistently.
- It’s arguably easier to make maintenance fixes (i.e. short-term) if the scope of said changes can easily be restricted to one project.
- All projects should always build with the one current version (current as of the source sync state plus local edits).
- Debug-time
- The correct version of the source should automatically open, when stepping into a routine or setting a breakpoint.
- Editing the displayed source should affect the next build.
- We do not want to debug against a temporary copy of the source: we'd probably lose code, in the confusion.
Considerations:
- Near-Term:
- What approach will be simplest to put in place?
- Long-Term:
- What approach will be simplest to use and maintain?
Thanks, in advance, for your feedback!
Mattias
--- UPDATE ---
Thanks for your feedback, via answers, comments, and votes!
I've started down the path of putting shared files into one "producer" project and importing a list of compiled files into each "consumer" project. The projects are being linked together with MSBuild. Once things are more nailed-down, I'll edit this question and the "Library Project" answer, to share what I've learned.
Stay tuned! (But don't hold your breath; you'll asphyxiate within minutes! :P )