Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell at compile time whether the project is a program or a library?

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.

like image 308
Cesar Romero Avatar asked Oct 28 '12 19:10

Cesar Romero


3 Answers

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.

like image 91
David Heffernan Avatar answered Oct 18 '22 23:10

David Heffernan


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).

like image 26
HeartWare Avatar answered Oct 18 '22 22:10

HeartWare


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.

like image 1
Remko Avatar answered Oct 18 '22 21:10

Remko