简体   繁体   中英

How do I make third party component's DCU files, not to get generated in my application directory?

In my Delphi, whenever I rebuild my application, all 3rd party component's DCU files are getting generated in my application's directory, where the executable resides.
How do I change this behaviour?
So that third party component's DCU files won't get generated in my application directory.

The .dcu files that the compiler generates are all created in the same directory. So there's no way to put generated .dcu files files into different directories and separate those from third party libraries from those from your source files.

However, it's generally a bad idea to put the .dcu files into the same directory as the source files. That just clutters things up. Best practise is to put the .dcu files into a sub-directory of your project. The compiler options let you do this. Open up the compiler options dialog and change the target drop down to All configurations - All platforms . This is the base configuration that you other configurations inherit from. The dialog looks like this:

在此输入图像描述

The setting you need to change is Unit output directory . The image above shows the default for a new project on XE2. The value .\\$(Platform)\\$(Config) is expanded by the compiler. So if you are building a debug config targeting the Win32 platform, your .dcu files will be output to .\\Win32\\Debug .

The compiler options are documented here: http://docwiki.embarcadero.com/RADStudio/en/Delphi_Compiler

The description of the unit output directory is:

Specifies a separate directory to contain the .dcu .

The other closely related option is the output directory . This is where the compiled executable file will be placed. If you are targeting multiple platforms then you really need to put this executable file somewhere other than the main project directory. Otherwise automating build becomes difficult and error prone. It's all too easy to pick up an out of date 32 bit executable when you actually want a 64 bit executable.

So my advice to you is to use the default of .\\$(Platform)\\$(Config) since it is an excellent default.

I generally make a COMP\\ folder in my source repository, which I will show as a folder tree here:

    root
      |
      comp\
      | |
      | |--  TMS\   - TMS component set
      | |
      | |--  JEDI\  - Jedi VCL and JCL
      | |
      | |--  Something\ - Your other favorite component
      |
      app\    - My application source code.

Under the comp\\ folder I create the following other DCU folders:

    comp\
      |
      LIB\
        |
        DXE4\

All my component packages (.dpk + .dproj) are modified to build and output into the comp\\LIB\\ xxx folder, where xxx is a short code that refers to a specific delphi version.

Then from my delphi root\\App\\MyApp1 folder, I have a APP\\DCU\\DXE4 folder, which is where the DCU files go for my main application project App.dproj . The Project Search Path for App.Dproj pulls in the already-compiled DCU, DFM and RES files which are found in comp\\LIB\\DXE4. This means that the App\\ projects do NOT rebuild my components from their source code files. This speeds up compilation.

As David points out, each project has only one DCU OUTPUT folder which is specified. So that folder which is the DCU OUTPUT folder for my component .dpk package compilation becomes a library INPUT folder, during my application (.dpr+.dproj) compile stage.

Because I need to make both .dfm, .res, and .dcu files available in the COMP\\LIB\\DXE4 folder, I have a batch file (buildcomp.cmd) which does all builds, and copies necessary to make the LIB\\DXE4 folder contain all it must contain. I do NOT check the contents of the LIB... folders into my version control system. They are binary and output products of my Component Build stage. Keeping the Component Build stage and the Application Build completely separate is a more scalable approach for larger applications and larger sets of components.

I choose to keep the BPL and DCP files in their default location (under %(BDSCOMMONDIR)\\BPL ) but some people choose to redirect their BPL and DCP files into their COMP\\LIB\\DXE4 equivalent folder. There is no uniform standard behaviour among Delphi developers, each developer or company seems to do what works for them. The bog standard Delphi practice is to ignore such practices completely and be as disorganized as possible, so the fact that you have started to even ask such a question speaks to the praiseworthy tendency you have to notice that there is some disorder that you may wish to impose some structure of some kind upon, if it benefits you or your company.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM