Recent

Author Topic: [SOLVED] How to get architecture description in the code  (Read 378 times)

tk

  • Sr. Member
  • ****
  • Posts: 388
[SOLVED] How to get architecture description in the code
« on: April 24, 2026, 12:43:39 pm »
How do I get description of the CPU and OS the binary is compiled for?
I want to show this information in the 'About xxx' window.
I mean through a function(s), not a sequence of ifdefs.

Like:
Code: Pascal  [Select][+][-]
  1. ...
  2. var S: string;
  3. begin
  4.   S := GetOSText + ', ' + GetCPUText;
  5. // expected result on Windows/x86_64: 'Windows, x86_64'
  6. // expected result on Linux/x86_64: 'Linux, x86_64'
  7. // expected result on MAC/M: 'Darwin, aarch64'
  8. end;
  9. ...
  10.  
« Last Edit: April 24, 2026, 02:15:18 pm by tk »

Thaddy

  • Hero Member
  • *****
  • Posts: 19165
  • Glad to be alive.
Re: How to get architecture description in the code
« Reply #1 on: April 24, 2026, 01:06:51 pm »
Not.
Except something like this:
Code: Pascal  [Select][+][-]
  1. var
  2.  Identity:array[0..1023] of AnsiChar external name '__fpc_ident';
  3. begin
  4.   writeln(identity);
  5. end.
Outputs in my case (differs, this one is compiled to include the git commit hash):
Code: Text  [Select][+][-]
  1. FPC 3.3.1-20084-g600dcc82f4 [2026/04/18] for x86_64 - Win64
This gives you: compiler version, target processor and target OS.
What's wrong with Macro's??? Macro's don't usually generate code.

Lazarus may have some code, though, but I think they use the same as I do.
« Last Edit: April 24, 2026, 01:28:15 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

tk

  • Sr. Member
  • ****
  • Posts: 388
Re: How to get architecture description in the code
« Reply #2 on: April 24, 2026, 01:51:44 pm »
What's wrong with Macro's???
No problem with macros.
But I wrote about ifdefs, where I meant sth like:
Code: Pascal  [Select][+][-]
  1. const
  2. {$IF DEFINED(MSWINDOWS)}
  3.   osText = 'Windows';
  4. {$ELSEIF DEFINED(LINUX)}
  5.   osText = 'Linux';
  6. {$ELSE}
  7.   osText = 'unknown';
  8. {$ENDIF}
  9.  

Would not be nice in this case indeed.

I've found a nice solution in FPCAdds.pas in the meantime (is what Lazarus IDE uses in its own about box):
Code: Pascal  [Select][+][-]
  1. function GetCompiledTargetOS: string;
  2. begin
  3.   Result:=lowerCase({$I %FPCTARGETOS%});
  4. end;
  5.  
  6. function GetCompiledTargetCPU: string;
  7. begin
  8.   Result:=lowerCase({$I %FPCTARGETCPU%});
  9. end;
  10.  
  11.  

Thausand

  • Hero Member
  • *****
  • Posts: 536
A docile goblin always follow HERMES.md

Thaddy

  • Hero Member
  • *****
  • Posts: 19165
  • Glad to be alive.
Re: [SOLVED] How to get architecture description in the code
« Reply #4 on: April 24, 2026, 06:23:48 pm »
Those are macro's btw...
objects are fine constructs. You can even initialize them with constructors.

 

TinyPortal © 2005-2018