0

Delphi 7: Is it possible to put a compiler conditionals in the IDE (like Tools, Environment options) rather than in a project under Project, Options, Conditionals?

We have a compiler directive that needs to be defined when compiling on developers' machines, but undefined when we build releases.

We don't want to use IFDEF DEBUG, since occasionally we ship code with debugging on.

We don't want to use an include file, because we'd risk it getting swept up into our source code control system.

Ideally, we would be able to create a compiler directive like we can an IDE environment variable where it wouldn't be saved in our source tree.

Any suggestions??

RobertFrank
  • 7,332
  • 11
  • 53
  • 99
  • Set in in your build script. Please don't tell me you build your release builds from the IDE. – David Heffernan Jun 27 '11 at 20:59
  • Good suggestion, David. Getting access to the build script is a bit tricky given the management structure here, but that would work. I was hoping that someone would have some clever way to use the IDE. – RobertFrank Jun 27 '11 at 21:12
  • @Robert when building for release the clever thing to do is to avoid the IDE – David Heffernan Jun 27 '11 at 21:17
  • If you don't want a certain file to be in source control, you can set up a pre-checkin script that rejects any checkins that include that file. Or use a build script that always checks out a specific revision of that file to overwrite the head before compiling. – Rob Kennedy Jun 27 '11 at 22:01
  • @David: "the clever thing to do is to avoid the IDE." That's what we do now. I was hoping I could define a conditional compilation variable in my IDE environment that wouldn't be seen by the build script. I may just use (SystemDebugHook <> 0) instead... – RobertFrank Jun 28 '11 at 00:10
  • What is this compiler directive for developers' machines intended to do? Knowing the ultimate goal may lead to alternate solutions... – Marjan Venema Jun 28 '11 at 06:12
  • @robert turn it the other way round. Define an conditional that is only set in the release build. If your build is truly repeatable then I can't see the problem. – David Heffernan Jun 28 '11 at 06:25
  • See http://stackoverflow.com/questions/7642891/delphi-predefined-environment-variables. – Tom Jun 25 '15 at 11:43

4 Answers4

2

The solution is to use a build tool like FinalBuilder to do your building. This way you can be completely sure that you ship a good build every time, and not forget to set some option back to what it should be. I used to take a real day doing builds, now it is a click and I'm done.

mj2008
  • 6,647
  • 2
  • 38
  • 56
  • This is a good solution, but it doesn't answer the question asked. :) – Ken White Jun 27 '11 at 22:53
  • @Ken Sometimes the solution is not what you think it should be! 8-) The wider issue is better fixed another way, particularly the not doing your release builds in the IDE. – mj2008 Jun 28 '11 at 08:25
  • I didn't downvote. I just pointed it out. When the question is totally different, you should answer it **first** (because it's what was asked), and then propose better alternatives. – Ken White Jun 29 '11 at 10:58
1

Automating it will be hard (although your restriction on include files sounds a bit artifical, simply put the thing in source control and replace the version on disk with a different one during build script), why not force your individual developers to turn it on manually?

  1. Introduce an extra DEFINE in the build script (e.g. FINAL_BUILD)
  2. Introduce a compile time error in the source code forcing your developers to turn it on.
  {$IFNDEF FINAL_BUILD}
    {$IFNDEF VERY_SPECIAL_COMPILER_DIRECTIVE_YOU_WANT_TURNED_ON
      You should have really turned option X on. Now things don't compile.
    {$ENDIF}
  {$ENDIF}

Finally, introduce a similar compile time error to make sure the FINAL_BUILD and special directive are never turned on at the same time.

Paul-Jan
  • 16,746
  • 1
  • 63
  • 95
0

You can use Conditional defines in project options

this will pass your custom defines to compiler when begin compile of project

follow this in Delphi IDE Project > Options > Delphi Compiler > Conditional defines

Mahdi
  • 247
  • 2
  • 6
  • 1
    Ignores the question, which was specifically "Is it possible to put a compiler conditionals in the IDE (like Tools, Environment options) rather than in a project under Project, Options, Conditionals" – Erik Knowles Nov 28 '12 at 20:35
0

Of course, adding {$DEFINE MYCONDITION} in your code would add a custom directive which you could check with {$IFDEF MYCONDITION} but this you should already know. However, if you compile your project from the commandline DCC32 -D MYCONDITION ... then you can compile it with (or without) that option.

Wim ten Brink
  • 25,901
  • 20
  • 83
  • 149