Forum > Editor

Can dependencies be based on conditional defines? If not, how about platform?

(1/3) > >>

hayanninja:
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.)

taazz:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- uses  {$IFDEF LINUX}, GFX_BGRABITMAP {$ELSE}, GFX_GRAPHICS32{$ENDIF} ; or any other pair of defines you might need. for a more complicated check read up on {$IF defined}.

balazsszekely:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs  {$IFDEF Linux},BGRABitmaps{$ELSE},GR32_Image{$ENDIF}; type

PS: The second one is already answered by taazz.

Thaddy:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses  {$if Defined(Windows)}graphic32{$else}BGRABitmap{$ifend}or:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$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.

hayanninja:
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?

Navigation

[0] Message Index

[#] Next page

Go to full version