5.3. Creating an Xcode project from a CMakeLists.txt file

The MeVisLab macOS edition includes a helper application (named ProjectGenerator.app) that provides macOS Services for the generation of Xcode projects from CMakeLists.txt files to develop, debug, and profile MeVisLab modules.

5.3.1. How to use the Project Generator

MeVisLab must be started at least once to perform the registration of these services with macOS. Afterwards, the contextual menu of the Finder’s folder view will offer several Generate Xcode Project* menu items for a selected CMakeLists.txt file or a folder entry (Figure 5.2, “Generating Xcode projects from CMakeLists.txt files via Finder contextual menu”). The Services submenu contains the same entries and can be used wherever macOS Services can be applied.

For every selected item, the Project Generator creates one Xcode project in a newly created Build folder offering release and debug build configurations. Besides compilation, both configurations (called Schemes in Xcode) are setup to facilitate debugging and profiling of MeVisLab modules or tests. See Section 5.5, “Debugging MeVisLab modules using Xcode” or Section 5.6, “Profiling MeVisLab modules using Instruments” for details.

Figure 5.2. Generating Xcode projects from CMakeLists.txt files via Finder contextual menu

Generating Xcode projects from CMakeLists.txt files via Finder contextual menu

Occasionally, you may want to inspect diagnostic messages from the CMake-based project generation process, for instance to detect and to resolve dependency issues. Selecting the Generate Xcode Project and Show Messages menu item in Finder or the Services menu will bring up a dialog that displays all messages from CMake plus the environment. The setup of custom environment variables is detailed in Section 5.3.2, “Setup of the Project Generator”.

The ProjectGenerator.app is also able to create a supplemental Xcode workspace for the Xcode projects. Select the CMakeLists.txt files of all projects you wish to be contained in a workspace, open the Finder context menu and choose Generate Xcode Projects and Workspace. The workspace will be created in the common parent folder of all selected items and include a scheme to build all projects at once. In addition to the workspace, a shell script with the file extension .command is written at the same location to facilitate regeneration of all included Xcode projects from the Finder by double-clicking on this script file.

Instead of using the ProjectGenerator.app interactively from the Finder, it may also be executed from the command line or scripts using the open command:

open -b de.fraunhofer.mevis.mlab.projectgenerator CMakeLists.txt

as well as by launching the bundle executable directly. Type the following call:

…/MeVisLab.app/Contents/Support/ProjectGenerator.app/Contents/MacOS/ProjectGenerator --help

in the Terminal to see all available options.

Finally, you may create and open an Xcode project from within MeVisLab via the context menu of a MeVisLab module (Edit Files › myproject.xcodeproj). Since MeVisLab uses some heuristics to locate your project, this entry may not always be included in the menu.

5.3.2. Setup of the Project Generator

The MeVisLab Project Generator offers lightweight integrations with macOS. You may enable or disable the contextual menu items for Finder in the Finder Extensions category of the Extensions system preferences pane (Figure 5.3, “Controlling the display of contextual menu items in Finder”) and for the Services menu in the Keyboard Shortcuts tab of the Keyboard system preferences pane.

Figure 5.3. Controlling the display of contextual menu items in Finder

Controlling the display of contextual menu items in Finder

The Finder Extension requires the definition of folder hierarchies where it will display the context menu entries. Default setting is the Developer folder in the home directory of the user and all subfolders. If you want to use a different or multiple folder hierarchies you can adapt the preference settings using the following command line (-array must be used even if just a single path is provided):

defaults write de.fraunhofer.mevis.mlab.projectgenerator.FinderExtension ObservedDirectories -array ~/Developer ~/Documents/Developer

To return to the default settings for the observed folder hierarchies, type:

defaults delete de.fraunhofer.mevis.mlab.projectgenerator.FinderExtension ObservedDirectories

If you need to provide custom environment variables to CMake and your project during the project generation phase, you may define them in the ToolRunner Preferences Panel box Additional Environment Variables. The MeVisLab Project Generator will read and apply these settings to CMake.