Using Cocoa from Trunk

Here's a fairly painless list of steps for using the 64-bit Cocoa widgetset from the Lazarus "trunk" (latest source code). This won't affect your existing Lazarus installation.

Most of these steps are done at the command line in a Terminal window, so start by running the Terminal app in /Applications/Utilities. Note that you can copy and paste any of the commands given below into the Terminal window to avoid typing them yourself.

  1. Check out code from trunk

    Create a folder somewhere and check out the code. For example:

    mkdir laz-svn
    cd laz-svn
    svn checkout .
    This may take a while, but it's just source code. Nothing is being installed.

  2. Build Lazarus IDE with 64-bit Cocoa widgetset

    make LCL_PLATFORM=cocoa CPU_TARGET=x86_64
  3. Run Lazarus Cocoa IDE to create alternate config folder

    open --args "--pcp=~/.laz-svn"
    You can substitute a different name for the config folder path ("pcp"). Don't use ~/.lazarus since that's the default for your existing Lazarus installation. The leading period (.) means the folder will be hidden -- omit the period if you don't want your config folder to be hidden, for example so you can easily delete it later.

    Note: Since the Cocoa widgetset is incomplete, the Lazarus IDE built with Cocoa isn't complete either. It should start okay and you can play around with it to see what's working and what's not, but you might just want to exit at this point. You only need to run it once to create the config folder.

  4. Compile the TWebBrowser control for 64-bit Cocoa

    First download and unzip the source:

    Now change to where you unzipped the source and compile it with the Lazarus lazbuild command. The lazbuild command was built when the Cocoa IDE was built, so substitute the path to your own checkout folder. Also make sure that the --pcp switch points to your config folder created above when you ran the Cocoa IDE.

    ~/laz-svn/lazbuild --pcp=~/.laz-svn --ws=cocoa --compiler=/usr/local/bin/ppcx64 --cpu=x86_64 webbrowserpackage.lpk
  5. Install the TWebBrowser control in your existing Lazarus

    Even though only Cocoa support is implemented currently in TWebBrowser, you can still install and use the control for designing a form in Lazarus on any platform, including the 32-bit Carbon IDE.

    This will add TWebBrowser to the Common Controls palette.

  6. Create a test app in your existing Lazarus

    Create a new project in Lazarus and add a TWebControl to the form. Then call the control's LoadPage method, passing in the URL of a site to load. For example:

    procedure TForm1.Button1Click(Sender: TObject);
    Compile and run the app. You won't see anything in the control's area of the form since only Cocoa is currently supported -- this is normal.

  7. Compile the 64-bit Cocoa app

    Now compile the app for 64-bit Cocoa from the command line. For example:

    ~/laz-svn/lazbuild --pcp=~/.laz-svn --ws=cocoa --compiler=/usr/local/bin/ppcx64 --cpu=x86_64 project1.lpi
    Again, substitute your own path to lazbuild and your own config folder. And if you used a different name for your project info file, substitute for project1.lpi too.

  8. Run the 64-bit Cocoa app in the lldb debugger

    Once you've quit the app, exit the debugger:

    You can also run the app by double-clicking it in Finder.

Copyright 2017 by Phil Hess.

macpgmr (at) icloud (dot) com

First posted July 5, 2017.