Recent

Author Topic: Required packages depending on the OS  (Read 821 times)

MaxM74

  • New Member
  • *
  • Posts: 17
Required packages depending on the OS
« on: November 04, 2024, 12:36:17 pm »
I am developing a cross platform Windows/Linux desktop application.

When the application is compiled for Windows it will use some specific packages, when it is compiled for Linux it will use others.

The question is...is there a way to  {$ifdef} required packages depending on the OS ?.

cdbc

  • Hero Member
  • *****
  • Posts: 1673
    • http://www.cdbc.dk
Re: Required packages depending on the OS
« Reply #1 on: November 04, 2024, 01:24:17 pm »
Hi
Code: Pascal  [Select][+][-]
  1. {$ifdef unix}
  2.   unix-dependencies
  3. {$else}
  4.   windows-dependencies
  5. {$endif}
Should roughly do it, as Mac belongs under unix...
Regards Benny
« Last Edit: November 04, 2024, 01:25:52 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

PascalDragon

  • Hero Member
  • *****
  • Posts: 5759
  • Compiler Developer
Re: Required packages depending on the OS
« Reply #2 on: November 04, 2024, 09:13:07 pm »
Should roughly do it, as Mac belongs under unix...

Please note that MaxM74 is talking about packages, not units.

cdbc

  • Hero Member
  • *****
  • Posts: 1673
    • http://www.cdbc.dk
Re: Required packages depending on the OS
« Reply #3 on: November 04, 2024, 10:02:10 pm »
Hi
Ooopsss, sorry - my bad, that escaped me...  :-[
Thanks Sven
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Required packages depending on the OS
« Reply #4 on: November 04, 2024, 11:15:41 pm »
The question is...is there a way to  {$ifdef} required packages depending on the OS ?.

If you are cross compiling from one machine, then you will need to have all the required packages installed. Each compile run will (given sensible uses of Benny's instructions) will not even know about the ones it does not need.

If you are compiling on different platforms, obviously you only install packages needed for that install. Again, Benny's answer may well be that answer you are looking for.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

MaxM74

  • New Member
  • *
  • Posts: 17
Re: Required packages depending on the OS
« Reply #5 on: November 05, 2024, 10:36:56 am »
for example...my application use image acquisition from scanners.

So if you are under Windows in the project file (lpi) there is:
Code: XML  [Select][+][-]
  1. <RequiredPackages Count="7">
  2.       <Item1>
  3.         <PackageName Value="WIAPascal_pkg"/>
  4.       </Item1>
  5.       <Item2>
  6.         <PackageName Value="DelphiTwain_pkg"/>
  7.       </Item2>
  8.       <Item3>
  9.         <PackageName Value="MaxM_Commons"/>
  10.       </Item3>
  11.       <Item4>
  12.         <PackageName Value="LazControls"/>
  13.       </Item4>
  14.       <Item5>
  15.         <PackageName Value="BGRABitmapPack"/>
  16.       </Item5>
  17.       <Item6>
  18.         <PackageName Value="bgracontrols"/>
  19.       </Item6>
  20.       <Item7>
  21.         <PackageName Value="LCL"/>
  22.       </Item7>

As you can see the first 2 items are strictly platform dependent because they use Windows DLLs and ActiveX.

If in the near future i want to port the application to Linux what should i do?
I should make another lpi project file where there would be something like:
Code: XML  [Select][+][-]
  1. <RequiredPackages Count="7">
  2.       <Item1>
  3.         <PackageName Value="Sane_pkg"/>
  4.       </Item1>
  5.       ..commons Items
  6.      

My opinion is that it would be useful to add something to filter the required packages by platform and include only those of the platform being compiled.
example :
Code: XML  [Select][+][-]
  1. <RequiredPackages Count="7">
  2.       <Item1 platform="linux">
  3.         <PackageName Value="Sane_pkg"/>
  4.       </Item1>
  5.       <Item2  platform="windows">
  6.         <PackageName Value="WIAPascal_pkg"/>
  7.       </Item2>
  8.        <Item3>
  9.         <PackageName Value="LCL"/>
  10.       </Item3>
  11.      

korba812

  • Sr. Member
  • ****
  • Posts: 442
Re: Required packages depending on the OS
« Reply #6 on: November 05, 2024, 12:00:42 pm »
I also encountered this problem. I solved it by using two lpi files (one for windows the other for unix) and a shared lpr and units/forms files between them. This is not a perfect solution (you have to remember to make changes to both project files, e.g. resources or new units) however it works.

MaxM74

  • New Member
  • *
  • Posts: 17
Re: Required packages depending on the OS
« Reply #7 on: November 05, 2024, 01:45:10 pm »
I also encountered this problem. I solved it by using two lpi files (one for windows the other for unix) and a shared lpr and units/forms files between them. This is not a perfect solution (you have to remember to make changes to both project files, e.g. resources or new units) however it works.

my idea could be a good feature to add to the IDE

korba812

  • Sr. Member
  • ****
  • Posts: 442
Re: Required packages depending on the OS
« Reply #8 on: November 05, 2024, 03:17:49 pm »
Well, sure. But before you start implementing it, consider whether it's better to make use of a particular package dependent on the build mode instead of the platform.

 

TinyPortal © 2005-2018