I'm trying to know if the project is a library or not, after read the help I wrote this code that does not work:
{$IF DEFINED(LIBPREFIX)}
{$DEFINE PROJECT_IS_EXECUTABLE}
{$UNDEF PROJECT_IS_LIBRARY}
{$ELSE}
{$DEFINE PROJECT_IS_EXECUTABLE}
{$UNDEF PROJECT_IS_LIBRARY}
{$IFEND}
I tried DEFINED, DECLARED and
{$IF (LIBPREFIX = '')}
Every try always returns the same for DLLs and for programs. How can I do this using only built-in compiler directives?
EDIT
My intention is to remove the extra information from "PE File".
I do it directly in .dpr project file, so no matter how the other units were compiled, but I can not do the same in DLL projects.
Therefore I was looking a way to block it in DLL projects.
This is how I solved this issue, I add this directives to my .dpr programs:
{$DEFINE STRIPE_PE_INFO}
{$DEFINE STRIPE_RTTI}
{$I DDC_STRIP.inc}
And DDC_STRIP.inc has all the logic.
There's no way to know this when your file is being compiled. A source file can be compiled to a .dcu and then linked into any type of project. A good example are the RTL and VCL units.
Probably the best you can do is to define a conditional in your project options that indicates whether or not the project is a library. But you need to make sure that the .dcu is always re-compiled when you build any project that uses this unit.
You can't determine this at compile time, but at runtime, you can check the SysInit.ModuleIsLib
(Delphi 2007) to determine if the code is running in a library (or package).
Best thing I can think of is to set a define in an include file. You could use a pre-build action (bat file) to modify the include file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With