Skip to content

Commit

Permalink
Merge pull request #19 from Mach1Studios/feature/embedded-cmake-build
Browse files Browse the repository at this point in the history
Feature/embedded cmake build
  • Loading branch information
himwho authored Jan 22, 2024
2 parents 85a4620 + 4d52998 commit d127e6e
Show file tree
Hide file tree
Showing 9 changed files with 338 additions and 51 deletions.
162 changes: 162 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
name: CMake

on:
push:
branches:
- main

env:
BUILD_TYPE: Release
OM_BUNDLE_ID: com.mach1.spatial.orientationmanager
OC_BUNDLE_ID: com.mach1.orientation.osc
JUCE_VERSION: 7.0.5
CMAKE_VERSION: 3.21.x
VERSION: 1.0.0

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-2016]

steps:
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.13
with:
cmake-version: 3.21.x

- name: Test cmake
run: cmake --version

- uses: actions/checkout@v3
with:
submodules: recursive

- name: OM Submodule JUCE
uses: actions/checkout@v3
with:
repository: juce-framework/JUCE
path: JUCE
ref: 7.0.5

- name: OM Configure (macos)
if: runner.os == 'MacOS'
shell: bash
run: cmake -Bbuild -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DM1_ORIENTATION_MANAGER_EMBEDDED=1

- name: OM Configure (windows)
if: runner.os == 'Windows'
shell: bash
run: cmake -Bbuild -A x64 -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DM1_ORIENTATION_MANAGER_EMBEDDED=1

- name: OM Build
shell: bash
run: cmake --build build --config $BUILD_TYPE

# - name: 'OM Upload Artifact (macos)'
# if: runner.os == 'MacOS'
# working-directory: ${{runner.workspace}}
# uses: actions/upload-artifact@v2
# with:
# name: m1-orientationmanager (MacOS)
# path: build/m1-orientationmanager_artefacts/Release/m1-orientationmanager
# if-no-files-found: error

# - name: 'OM Upload Artifact (windows)'
# if: runner.os == 'Windows'
# uses: actions/upload-artifact@v2
# with:
# name: m1-orientationmanager (Windows)
# path: ${{runner.workspace}}\build\m1-orientationmanager_artefacts\Release\m1-orientationmanager.exe
# if-no-files-found: error

# --- OSC CLIENT APP ---

- name: OC Configure (macos)
if: runner.os == 'MacOS'
shell: bash
working-directory: osc_client
run: cmake -Bbuild -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DM1_ORIENTATION_MANAGER_EMBEDDED=1

- name: OC Configure (windows)
if: runner.os == 'Windows'
shell: bash
working-directory: osc_client
run: cmake -Bbuild -A x64 -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DM1_ORIENTATION_MANAGER_EMBEDDED=1

- name: OC Build
working-directory: osc_client
shell: bash
run: cmake --build build --config $BUILD_TYPE

- name: OC Package (macos)
if: runner.os == 'MacOS'
shell: bash
env:
DIST_DIR: ${{ github.workspace }}/osc_client/build/M1-OrientationOSC_artefacts/Release
INSTALL_DIR: /Application/Mach1/OSC-Tool
BUNDLE_ID: ${{ env.OC_BUNDLE_ID }}
VERSION: ${{ env.VERSION }}
MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
MACOS_CERTIFICATE_NAME: ${{ secrets.MACOS_CERTIFICATE_NAME }}
MACOS_INSTALLER_CERTIFICATE: ${{ secrets.MACOS_INSTALLER_CERTIFICATE }}
MACOS_INSTALLER_CERTIFICATE_NAME: ${{ secrets.MACOS_INSTALLER_CERTIFICATE_NAME }}
MACOS_CERTIFICATE_PWD: ${{ secrets.MACOS_CERTIFICATE_PWD }}
MACOS_CI_KEYCHAIN_PWD: ${{ secrets.MACOS_CI_KEYCHAIN_PWD }}
run: |
echo $MACOS_CERTIFICATE | base64 --decode > certificate.p12
echo $MACOS_INSTALLER_CERTIFICATE | base64 --decode > installer.p12
RANDOM_PWD=`date | md5`
security create-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain
security import certificate.p12 -k build.keychain -P "$MACOS_CERTIFICATE_PWD" -T /usr/bin/codesign
security import installer.p12 -k build.keychain -P "$MACOS_CERTIFICATE_PWD" -T /usr/bin/productbuild
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$MACOS_CI_KEYCHAIN_PWD" build.keychain
/usr/bin/codesign -v --force -s "$MACOS_CERTIFICATE_NAME" --options runtime --entitlements Resources/entitlements.mac.plist --timestamp osc_client/build/M1-OrientationOSC_artefacts/Release/M1-OrientationOSC.app/Contents/MacOS/m1-orientationmanager
/usr/bin/codesign -v --force -s "$MACOS_CERTIFICATE_NAME" --options runtime --entitlements osc_client/Resources/M1-OrientationOSC.entitlements --timestamp osc_client/build/M1-OrientationOSC_artefacts/Release/M1-OrientationOSC.app
pkgbuild --identifier ${BUNDLE_ID} --version ${VERSION} --component ${DIST_DIR}/M1-OrientationOSC.app \
--install-location "${INSTALL_DIR}" ${DIST_DIR}/M1-OrientationOSC.app.pkg
productbuild --synthesize \
--package "${DIST_DIR}/M1-OrientationOSC.app.pkg" \
distribution.xml
productbuild --sign "$MACOS_INSTALLER_CERTIFICATE_NAME" --distribution distribution.xml --package-path ${DIST_DIR} ${DIST_DIR}/M1-OrientationOSC.pkg
- name: OC Notarize (macos)
if: runner.os == 'MacOS'
uses: cocoalibs/xcode-notarization-action@v1
with:
app-path: ${{ github.workspace }}/osc_client/build/M1-OrientationOSC_artefacts/Release/M1-OrientationOSC.pkg
apple-id: ${{ secrets.MACOS_NOTARIZE_USER }}
password: ${{ secrets.MACOS_NOTARIZE_PWD }}
team-id: ${{ secrets.TEAM_ID }}
# Further Parameters:
staple: 'true' # if you wish to skip running stapler

