ProjectXC currently includes several templates for creating Xcode projects:
Install version 3.0.0 or later.
Run it with without any parameters:
./makeproj osx-simple ~/MyXcodeProjects/test1
Change ~/MyXcodeProjects to point to an existing folder where you want the test1 project folder to be created.
Now open test1.xcodeproj in Xcode and choose Product | Run to compile and run it.
Tip: Lazarus also uses this to name your app's .app bundle. In general, the target name should be in mixed-case, NOT lower-case.
Note: Unfortunately, Lazarus itself does not understand messages in this standard format, so you'll probably want to remove this switch when you're compiling your project in Lazarus.
./makeproj osx-laz ~/MyXcodeProjects/test2 ~/MyLazProjects/test2/test2.lpi
Now open test2.xcodeproj in Xcode and review what's been added:
Like most IDEs, Xcode runs a series of command line tools when it builds a project. The osx-laz template includes a build script that runs the Lazarus lazbuild console app to do the actual compiling of your Lazarus project. If the Free Pascal compiler that lazbuild runs detects a syntax error in your code, Xcode will jump to the line where the error occurred, assuming you added the -vbr switch to your Lazarus project as described above.
The rest of the build process is standard Xcode, for example creating the .app bundle (under ~/Library/Developer/Xcode/DerivedData) and signing the app (with codesign).
ProjectXC was tested with Xcode 8.2.1, Lazarus 1.8.0 RC1 and Free Pascal 3.0.2 on El Capitan (OS X 10.11).
Except for edits that you might make to your Pascal source files or Info.plist file, Xcode won't make changes to your Lazarus project files.
Yes, you can set breakpoints the same way you would in any Xcode project. For more information, see this link.
Lazarus build modes correspond roughly to Xcode schemes. For example, if you have a Debug build mode and a Release build mode in your Lazarus project, you can try this:
Now when you select the Debug scheme and build your Xcode project, it will run lazbuild with the Debug build mode. When you select the Release scheme and build your Xcode project, it will run lazbuild with the Release build mode.
Yes, specify the widgetset to use in the LAZBUILD_OPTIONS setting. For example, to build your Lazarus project with the Cocoa widgetset, enter this:
To build a 64-bit Cocoa app, add these switches as well to LAZBUILD_OPTIONS:
You can also use a different lazbuild than the one installed with Lazarus. Just change the LAZBUILD_PATH setting. If you have more than one installation of Lazarus, you can also specify a different configuration path to use in the LAZBUILD_OPTIONS, for example:
Yes, enable signing on the General tab the same as any Xcode project.
Yes, use xcodebuild the same as with any Xcode project.
Yes, in general you should be able to do that.
Note that when you save edits in Lazarus, Xcode will immediately update the code in its editor. Lazarus isn't quite that smart, but it will prompt you to reload the modified file when you save edits in Xcode.
No, if you want that, create a project with the Objective Pascal template above. You won't use Lazarus at all in that case. You can use non-UI units from a Lazarus project, but none of its form design files or form code units.
This is caused by Lazarus not setting the Info.plist's CFBundleName correctly.
Example 1: You have a Lazarus project myapp.lpi whose target file name is "My App" and you create the Xcode project like this:
./makeproj osx-laz "~/MyXcodeProjects/My App" ~/MyLazProjects/myapp/myapp.lpi
Both Lazarus and Xcode will use the correct mixed-case name for the .app bundle and executable file, but the app menu will be lower-case. To fix, edit the Bundle name in Xcode's Info panel.
Example 2: You used the same name for the Xcode project as the Lazarus project:
./makeproj osx-laz ~/MyXcodeProjects/myapp ~/MyLazProjects/myapp/myapp.lpi
By default Xcode will use the project name for the .app bundle and executable file, so in addition to the fix in example 1, change the Xcode project's target from "myapp" to "My App".
Your Lazarus project won't be affected.
Note that if you added files to the Xcode project (not just references) or enabled things that only Xcode can do (for example, copy files to the .app bundle's Resources folder when building the app), you will lose these changes.
Yes, the Xcode project uses absolute paths to the Lazarus project's files.
Yes, but with consequences. The Xcode project uses absolute paths to the Lazarus project's files. You will lose the ability to view and edit the Info.plist and Pascal source files in Xcode, although you can still build once you've updated the LAZ_PROJECT_DIR setting in Xcode's Build settings.
If possible, delete the Xcode project (see question above), move the Lazarus project, then create the Xcode project again.
macpgmr (at) icloud (dot) com
First posted Oct. 25, 2015; last edited June 29, 2017.