Search code examples
idelazarus

Lazarus - How to create an own $(CustomRelativeUnitPath)


as mentioned quiet similar in the header, may someone tell me, how can I create an own custom-relative-unit-path for the lazarus IDE (version: 2.0.6) .

The IDE has alreaday some internal $(RelativePaths) but I would like to create my own ones and setting them up in the "other unit paths" and finally use them of course ^^

i wanna do somewhere like: "$(MyCustomPath) = C:\Lazarus(someotherpathhere..)"

and put $(MyCustompath) in the "other unit" line and have it work ^^

Below what I would like to see :-)

Best regards

Shpendicus

enter image description here


Solution

  • I think the way to do this may be to use Lazarus IDE macros.

    See https://wiki.freepascal.org/IDE_Macros_in_paths_and_filenames for full documentation.

    In the section IDE Macros it says

    IDE macros: they can be used in almost all IDE fields, e.g. search paths, custom options, file names, run parameters. They are replaced with their value before calling external tools like the compiler or the debugger. They are case insensitive.

    and the IDE macro format section includes a few examples of ones which are already defined.

    Creating macros is explained here: https://wiki.freepascal.org/Macros_and_Conditionals

    To set a macro up for the current project, do the following:

    • Go to Project | Project Options | Compiler Options | Additions and Overrides
    • On the righthand side, click Add and select IDE Macro from the drop-down menu This will open an IDE Macro line in the editor below. In it, replace MacroName by MyCustomPath and Value by whatever you like. I used D:\Lazarus2\MA
    • Close the Project Options pop-up

    Next, in the directory that MyCustomPath points to, create a unit e.g. Test.Pas that includes a compile stopper like an ! I used

    unit Test
    
    interface
    !
    implementation
    
    end.
    

    Add Test.Pas to the project's Uses list and attempt to compile. The compiler should complain that it can't find Test.Pas.

    Next, open Project | Project Options | Compiler Options | Paths and in the Other unit files box at the top insert $(MyCustomPath)

    Close Project Options and compile - now the compilation should proceed until it encounters the compile-stopping ! in Test.Pas