AngusJohnson / Image32

An extensive 2D graphics library written in Delphi Pascal
Boost Software License 1.0
140 stars 31 forks source link

Issues when building Mac Os 64 Bit #46

Closed gdacunto closed 8 months ago

gdacunto commented 9 months ago

Hi! We are using the SVG Icon Image List library which at its core uses the Image32 library from this repository. We noticed that simply inserting a tsvgiconimage into an empty FMX project, using the default engine, builds for Windows but not for Mac. This happens using version 4.1.2 of SVGIconImageList but not with 3.9.6 Version 4.1.2 includes Image32 version 4.4 (2023/12/17) while version 3.9.6 includes version 4.4 (2023/01/30). The odd thing, which also happens on Windows, seems to be related to the FireMonkeyVersion define which is not read correctly and causes the Mac build to fail when the Img32 unit (Angus Johnson) tries to include Vcl.* units instead of FMX units as expected.

AngusJohnson commented 8 months ago

Thanks for the helpful feedback. Unfortunately I don't have any Apple Inc products to test so I'm relying on Mac users such as yourself to help with debugging there.

The odd thing, which also happens on Windows, seems to be related to the FireMonkeyVersion define which is not read correctly and causes the Mac build to fail when the Img32 unit (Angus Johnson) tries to include Vcl.* units instead of FMX units as expected.

It would really help if you could explain exactly where this incorrect define is located. Cheers,

gdacunto commented 8 months ago

Yes, of course. When building with Delphi 12 for a MacOS64 bit platform the error is detected in the unit Img32.pas as in the screenshot. The unit would use the Vcl. instead of FMX. units. The difference between last version and the 4.4 (2023/01/30) used in the SVG Icon Image List library are the defines on top of the Img32.inc. In my opinion both Windows and MacOS platforms should use the FMX.* units.

Thanks. Screenshot 2024-02-19 070329

AngusJohnson commented 8 months ago

OK. Do the following modifications in Img32.inc solve this?

{$IF DEFINED MACOS}
  {$DEFINE USING_FMX}
{$ELSEIF DEFINED(FPC)}
  {$DEFINE USING_LCL}
{$ELSEIF declared(FireMonkeyVersion)}
  {$DEFINE USING_FMX}
{$ELSE}
  {$DEFINE USING_VCL}
{$IFEND}
gdacunto commented 8 months ago

Hi! These modifications makes the MacOs 64bit builds successfully but the issue with Windows is still there. Despite the fact that the Windows build goes well, it still uses the Vcl.* units. Seems that the "Declared(FireMonkeyVersion)" works only in units where FMX.Types is used.

AngusJohnson commented 8 months ago

Seems that the "Declared(FireMonkeyVersion)" works only in units where FMX.Types is used.

Img32.FMX replaces the Img32.Fmt.BMP, Img32.Fmt.JPG, Img32.Fmt.PNG & Img32.Fmt.GIF units that are used in VCL dependant applications.

IOW, img32.FMX.pas replaces several Img32.Fmt.XXX units that are VCL dependant (Img32.Fmt.JPG, Img32.Fmt.PNG & Img32.Fmt.GIF), so you shouldn't (ie can't) use them when using FMX.

gdacunto commented 8 months ago

I was probably not clear enough in my explanation. By the Vcl.* units that are used on Windows, I mean those that in the Img32.pas unit are imported because of USING_VCL_LCL which would seem to be active as shown in the screenshot here https://github.com/AngusJohnson/Image32/issues/46#issuecomment-1951779306 Trying to replace FireMonkeyVersion with FRAMEWORK_FMX in Img32.inc, then in Img32.pas on windows platform the step with USING_VCL_LCL is correctly skipped .

{$IFDEF MACOS}
  {$DEFINE USING_FMX}
{$ELSEIF DEFINED(FPC)}
  {$DEFINE USING_LCL}
{$ELSEIF Defined(FRAMEWORK_FMX)}
  {$DEFINE USING_FMX}
{$ELSE}
  {$DEFINE USING_VCL}
{$IFEND}

Screenshot 2024-02-21 100416

Even comparing the 2 exe, one built with the changes suggested yesterday and the other using FRAMEWORK_FMX, the first one is larger in size than the latter. My idea could be wrong, but probably, the difference between the 2 exe could be from importing Vcl units.

AngusJohnson commented 8 months ago

By the Vcl.* units that are used on Windows, I mean those that in the Img32.pas unit are imported because of USING_VCL_LCL

If USING_VCL_LCL is still being defined and you made the changes that I suggested above to Img32.inc, then I can only presume that MACOS isn't a predefined conditional in your version of Delphi. And if it isn't, I'm not sure how else to test for MacOS compiling.

Anyhow here's a slightly modified block of code for img32.inc:

{$IF DEFINED(FPC)}
  {$DEFINE USING_LCL}
  {$DEFINE USING_VCL_LCL}
{$ELSEIF declared(FireMonkeyVersion) OR DEFINED(FRAMEWORK_FMX)}
  {$DEFINE USING_FMX}
{$ELSEIF DEFINED(MACOS)}
  {$DEFINE USING_FMX}
{$ELSE}
  {$DEFINE USING_VCL}
  {$DEFINE USING_VCL_LCL}
{$IFEND}
gdacunto commented 8 months ago

The issue that i've explained in previous reply was about Windows and not MacOs. MacOS was already solved but Windows compiled in FMX env was still getting the Vcl. units. Now with that modifcation, everything works fine on both Mac and Win compiled on FMX and they don't use the Vcl. units as expected. Maybe the {$ELSEIF DEFINED(MACOS)} can be deleted because MacOs projects should be built only on FMX. Will you release a new version with this modification and make a pull request at Ethea SVG Icon Image List library? Thanks

AngusJohnson commented 8 months ago

Now with that modifcation, everything works fine on both Mac and Win compiled on FMX and they don't use the Vcl.* units as expected.

OK, and thanks again, I appreciate your helpful feedback.

Will you release a new version with this modification and make a pull request at Ethea SVG Icon Image List library?

I'm keen to do that too, but I'm very occupied in another project that's currently taking most of my attention. But hopefully in the next week or two.

gdacunto commented 8 months ago

Perfect! Thanks for your support