'How to have relative paths in optset?

We have a few related projects which reside in a common folder but at different nesting levels - like:

  • C:\MyProject\MainApp\MainApp.dproj
  • C:\MyProject\ServiceTools\Tool1\Tool1.dproj.

We're using option sets to configure common settings across these projects.

The problem is with paths in the optset: I really want them to be relative, like:

<DCC_UnitSearchPath>.\libs\SomeLib\src;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>

However this doesn't work with different nesting levels, because the paths are expanded regarding to the importing .dproj's location, not regarding to the containing optset.

How can I get the "relativeness"? Maybe there is a macro like $(LocationOfThisOptsetFile) or similar?



Solution 1:[1]

Relative paths work fine, we use them starting from version Delphi 7 till Delphi 11. Specific to using them: first one is that it always starts calculating from the location of “dproj” file, second – there is some problem, if you try to install “BPL” into an IDE, it can't find it.

If we talk about a specific variable in “optset-file” – didn’t know about any of it.

We recommend you use your own “environment variable” (it can be system, user, or created directly in IDE) to your work folder(or use a few variables specified to your project).

Example: Variable name: MainProject Value: C:\Work\MainProject BPL package located in: C:\Work\MainProject\Kaskad\Source\ExternalPackages\dac\Delphi27 Options for it:

<DCC_DcpOutput>$(MainProject)\Lib\$(Platform)\$(Config)</DCC_DcpOutput>
<DCC_BplOutput>$(MainProject)\Bin\$(Platform)\$(Config)</DCC_BplOutput> 
<DCC_UnitSearchPath>$(MainProject)\Lib\$(Platform)\$(Config);$(BDSCOMMONDIR)\Dcp\$(Platform);..\;..\Design;$(BDS)\source\ToolsAPI;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<DCC_DcuOutput>$(MainProject)\Lib\$(Platform)\$(Config)</DCC_DcuOutput>

In this case you can use the same codebase synchronized via GIT on different PC, even if on other PC projects placed in another location, just use this new location in the environment variable. If you need add into searchPath, let’s say folder “C:\Work\AltSQLDeveloper\Sources”, for same BPL you can use:

$(MainProject)\..\AltSQLDeveloper\Sources

OR

..\..\..\..\..\..\AltSQLDeveloper\Sources

Both solutions will work fine for BPL, but if you plan to use it in “optset-file” – choose the first one. It will be the same folder to any project.

P.S. If you plan to use MSBuild for CommandLine compilation – you must set your custom “environment variable” in your BAT-file or in “c:\Program Files (x86)\Embarcadero\Studio\21.0\bin\rsvars.bat”

P.P.S. If you really need a variable with otpset-file location, you can write your own parser/manager with custom functionality. Dproj-file it’s just a simple xml.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1