Recent

Author Topic: [Solved] An include with a variable path  (Read 442 times)

devEric69

  • Sr. Member
  • ****
  • Posts: 465
[Solved] An include with a variable path
« on: March 03, 2021, 12:22:27 pm »
Hello,

Is it possible to use a file's inclusion directive, with a variable path like this...
Code: Pascal  [Select][+][-]
  1. {$I ./../../project_1 or project_2 or project_3/foo.inc}
... where project_1, or project_2, or project_3 being a variable inside the path itself, depending on the name of the current project?
« Last Edit: March 03, 2021, 03:52:19 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

PascalDragon

  • Hero Member
  • *****
  • Posts: 2981
  • Compiler Developer
Re: An include with a variable path
« Reply #1 on: March 03, 2021, 01:12:55 pm »
No, that's not possible.

What you could work with are the include file search paths passed in through -FiXXX if you use only the filenames.

Kays

  • Sr. Member
  • ****
  • Posts: 299
  • Whasup!?
    • KaiBurghardt.de
Re: An include with a variable path
« Reply #2 on: March 03, 2021, 01:20:19 pm »
[…]
Code: Pascal  [Select][+][-]
  1. {$I ./../../project_1 or project_2 or project_3/foo.inc}
... where project_1, or project_2, or project_3 being a variable inside the path itself, depending on the name of the current project?

I don’t understand why you are “going up” twice (..) when your source code files are obviously part of either project 1, 2 or 3. For what reason does ./../foo.inc not work?
Yours Sincerely
Kai Burghardt

devEric69

  • Sr. Member
  • ****
  • Posts: 465
Re: An include with a variable path
« Reply #3 on: March 03, 2021, 02:04:29 pm »
For what reason does ./../foo.inc not work?

I have a directory tree like this...:
Code: [Select]
/copyW_common/trunk
/copyW_project1/trunk
/copyW_project2/trunk
...so, I'm trying to include in a *.pas file of /copyW_common/trunk: ./../copyW_project1/trunk/foo.inc, when I'm compiling project1. Or to include ./../copyW_project2/trunk/foo.inc, when I'm compiling project2.

Maybe, it could work using $(TargetFile) in another way...
« Last Edit: March 03, 2021, 02:06:10 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

devEric69

  • Sr. Member
  • ****
  • Posts: 465
Re: An include with a variable path
« Reply #4 on: March 03, 2021, 02:22:42 pm »
I've found how to include one path or another, depending on the name of the current project, here: https://wiki.freepascal.org/Extending_the_IDE#The_executable_/_target_file_name_of_a_project.
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

devEric69

  • Sr. Member
  • ****
  • Posts: 465
Re: An include with a variable path
« Reply #5 on: March 03, 2021, 03:33:31 pm »
Well, I'm trying to create a compilation directive in and for each project, and then testing them like this, in the common code:
Code: Pascal  [Select][+][-]
  1. {$IF defined(PROJECT_1)}
  2.     {$INCLUDE ./../copyW_project1/trunk/foo.inc}
  3. {$ElseIf defined(PROJECT_2)}
  4.     {$INCLUDE ./../copyW_project2/trunk/foo.inc}
  5. {$ENDIF}

It works.
« Last Edit: March 03, 2021, 03:53:29 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

 

TinyPortal © 2005-2018