FPC 2.6.1 macOS Targets

From Free Pascal wiki
Jump to navigationJump to search

English (en)

FPC 2.6.1 and below

To make sure that an application will run under previous macOS releases, use the -macosx_version_min linker parameter and link against the appropriate SDK (e.g. -XR/Developer/SDKs/MacOSX10.5.sdk/ or -XR/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/). For example, to compile an application that should work on Leopard 10.5 and higher:

Add to /etc/fpc.cfg OR to Project / Compiler options / Other / Custom options:

-k-macosx_version_min -k10.5
-XR/Developer/SDKs/MacOSX10.5.sdk/

The 10.4 SDK is the only one with a special name (10.4u instead of 10.4). Other SDK names simply contain the major macOS version number: MacOSX10.5.sdk, MacOSX10.6.sdk, ...

Note: The path /Developer depends on where you installed the Apple developer tools, and may be different if you chose a different location. Do not assume it will always be /Developer.

The 10.7 is by default:

-k-macosx_version_min -k10.7
-XR/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/

For targeting Tiger 10.4 the following settings are required:

-k-macosx_version_min -k10.4
-XR/Developer/SDKs/MacOSX10.4u.sdk/

Adding the custom options only when compiling for macOS

To add the above custom options only when compiling for macOS add to Project / Compiler options / IDE macros / Conditionals:

if TargetOS = 'darwin' then begin
  UsageCustomOptions += ' -k-macosx_version_min -k10.5';
  UsageCustomOptions += ' -XR/Developer/SDKs/MacOSX10.5.sdk/';
end;