Compiler directive in IDE rather than Project files?
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 wi开发者_如何学运维th 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??
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.
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?
- Introduce an extra DEFINE in the build script (e.g. FINAL_BUILD)
- 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.
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
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.
精彩评论