Difference between revisions of "Show Application Title, Version, and Company"
(Attempt at initial version.) |
(corrected fcl-res being in fpc trunk; layout) |
||
Line 1: | Line 1: | ||
''This article is a placeholder containing links to code, some of which might be obsolete as of late 2013 (Lazarus 1.0, FPC 2.6.2).'' | ''This article is a placeholder containing links to code, some of which might be obsolete as of late 2013 (Lazarus 1.0, FPC 2.6.2).'' | ||
+ | == Overview == | ||
From its earliest versions, Microsoft Windows had the capability of storing version information etc. in an executable file. Support for that was added to Delphi around v3, and was part-functional in Lazarus 0.9.24. | From its earliest versions, Microsoft Windows had the capability of storing version information etc. in an executable file. Support for that was added to Delphi around v3, and was part-functional in Lazarus 0.9.24. | ||
There is no implicit provision in the ELF file format for version numbers, copyright and so on, but Lazarus stores this in resource sections. Reading the information back at runtime relies on FPC units, below are some pointers that might be useful. | There is no implicit provision in the ELF file format for version numbers, copyright and so on, but Lazarus stores this in resource sections. Reading the information back at runtime relies on FPC units, below are some pointers that might be useful. | ||
− | + | === Implementations using FPC 2.6.x === | |
+ | Contribution via the mailing list: [http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100723/8db6b97e/attachment.ksh] | ||
Use this like | Use this like | ||
− | + | <syntaxhighlight> | |
FUNCTION resourceVersionInfo: STRING; | FUNCTION resourceVersionInfo: STRING; | ||
Line 45: | Line 47: | ||
END | END | ||
END { resourceVersionInfo } ; | END { resourceVersionInfo } ; | ||
+ | </syntaxhighlight> | ||
− | |||
Using vinfo: [http://forum.lazarus.freepascal.org/index.php?topic=12435.0] and [http://forum.lazarus.freepascal.org/index.php?topic=13957.0] | Using vinfo: [http://forum.lazarus.freepascal.org/index.php?topic=12435.0] and [http://forum.lazarus.freepascal.org/index.php?topic=13957.0] | ||
− | On an Apple | + | On an Apple OSX machine: [[Mac Show Application Title, Version, and Company]] |
+ | |||
+ | === FPC 2.7.1/trunk === | ||
+ | Implementation in FPC 2.7.1 using [[fcl-res]]: [http://wiki.lazarus.freepascal.org/User_Changes_Trunk#TVersionInfo_.28fileinfo_unit.29_re-implemented_in_a_platform_independent_way] | ||
+ | |||
− | = Unix-only hacks = | + | == Unix-only hacks == |
These work with Linux on various platforms, and probably with Solaris provided that the GNU-derived utilities are installed. | These work with Linux on various platforms, and probably with Solaris provided that the GNU-derived utilities are installed. | ||
− | == Getting Subversion revision information as a program-accessible string == | + | === Getting Subversion revision information as a program-accessible string === |
Put this into Project options -> Compilation -> Execute before -> Command: | Put this into Project options -> Compilation -> Execute before -> Command: | ||
Line 65: | Line 71: | ||
Put this into the program: | Put this into the program: | ||
− | + | <syntaxhighlight> | |
(*$IFDEF UNIX *) | (*$IFDEF UNIX *) | ||
rev= (*$I project_svnrevision.inc *) ; | rev= (*$I project_svnrevision.inc *) ; | ||
Line 71: | Line 77: | ||
rev= 'unimplemented'; | rev= 'unimplemented'; | ||
(*$ENDIF *) | (*$ENDIF *) | ||
+ | </syntaxhighlight> | ||
Note that that has to be a string, since the revision number will have a non-numeric suffix if the project has been updated since it was last committed. | Note that that has to be a string, since the revision number will have a non-numeric suffix if the project has been updated since it was last committed. | ||
− | == Renaming the final executable to include platform and timestamp == | + | === Renaming the final executable to include platform and timestamp === |
Put this into Project options -> Paths -> Unit output directory: | Put this into Project options -> Paths -> Unit output directory: | ||
Line 87: | Line 94: | ||
Put this into Project options -> Compilation -> Execute after -> Command: | Put this into Project options -> Compilation -> Execute after -> Command: | ||
− | + | <syntaxhighlight lang="bash"> | |
/bin/sh -c "mv libunyokedbackend-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType).so UnyokedBackend-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType).`date +%F.%R`.so" | /bin/sh -c "mv libunyokedbackend-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType).so UnyokedBackend-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType).`date +%F.%R`.so" | ||
− | + | </syntaxhighlight> | |
That should be a single line. Note quote and backtick positions. | That should be a single line. Note quote and backtick positions. | ||
[[Category:Mac OS X]] | [[Category:Mac OS X]] | ||
+ | [[Category:Linux]] | ||
+ | [[Category:Windows]] | ||
+ | [[Category:Lazarus]] | ||
+ | [[Category:FPC]] | ||
+ | [[Category:Code]] |
Revision as of 12:50, 26 December 2013
This article is a placeholder containing links to code, some of which might be obsolete as of late 2013 (Lazarus 1.0, FPC 2.6.2).
Overview
From its earliest versions, Microsoft Windows had the capability of storing version information etc. in an executable file. Support for that was added to Delphi around v3, and was part-functional in Lazarus 0.9.24.
There is no implicit provision in the ELF file format for version numbers, copyright and so on, but Lazarus stores this in resource sections. Reading the information back at runtime relies on FPC units, below are some pointers that might be useful.
Implementations using FPC 2.6.x
Contribution via the mailing list: [1]
Use this like
FUNCTION resourceVersionInfo: STRING;
(* Unlike most of AboutText (below), this takes significant activity at run- *)
(* time to extract version/release/build numbers from resource information *)
(* appended to the binary. *)
VAR Stream: TResourceStream;
vr: TVersionResource;
fi: TVersionFixedInfo;
BEGIN
RESULT:= '';
TRY
(* This raises an exception if version info has not been incorporated into the *)
(* binary (Lazarus Project -> Project Options -> Version Info -> Version *)
(* numbering). *)
Stream:= TResourceStream.CreateFromID(HINSTANCE, 1, PChar(RT_VERSION));
TRY
vr:= TVersionResource.Create;
TRY
vr.SetCustomRawDataStream(Stream);
fi:= vr.FixedInfo;
RESULT := 'Version ' + IntToStr(fi.FileVersion[0]) + '.' + IntToStr(fi.FileVersion[1]) +
' release ' + IntToStr(fi.FileVersion[2]) + ' build ' + IntToStr(fi.FileVersion[3]) + eol;
vr.SetCustomRawDataStream(nil)
FINALLY
vr.Free
END
FINALLY
Stream.Free
END
EXCEPT
END
END { resourceVersionInfo } ;
On an Apple OSX machine: Mac Show Application Title, Version, and Company
FPC 2.7.1/trunk
Implementation in FPC 2.7.1 using fcl-res: [4]
Unix-only hacks
These work with Linux on various platforms, and probably with Solaris provided that the GNU-derived utilities are installed.
Getting Subversion revision information as a program-accessible string
Put this into Project options -> Compilation -> Execute before -> Command:
/bin/sh -c "echo -n C`svnversion -n`C |tr A-G %-+ >project_svnrevision.inc"
Note quote and backtick positions. The tr is converting C into another layer of quotes which is necessary for things to work as required.
Put this into the program:
(*$IFDEF UNIX *)
rev= (*$I project_svnrevision.inc *) ;
(*$ELSE *)
rev= 'unimplemented';
(*$ENDIF *)
Note that that has to be a string, since the revision number will have a non-numeric suffix if the project has been updated since it was last committed.
Renaming the final executable to include platform and timestamp
Put this into Project options -> Paths -> Unit output directory:
lib/$(TargetCPU)-$(TargetOS)
Put this into Project options -> Paths -> Target file name:
UnyokedBackend-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType)
Make sure that "Apply conventions" is ticked (checked). This might vary slightly according to IDE and compiler/linker versions.
Put this into Project options -> Compilation -> Execute after -> Command:
/bin/sh -c "mv libunyokedbackend-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType).so UnyokedBackend-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType).`date +%F.%R`.so"
That should be a single line. Note quote and backtick positions.