Can I undefine a conditional in the command line?
Asked Answered
T

2

6

In the help of Delphi 7 command line compiler, I just see an option to define a conditional compiling directive:

-D<syms> = Define conditionals

Is it possible to undefine a conditional?

I have defined DEVELOPMENT in the IDE, and want to have define just PRODUCTION in the command line compiler. The problem is that the command line compiler keeps the IDE definitions. I'd like just to undef it as is possible in the C world.

Twoup answered 22/11, 2011 at 22:53 Comment(3)
Could you give some more details of how you are specifying options for dcc32? Are you setting them at the command line? In a project.cfg file? In a global dcc32.cfg file?Durand
Maybe you can just replace all {$IFDEF DEVELOPMENT} directives with {$IFNDEF PRODUCTION} and so on. Depends on if DEVELOPMENT and PRODUCTION are mutually exclusive.Candescent
@UlrichGerhardt I've simplified the problem. I also have a HOMOLOGATION. I want to avoid nested ifdefs.Twoup
S
4

If you don't come up with a command line option, you can always add additional conditionals in your units or include file like this:

{$DEFINE FOO}

// Allow us to undefine foo at the command line by defining UNDEFFOO
{$IFDEF UNDEFFOO}
  {$UNDEF FOO}
{$ENDIF}

{$IFDEF FOO}
  ...
{$ENDIF}

Then use -D to set UNDEFFOO.

Shan answered 23/11, 2011 at 2:23 Comment(1)
Nice hack. I've put in my project file: {$IFDEF PRODUCTION}{$UNDEF DEVELOPMENT}{$ENDIF}.Twoup
D
3

You can use {$UNDEF NAME} to undefine a symbol, equivalent to #undef in C and C++. The facility to undefine a conditional is only applicable at a unit level and cannot be applied project wide. In other words you cannot unset conditionals at the command line. This is no different from the facilities offered by C or C++ toolsets.

A very common approach is to locate all your conditional definitions in a shared .inc file which is then included at the head of every source file that relies on those definitions. If you arrange things this way then you have all the flexibility that you need.

I know it will be of little consolation, but more recent Delphi versions have much stronger support for configuration management. Modern Delphi versions make use of the msbuild system. They allow the same configuration options to be used in the IDE and on the command line. There is flexibility to define, for example, debug and release build options and switch between them easily. I know I find it a great reassurance to know, for sure, that I am using the same build in the IDE as on the command line. I did not feel anywhere near so secure in legacy Delphi versions.

Durand answered 22/11, 2011 at 23:7 Comment(2)
David, I'm not sure how this answers the question about how to undefine a symbol defined in the IDE's project configuration when you're using the command line compiler (DCC32). Not downvoting, because I may be missing something here. ??Fourierism
@ken Second sentence meant to imply that that cannot be done.Durand

© 2022 - 2024 — McMap. All rights reserved.