Recent

Author Topic: Use different packages per build mode?  (Read 1850 times)

piola

  • Full Member
  • ***
  • Posts: 157
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Use different packages per build mode?
« on: March 02, 2025, 12:04:04 pm »
Hello,

is it possible to have different build modes use a different set of required packages?

Background: I'd like to use build modes for including or excluding features, and some packages are only necessary if a particular feature is included.

Zoran

  • Hero Member
  • *****
  • Posts: 1980
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Use different packages per build mode?
« Reply #1 on: March 02, 2025, 04:23:26 pm »
As far as I know, Lazarus build modes system does not provide a way to include a package in a project depending on build mode.

It would be a useful feature.
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

cdbc

  • Hero Member
  • *****
  • Posts: 2604
    • http://www.cdbc.dk
Re: Use different packages per build mode?
« Reply #2 on: March 02, 2025, 05:30:15 pm »
Hi
I'd say, it smells more like a plugin-framework is needed...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12098
  • Debugger - SynEdit - and more
    • wiki
Re: Use different packages per build mode?
« Reply #3 on: March 02, 2025, 05:44:25 pm »
Best I can think off is to have defines ( -dSomeDefine _ set per buildmode, and then $IFDEF the units in the uses clause.

The package may be included and build, but if no units are used, then it wont be in the resulting exe. (you just loose some time, if some of the unused units are rebuild).

It be more complex, if want to choose between 2 packages that provide the same units. So your project always "uses UnitFoo", but that could be of one or the other package. If you add neither package, you can set the include path for the ppu and o files per buildmode. But you then have to always manually rebuild the units.
Or you need to find a way to hide the path from the IDE, so you can add both packages, but none of their ppu would be found, until you manually add that path to the buildmode.

Whatever you do, I would advice against including the path to the source /pas files per buildmode => then you get ppu files in the project, rather than the package. And if you change stuff, it will generate chaos. (People have tried that often enough, and regularly lost the battle)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12098
  • Debugger - SynEdit - and more
    • wiki
Re: Use different packages per build mode?
« Reply #4 on: March 02, 2025, 05:47:03 pm »
Other than adding "custom option" per build mode, or using "Additions and Overrides" to specify per buildmode settings, you can look at https://wiki.freepascal.org/Macros_and_Conditionals

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: Use different packages per build mode?
« Reply #5 on: March 02, 2025, 06:21:10 pm »
{$ifopt D+} is usually used for that. It recognizes debug mode vs release mode. I am surprised it is not mentioned yet.
Although the documentation lacks a bit: https://www.freepascal.org/docs-html/current/prog/progsu33.html#x40-390001.2.33
The documentation reflects a less used option.
D+/- is one of the supported options.
« Last Edit: March 02, 2025, 06:32:15 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

Zoran

  • Hero Member
  • *****
  • Posts: 1980
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Use different packages per build mode?
« Reply #6 on: March 02, 2025, 06:46:28 pm »
{$ifopt D+} is usually used for that. It recognizes debug mode vs release mode. I am surprised it is not mentioned yet.
Although the documentation lacks a bit: https://www.freepascal.org/docs-html/current/prog/progsu33.html#x40-390001.2.33
The documentation reflects a less used option.
D+/- is one of the supported options.

Thaddy, if not the whole discussion, did you try to read at least the first post? ::)
It's nothing else but a variant of conditional compilation -- to be used in Pascal code. It cannot be used in Lazarus project options to conditionally include a Lazarus package.
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: Use different packages per build mode?
« Reply #7 on: March 02, 2025, 07:48:53 pm »
Of course it can, but Lazarus simply lacks explicit support. That is not the fault of the compiler options, Zoran.... These are in place.
In Lazarus you can configure it through custom.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

zamtmn

  • Hero Member
  • *****
  • Posts: 679
Re: Use different packages per build mode?
« Reply #8 on: March 02, 2025, 07:54:39 pm »
Unfortunately project dependencies cannot be configured depending on the platform, build mode, and the like... This is really missing. For now, you can only use different project files in different situations, but this is inconvenient((

Zoran

  • Hero Member
  • *****
  • Posts: 1980
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Use different packages per build mode?
« Reply #9 on: March 02, 2025, 11:14:28 pm »
Of course it can

How?

, but Lazarus simply lacks explicit support. That is not the fault of the compiler options, Zoran.... These are in place.

The compiler knows nothing about Lazarus packages, so we can hardly expect a compiler option for them.

In Lazarus you can configure it through custom.

I can't.
Would you please tell us where exactly and how do you include/exclude Lazarus packages in build mode options?
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Zoran

  • Hero Member
  • *****
  • Posts: 1980
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Use different packages per build mode?
« Reply #10 on: March 02, 2025, 11:17:51 pm »
Unfortunately project dependencies cannot be configured depending on the platform, build mode, and the like... This is really missing. For now, you can only use different project files in different situations, but this is inconvenient((

Thaddy claims they can. Let's wait for his answer.  ::)
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

piola

  • Full Member
  • ***
  • Posts: 157
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Re: Use different packages per build mode?
« Reply #11 on: March 03, 2025, 04:36:16 pm »
Thank you all -- wasn't my intention to start a debate on principles :D

@cdbc: Actually, the app currently is a plugin system, but I'd like to create builds with common plugins already included.

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: Use different packages per build mode?
« Reply #12 on: March 03, 2025, 07:03:03 pm »
Unfortunately project dependencies cannot be configured depending on the platform, build mode, and the like... This is really missing. For now, you can only use different project files in different situations, but this is inconvenient((

Thaddy claims they can. Let's wait for his answer.  ::)
Of course they can be configured by simply adapting fpc.cfg.
That is even documented - in the skeleton fpc.cfg..... But you can also do that and use that from Lazarus, which ultimately relies on.... You guessed it... fpc.cfg.
Pretending otherwise is a fallacy.
If such seasoned programmers like you two even overlooked that and got stuck in Lazarus only environment that is a sorry thing to watch.
« Last Edit: March 03, 2025, 07:05:23 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

zamtmn

  • Hero Member
  • *****
  • Posts: 679
Re: Use different packages per build mode?
« Reply #13 on: March 03, 2025, 07:45:25 pm »
Thaddy
You are wrong. Of course, you can customize everything (including in fpc.cfg) and say look - it works)). But why would you do that?
The whole point of packages is to easily connect the necessary functionality to the project.
For example package https://github.com/zamtmn/metadarkstyle - implementation of dark theme by means of winapi.
This package makes sense only when compiling under win32... and if dependence on other platforms in the application code can be easily removed by means of conditional compilation, the project dependence on this package cannot be removed in any way.... I had to make this package look empty under targets other than windows

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: Use different packages per build mode?
« Reply #14 on: March 04, 2025, 09:57:12 am »
no, because it is the responsability of the programmer to provide debug and release packages. si.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

 

TinyPortal © 2005-2018