Building on macOS#
This tutorial shows how to build a SAMSON Extension on macOS using Qt Creator.
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.3.10+
- Qt 6.5.2 (download Qt: https://www.qt.io/download)
- Qt Creator (should be available when you install Qt) or another IDE you prefer, e.g. XCode. Qt Creator is necessary if you want to modify Qt forms.
Configuration of a project in Qt Creator#
Open the Qt Creator and click Open Project... or go to File > Open File or Project... (Cmd+O). Choose the root CMakeLists.txt file in the folder with your SAMSON Extension(s) (Note: CMakeLists.txt from the parent folder to your SAMSON Extension, not the CMakeLists.txt that is inside of your SAMSON Extension folder).
Building for x86_64 on ARM64#
Important
The shipped SAMSON SDK is done for the x86_64 system for the compatibility reasons. So, if your system has ARM64 processors (i.e., M1, M2, M3, M4, etc.) then you will need to build your SAMSON Extension(s) for the x86_64 system.
Change CMakeLists.txt#
To build for x86_64, i.e. against the shipped SAMSON SDK, add to the root CMakeLists.txt file in the folder with your SAMSON Extension(s) the following line right on top just after the line with CMAKE_MINIMUM_REQUIRED
:
Create a kit for x86_64 on ARM64#
You will need to create a special Kit (if it doesn't already exist) in Qt Creator:
-
Click Manage Kits...
-
In the Auto-detected kits, click on the Qt 6.5.2 for macOS and click Clone.
-
In the newly cloned Kit:
- Change its name by adding x86_64 to distinguish it from the original kit.
- Change C and C++ compilers to Apple Clang (x86_64).
-
Click OK to save the changes.
Configure Project#
- Choose the suitable Kit, e.g. the newly created kit for x86_64.
- Click on Details to unroll it.
-
Choose only Debug and Release options and specify the paths for them as follows:
- For Debug:
PathToExtensions/build/Debug
- For Release:
PathToExtensions/build/Release
- For Debug:
-
Click Configure Project.
You may see some errors in the Issues window. This is because it is necessary to specify some other CMake arguments for both Debug and Release builds. To do so, switch to the Projects mode (Cmd+5) in the left sidebar.
Build Settings#
CMake configuration#
Now, you need to specify some build settings:
-
Add a string variable called
SAMSON_SDK_PATH
and set it to the path to SAMSON SDK:$HOME/OneAngstrom/SAMSON-Sdks/6.0.2
. -
Add a boolean variable called
DEBUG
and toggle it toON
for the Debug build configuration and leave itOFF
for the Release build configuration. - Click Re-configure with Initial Parameters and press Yes in the pop-up dialog.
Now, the probject should be ready for building. But to be able to use your SAMSON Extension, it should be installed in a specific SAMSON directory to make it available in your SAMSON installation.
Build Steps#
To ensure that your SAMSON Extension(s) is installed:
- Scroll down to Build Steps and click on Details to unroll the options.
- Check the install option.
Build#
On the left sidebar, click on Edit and you should see your project - you can expand it to see its content.
Let's now try to build the project. Click Cmd+B to build the project or go to Build > Build Project "SAMSON-Elements".
You can see the build progress in the bottom right corner. The progress bar should go green if everything is alright. If it becomes red, then please check the Compile Output and also ensure that you properly specified the CMake variables mentioned above.
Note
Building the install target will automatically build your project.
If the build was successful your SAMSON Extension should be available when you launch SAMSON. During startup, your SAMSON Extension will be loaded alongside with the SAMSON Extensions you added from SAMSON Connect, as well as other SAMSON Extensions you developed.
Run Settings#
SAMSON Extensions may be built in both Debug and Release configurations. SAMSON Extensions compiled in Release mode will be available only when launching the SAMSON-Core executable provided with SAMSON installation, while SAMSON Extensions compiled in Debug mode will be available only when launching the SAMSON-Core executable provided with SAMSON SDK installation which provides the Debug version of the SAMSON-Core executable. 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 Extension, and when uploading it to SAMSON Connect. SAMSON Users only get the Release configuration, since this is the optimized one.
In order to let Qt Creator know which version of SAMSON to start, enter the path to the SAMSON-Core executable for each build configuration. For that switch to Projects mode (Cmd+5) through the left sidebar and in the Run Settings create two run configurations (one for Release and one for Debug) and specify the following SAMSON-Core executables (not the SAMSON-Core.sh files):
-
Set the executable in the Run configuration:
$HOME/OneAngstrom/SAMSON-Sdks/6.0.2/SAMSON-Debug/Binaries/SAMSON-Core-Console
$HOME/Applications/SAMSON.app/6.0.2/Binaries/SAMSON-Core-Console
Important
Replace
$HOME
with the path to your user folder.And save the run configuration as Debug or Release, respectively.
-
Add the following environment variables in the Environment section to let SAMSON search for frameworks or libraries to the correct location:
- add
DYLD_LIBRARY_PATH
and set it to$HOME/OneAngstrom/SAMSON-Sdks/6.0.2/SAMSON-Debug/Binaries
- add
DYLD_FRAMEWORK_PATH
and set it to$HOME/Qt/Qt6.5.2/6.5.2/macos/lib:$HOME/Applications/SAMSON.app/6.0.2/Binaries
- add
DYLD_LIBRARY_PATH
and set it to$HOME/OneAngstrom/SAMSON/6.0.2/SAMSON/Binaries
- add
DYLD_FRAMEWORK_PATH
and set it to$HOME/Qt/Qt6.5.2/6.5.2/macos/lib:$HOME/Applications/SAMSON.app/6.0.2/Binaries
Important
Replace
$HOME
with the path to your user folder. - add
Now when you build the install target (Cmd+B) and run (Cmd+R) SAMSON will be launched from Qt Creator.
Tip
If you choose Debug build and Debug run you can debug your SAMSON Extension, add breakpoints, and inspect variables values.
Run#
Now, you should be able to run SAMSON directly from Qt Creator and debug your SAMSON Extention(s), if necessary.
To run, click Cmd+R or Build > Run.
If you have any issues or questions, please use the SAMSON Connect Forum or contact us.
Adding files to a SAMSON Extension#
You can add files to (or remove files from) your new SAMSON Extension (e.g. to add or remove classes, to wrap existing code, etc.). When you do so you need to regenerate the project. To do this you can run cmake again or let your IDE to run it. Another more 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 or remove a whitespace somewhere) and save it: when building the project (see the next section), CMake will automatically detect the changes and will update the project.
Adding new SAMSON Extensions to the project#
When you generate a new SAMSON Extension with the SAMSON Extension Generator in the same folder with your other SAMSON Extensions, the Extension Generator will include the newly generated extensions into the root CMakeLists.txt
via ADD_SUBDIRECTORY
and this should be taken automatically into account next time you try to build the project.