Building on Mac OS X

This tutorial shows how to build a SAMSON Element on Mac OS using XCode. If you want to use QtCreator as the main IDE for developing a SAMSON Element you can follow the same steps from the Building on Linux tutorial.

Requirements

If you have not installed the SAMSON SDK, please, follow the instructions from the Installation of SDK section.

• Compiler Clang (available when you install XCode)
• CMake v.2.8.9+
• Qt5.12.5
• XCode, QtCreator (should be available when you install Qt) or another IDE you prefer. QtCreator is necessary if you want to modify Qt forms.

Configuration of a project in XCode

Once CMake is installed, generating a project for your development environment is straightforward.

Let's assume that Qt is installed in YourQtPath (i.e. the folder which contains the Qt5.12.5 folder) and the SAMSON SDK is installed in YourSDKPath/SDK/0.10.0/ (i.e. the folder which contains the following sub-folders: cmake, include, libs, SAMSON-Debug).

We will configure a project in the terminal. Go to the folder where your SAMSON Element is stored, open the build folder (if there is no such folder, create it) and execute the following command in terminal:

cmake -DSAMSON_SDK_PATH=YourSDKPath/SDK/0.10.0 -G"Xcode" ..

The -G designates the cmake generator, to check the available ones execute cmake -h in the terminal.

Note: If you have not specified the QT5_CMAKE_INCLUDE_DIR during the SAMSON SDK Intallation procedure, you will need either to add the QT5_CMAKE_INCLUDE_DIR environment variable or specify it in the previous cmake command by adding -DQT5_CMAKE_INCLUDE_DIR:

cmake -DSAMSON_SDK_PATH=YourSDKPath/SDK/0.10.0 -G"Xcode" \
-DQT5_CMAKE_INCLUDE_DIR=YourQtPath/Qt5.12.5/5.12.5/clang_64/lib/cmake/ ..

Generating a XCode project in the terminal

This should generate a XCode project .xcodeproj for your development environment. In this example for Xcode, cmake generates, among others, the xcodeproj file SAMSON-Elements-release that you can now open in Xcode. The Solution Explorer of XCode should show a project structure similar to the one shown below:

The generated solution in XCode

Adding files to a SAMSON Element

You can add files to (or remove files from) your new SAMSON Element (e.g. to add or remove classes, to wrap existing code, etc.). When you do so, you should run cmake again (or let your IDE to run it) to regenerate a project for your development environment. One simple way to do this without having to open a command window is to slightly alter the CMakeLists.txt file located in the SEMyElement (e.g. add and remove a whitespace somewhere) and save it: when building the project (see the next section), CMake will detect the changes and update the project.

Building step

Once your project is opened, you can now browse your SAMSON Element files and edit your code. The project contains one target for your SAMSON Element (SEMyElement), as well as some cmake-specific targets. When you generate new SAMSON Elements with the SAMSON Element generator in the same folder, CMake will re-generate the project files and will add new targets as needed.

You may now check that your code compiles by either building the target corresponding to it (SEMyElement) or when your solution contains several SAMSON Elements and you want to compile them all at once, by building the ALL_BUILD target.

Note that SAMSON Elements may be built in both Debug and Release configurations. The Debug configuration is the one you should use to develop and debug your code, while the Release configuration is the one you should use when testing the performance of your SAMSON Element, and when uploading it to SAMSON Connect.

To switch between Debug and Release builds, click on the Edit scheme (see image below) and in the Run tab set the Build configuration to Debug or Release.

Click on Edit scheme

Select Debug or Release mode

To be able to use your SAMSON Element, it should be installed in a specific SAMSON directory to make it available in your SAMSON installation. Choose and build the install target (either in Debug or Release configurations) to install your new SAMSON Element (building the install target will automatically build your project). If the build was successful your SAMSON Element should be available when you launch SAMSON (for Release configuration - SAMSON-Core from SAMSON installation, for Debug configuration - SAMSON-Core from the SAMSON SDK installation). During startup, your SAMSON Element will be loaded alongside with the SAMSON Elements you added from SAMSON Connect as well as other SAMSON Elements you developed.

Choose install target

Running SAMSON

Note that you should start the SAMSON configuration that corresponds to the configuration used to build your SAMSON Element:

• a SAMSON Element compiled in Release mode will be available only when launching the SAMSON-Core executable provided with SAMSON installation;
• a SAMSON Element compiled in Debug mode will be available only when launching the SAMSON-Core executable provided with SAMSON SDK installation.

SAMSON users only get the Release configuration, since this is the optimized one. The SAMSON SDK installer, though, adds a Debug version of the SAMSON-Core executable. It is this version that should be started when testing or debugging SAMSON Elements compiled in the Debug configuration.

In order to let XCode know which version of SAMSON to start, open Edit scheme and enter the path to the SAMSON-Core executable (not the SAMSON-Core.command file) for both Release and Debug build configurations:

• for the Debug configuration indicate the SAMSON-Core executable from the SAMSON SDK installation and tick the Debug executable checkbox.
• for the Release configuration indicate the SAMSON-Core executable from the SAMSON installation and untick the Debug executable checkbox.

Set the SAMSON-Core executable

We need to setup some environment variables to let SAMSON search for frameworks or libraries to the corect location. In the Arguments tab add the following environment variables :

• DYLD_LIBRARY_PATH filled with absolute path coresponding to SAMSON debug libraries: YourSDKPath/SDK/0.10.0/SAMSON-Debug/Binaries
• DYLD_FRAMEWORK_PATH filled with absolute path coresponding to the location of Qt frameworks: YourQtPath/Qt5.12.5/5.12.5/clang_64/lib/.

You may also add some command line arguments into Arguments Passed On Launch, like: –logconsole –disablenetwork –import –logfile “file” –logdefaultfile.

Set environment variables

Now when you build the install target SAMSON will start.

Runnin SAMSON from XCode

Debugging a SAMSON Element

You can debug your code in the Debug mode, add breakpoints, inspect variables, etc.

Debugging a SAMSON Element

Debugging a SAMSON Element