- name: OC InnoSetup Installer (windows)
if: runner.os == 'Windows'
working-directory: osc_client/build
run: |
"%programfiles(x86)%\Inno Setup 6\iscc.exe" /DBuildDir="${{github.workspace}}\osc_client" "${{github.workspace}}\osc_client\Resources\InnoSetup.iss"
shell: cmd

- name: 'OC Upload Artifact (macos)'
if: runner.os == 'MacOS'
uses: actions/upload-artifact@v2
with:
name: M1-OrientationOSC (MacOS)
path: ${{ github.workspace }}/osc_client/build/M1-OrientationOSC_artefacts/Release/M1-OrientationOSC.pkg
if-no-files-found: error

- name: 'OC Upload Artifact (windows)'
if: runner.os == 'Windows'
uses: actions/upload-artifact@v2
with:
name: M1-OrientationOSC (Windows)
path: ${{ github.workspace }}\osc_client\build\m1-M1-OrientationOSC_artefacts\Release\Output\M1-OrientationOSC_WIN.exe
if-no-files-found: error
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ M1notifier/dist
* - Notarized*
*.ttf
*.otf
osc_client/Resources/m1-orientationmanager*

# JUCE
Builds
Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
m1_orientation_client
)

option(M1_ORIENTATION_MANAGER_EMBEDDED "Build with m1-orientationmanager expected alongside this client" OFF)

option(BUILD_DEBUG_UI "Build with debug GUI window" OFF)

if (BUILD_DEBUG_UI)
Expand Down Expand Up @@ -166,4 +168,11 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
endif()

install(TARGETS ${CMAKE_PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})

if (M1_ORIENTATION_MANAGER_EMBEDDED)
message(STATUS "Copying to OSC Client Resources: ${CMAKE_SOURCE_DIR}/osc_client/Resources")
add_custom_command(TARGET ${CMAKE_PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_SOURCE_DIR}/osc_client/Resources)
endif()
58 changes: 56 additions & 2 deletions osc_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,62 @@ option(M1_ORIENTATION_MANAGER_EMBEDDED "Build with m1-orientationmanager expecte

if (M1_ORIENTATION_MANAGER_EMBEDDED)
add_compile_definitions(M1_ORIENTATION_MANAGER_EMBEDDED=ON)
message(STATUS "Please embed or install the m1-orientationmanager: MacOS=`Contents/MacOS/m1-orientationmanager` Win= sibling to M1-OrientationOSC.exe")
message(STATUS "Please embed or install the settings.json: MacOS=`Contents/Resources/settings.json` Win= sibling to M1-OrientationOSC.exe")

message(STATUS "[Warning] Please make sure you build m1-orientationmanager first!")

# TODO: Make this process safer and not hardcoded copying
if(APPLE)
# Add settings.json
message(STATUS "Adding copy command for the settings.json file")
add_custom_command(
TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/Resources/settings.json
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}_artefacts/$<CONFIG>/${CMAKE_PROJECT_NAME}.app/Contents/Resources/settings.json
)
# Add m1-orientationmanager executable
message(STATUS "Adding copy command for the m1-orientationmanager file")
add_custom_command(
TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/Resources/m1-orientationmanager
$<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>/m1-orientationmanager
)
elseif(MSVC OR WIN32 OR MINGW)
# Add settings.json
message(STATUS "Adding copy command for the settings.json file")
add_custom_command(
TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/Resources/settings.json
$<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>/settings.json
)
# Add m1-orientationmanager executable
message(STATUS "Adding copy command for the m1-orientationmanager file")
add_custom_command(
TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/Resources/m1-orientationmanager.exe
$<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>/m1-orientationmanager.exe
)
else()
# Add settings.json
message(STATUS "Adding copy command for the settings.json file")
add_custom_command(
TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/Resources/settings.json
$<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>/settings.json
)
# Add m1-orientationmanager executable
message(STATUS "Adding copy command for the m1-orientationmanager file")
add_custom_command(
TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/Resources/m1-orientationmanager
$<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>/m1-orientationmanager
)
endif()
endif()

### IDE Generator post-config ###
Expand Down
35 changes: 35 additions & 0 deletions osc_client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# M1-OrientationOSC Client App
Client GUI app for interfacing with the m1-orientationmanager service. Also can be used to relay the orientation to a software target via OSC.

## Setup

This project is designed to be used 2 ways:
- [default] Built as is and the M1-OrientationOSC.app/exe will expect to communicate with already installed M1-OrientationManager and M1-System-Helper to avoid conflicts when these are already installed as services
- [Warning this can cause conflict if a locally installed Mach1 Spatial System 2.0+ is installed] Build with the definition `M1_ORIENTATION_MANAGER_EMBEDDED` so that the Client expects to find sibling m1-orientationmanager executable and associated `settings.json` locally.

### Build via CMake
- `cmake -Bbuild` Create project files by adding the appropriate `-G Xcode` or `-G "Visual Studio 16 2019"` also decide if you are building to sit as a portable client (and not installed to a machine that already has Mach1 Spatial System installed) add `-DM1_ORIENTATION_MANAGER_EMBEDDED=1`
- `cmake --build build`

### Build via .jucer
- `cd Builds/MacOSX/` or `cd Builds/VisualStudio2019`
- if you are building to sit as a portable client (and not installed to a machine that already has Mach1 Spatial System installed) add `M1_ORIENTATION_MANAGER_EMBEDDED=1` to the target definitions.
- Open the `M1-OrientationOSC.jucer` and compile as needed

## Install
By default the m1-orientationmanager service executable is expected in a common data directory of each local machine, and where applicable to be managed by a service agent or LaunchAgent unless built with the `M1_ORIENTATION_MANAGER_EMBEDDED` definition.

**If using `M1_ORIENTATION_MANAGER_EMBEDDED` please make sure the m1-orientationmanager executable and the settings.json are also installed locally**

## OSC Tool
This repo also includes a flexible and simple UI app to show an example of interfacing with the m1-orientationmanager background service and output the calculated orientation via OSC to any IP + port for use with other software.

This can be found in the [osc_client](osc_client) directory.

### Setup
- Build via CMake or JUCE to compile the contents of [osc_client](osc_client) via the same methods described above
- Copy the [settings.json](Resources/settings.json) to either:
- MacOS `/Library/Application Support/Mach1/settings.json` or on windows `\Documents and Settings\All Users\Application Data\Mach1\settings.json` and ensure that `useStandalone = false`
- Set `useStandalone = true` and install the `settings.json` next to the executable
- Run the built m1-orientationmanager executable via the instructions above, the client will look for the server locally via http

12 changes: 12 additions & 0 deletions osc_client/Resources/InnoSetup.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Setup]
AppName=M1-OrientationOSC
AppVersion=1.0.0
Uninstallable=no
SourceDir="{#BuildDir}"
DefaultDirName="{pf64}\Mach1\OSC-Tool"
DefaultGroupName=M1-OrientationOSC
OutputBaseFilename=M1-OrientationOSC_WIN
[Files]
Source: "build\m1-M1-OrientationOSC_artefacts\Release\M1-OrientationOSC.exe"; DestDir: {app}; Flags: recursesubdirs
Source: "Resources\M1-OrientationManager.exe"; DestDir: {app}; Flags: recursesubdirs
Source: "Resources\settings.json"; DestDir: {app}; Flags: recursesubdirs
18 changes: 18 additions & 0 deletions osc_client/Resources/M1-OrientationOSC.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
</dict>
</plist>
6 changes: 0 additions & 6 deletions osc_client/Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,17 @@ class M1OrientationDeviceClientTestApplication : public juce::JUCEApplication
//==============================================================================
void initialise (const juce::String& commandLine) override
{
// This method is where you should put your application's initialisation code..

mainWindow.reset (new MainWindow (getApplicationName()));
}

void shutdown() override
{
// Add your application's shutdown code here..

mainWindow = nullptr; // (deletes our window)
}

//==============================================================================
void systemRequestedQuit() override
{
// This is called when the app is being asked to quit: you can ignore this
// request and let the app carry on running, or call quit() to allow the app to close.
quit();
}

Expand Down
Loading

0 comments on commit d127e6e

Please sign in to comment.