* * *

Author Topic: Can dependencies be based on conditional defines? If not, how about platform?  (Read 1675 times)

hayanninja

  • New member
  • *
  • Posts: 45
Basically - my program uses Graphics32 on Windows and Mac. However, Graphics32 won't compile properly on Linux, so on Linux it's using BgraBitmap instead.

This means - firstly, BgraBitmapPack is not a needed dependency on Windows or Mac. Having it included doesn't hurt as such, but it doesn't need to be there.
More importantly, this means that on Linux, Graphics32 (which won't compile on Linux) will be listed as a dependency.

Is there any way I can set it, ideally, so that it will consider Graphics32 a dependancy only if the define GFX_GRAPHICS32 is present, and likewise, BgraBitmapPack only if GFX_BGRABITMAP is present? If not, can it at least be set so Graphics32 will be treated as a dependency on Windows and Mac, while BgraBitmap will on Linux?

(Edit: I should clarify, the GFX_GRAPHICS32 / GFX_BGRABITMAP defines are set by an include file, not the project information.)

I don't want to switch to just using BgraBitmap on all platforms as it's considerably slower. (Based on some relatively simple profiling code using GetTickCount64; BgraBitmap averages 60 ticks per frame on my Windows machine, while Graphics32 records most frames as zero ticks, occasionally it will record one as 16 or so ticks. The difference is also noticable visually.)
« Last Edit: January 28, 2018, 09:10:44 am by hayanninja »

taazz

  • Hero Member
  • *****
  • Posts: 5336
I do not really understand the question but there are number of solutions.
1) use different packages for windows/macos and linux with different dependencies.(simplest)
2) if your problem is only in the uses section of the unit you can use ifdefs eg.
Code: Pascal  [Select]
  1.  
  2. uses
  3.   {$IFDEF LINUX}, GFX_BGRABITMAP {$ELSE}, GFX_GRAPHICS32{$ENDIF} ;
  4.  
or any other pair of defines you might need. for a more complicated check read up on {$IF defined}.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

GetMem

  • Hero Member
  • *****
  • Posts: 3160
Hi hayanninja,

Firstly which version of Graphics32 do you use? The one in OPM compiles fine under linux(see attached screenshots). IIRC it was ported from CT. You should give it a try.
Secondly you can add platform specific ifdefs even in uses section, something like this:
Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs
  9.   {$IFDEF Linux},BGRABitmaps{$ELSE},GR32_Image{$ENDIF};
  10.  
  11. type


PS: The second one is already answered by taazz.

Thaddy

  • Hero Member
  • *****
  • Posts: 6736
Code: Pascal  [Select]
  1. uses
  2.   {$if Defined(Windows)}graphic32{$else}BGRABitmap{$ifend}
or:
Code: Pascal  [Select]
  1. {$if defined(GFX_GRAPHICS32) and Defined(Windows)}graphics32{$else}BGRABitmap{$ifend}

in that order because BGRABitmap is not only for linux: it works on most platforms. You should test for Windows, NOT Linux.... Logic...
And BGRABitmap works also on windows so the above answer is a screw up.
« Last Edit: January 28, 2018, 09:35:09 am by Thaddy »
Ada's daddy wrote this:"Fools are my theme, let satire be my song."

hayanninja

  • New member
  • *
  • Posts: 45
Will have to try using the OPM version of Graphics32.

Regarding the uses section - yeah no problem, already got plenty of conditional defines here. What I mean is in the project's dependencies, ie: what's listed in the Project Inspector. Or is it safe to have uncompilable / missing ones there, as long as none of the project's code actually makes use of them?

Thaddy

  • Hero Member
  • *****
  • Posts: 6736
Will have to try using the OPM version of Graphics32.
That is still not crossplatform. win32/64 only, [edit] linuxX86_XX works but nothing else.
« Last Edit: January 28, 2018, 09:42:45 am by Thaddy »
Ada's daddy wrote this:"Fools are my theme, let satire be my song."

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6506
Will have to try using the OPM version of Graphics32.

Regarding the uses section - yeah no problem, already got plenty of conditional defines here. What I mean is in the project's dependencies, ie: what's listed in the Project Inspector. Or is it safe to have uncompilable / missing ones there, as long as none of the project's code actually makes use of them?

Afaik it mostly sets some extra directories, so if the packages have no conflicting units, and you don't accidentally use them, it should be fine I guess.

However the ide might not know the package on Linux, so you might need to register it there anyway, even if just empty units.

hayanninja

  • New member
  • *
  • Posts: 45
Will have to try using the OPM version of Graphics32.
That is still not crossplatform. win32/64 only, [edit] linuxX86_XX works but nothing else.

That's good enough for me for now. I can use either version for Windows, the normal version for Mac, and the OPM version for Linux. I want to also eventually port my project to Android and possibly iOS too, but by the time I'm ready for that, I'll probably move to a full-blown everything library like SDL or something anyway. (I'm making sure to write my code so that it's as easy as possible to switch out the external libraries used for stuff like graphics, audio, etc.)

Now I just have to figure out what "OPM" even means... (EDIT: A quick Google answered that for me.)
« Last Edit: January 28, 2018, 11:02:18 am by hayanninja »

hayanninja

  • New member
  • *
  • Posts: 45
Okay, tried the OPM version. It works fine for all three versions; Mac included. :D

However - I'd like to suggest, if feasible, that GR32_Png either be integrated into it, or seperately added to the OPM. No problem for me - I can just manually add it to the package myself - but I think it'd be well worthwhile having it available easily in general.

Thaddy

  • Hero Member
  • *****
  • Posts: 6736
Why would you need it? PNG handling is already available in multiple flavors - and often better than gr_png - e.g. fcl-image.
Overview here: http://wiki.freepascal.org/Graphics_libraries

Note for now you only need just three OS versions, but what if you want more? then you are stuck. fcl-image supports all platforms, BGRA most platforms (way more than 3, including ARM).
« Last Edit: January 28, 2018, 01:02:59 pm by Thaddy »
Ada's daddy wrote this:"Fools are my theme, let satire be my song."

GetMem

  • Hero Member
  • *****
  • Posts: 3160
@hayanninja
Quote
However - I'd like to suggest, if feasible, that GR32_Png either be integrated into it, or seperately added to the OPM. No problem for me - I can just manually add it to the package myself - but I think it'd be well worthwhile having it available easily in general.
If it's a package I can add it to OPM. From where I can download GR32_Png?

Thaddy

  • Hero Member
  • *****
  • Posts: 6736
It is a separate add-on to graphics32 https://github.com/graphics32/GR32PNG
Ada's daddy wrote this:"Fools are my theme, let satire be my song."

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus