Chau Chee Yang
Chau Chee Yang

Reputation: 19600

How to keep dcu files in per project folder (e.g.: .\$(Platform)\$(Config)\$(ProjectFilename)?

I have lot of Delphi projects in a project group. I can set Unit output directory to .\$(Platform)\$(Config) and all dcu files will keep in the directory according to platform and config value.

In my build environment, I would like to set the Unit output directory to something like .\$(Platform)\$(Config)\$(ProjectFilename) so all DCU files shall keep in it's own directory identified by current project file.

The Build Events in Project | Options has $(ProjectFilename) macro but I can't use it in Unit output directory.

I want to set .\$(Platform)\$(Config)\$(ProjectFilename) to all projects' Unit output directory and it will keep all DCU files in unique project directory.

Upvotes: 3

Views: 2344

Answers (2)

Chau Chee Yang
Chau Chee Yang

Reputation: 19600

I found this answer coincidentally. I pick one project and (ms)build with verbosity of diagnostic. By studying the output of msbuild, I simply pick a variable: MSBuildProjectName and specify in my optset file shared by 300 projects:

<DCC_DcuOutput>.\$(Platform)\$(Config)\$(MSBuildProjectName)</DCC_DcuOutput>

And I try build all projects in IDE. Amazingly, Delphi create folders for each project built and keep the DCU files in the folders respectively.

Upvotes: 6

Deltics
Deltics

Reputation: 23036

The Build Events pre-processors supports a range of macros, some of which are equivalent to some environment variables.

The DCU Output folder setting supports only environment variables and not these macros.

Possible Alternative Approach

To get a per-project DCU folder you can take a different approach, making dcu a subfolder of the current project, e.g.:

Unit Output Directory: .\dcu

(or perhaps just "dcu", but I prefer to include the ".\" if only to make it clear that the relative setting is intentional)

This achieves the objective of keeping the DCU's for each project separate from each other, but means you no longer have all DCU's in a separate location outside of the project folder.

You can of course still use the $(platform) and $(config) variables in this relative path, if this is important to you:

Unit Output Directory: .\dcu\$(platform)\$(config)

Whether this is an acceptable compromise only you can say in your situation.

Often the intention of keeping DCU's in a location other than the project folder is to:

  • keep the project folder "clean"

  • avoid having to maintain a long list of "ignore" entries for each dcu file in VCS (SubVersion/Git etc)

Keeping DCU's in a project subfolder achieves the first of these, and the second issue is much simplified by being able to add just the DCU subfolder to the VCS ignore list, to ignore any file in that DCU folder.

Upvotes: 1

Related Questions