Skip to content

Commit

Permalink
Add support for macOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Jan 27, 2024
1 parent 0f0bfe3 commit 49cc317
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(FREEDV_SOURCES
freedv_interface.cpp
)

set(FREEDV_LINK_LIBS_OSX
list(APPEND FREEDV_LINK_LIBS_OSX
"-framework AVFoundation"
)

Expand All @@ -35,7 +35,7 @@ if(APPLE)
BUNDLE True
MACOSX_BUNDLE_GUI_IDENTIFIER org.freedv.freedv
MACOSX_BUNDLE_BUNDLE_NAME FreeDV
MACOSX_BNUDLE_COPYRIGHT "Copyright (c) 2021 FreeDV"
MACOSX_BNUDLE_COPYRIGHT "Copyright (c) 2024 FreeDV"
MACOSX_BUNDLE_BUNDLE_VERSION "${FreeDV_VERSION}"
MACOSX_BUNDLE_BUNDLE_SHORT_VERSION_STRING "${FreeDV_VERSION}"
MACOSX_BUNDLE_BUNDLE_LONG_VERSION_STRING "${FreeDV_VERSION}"
Expand Down Expand Up @@ -76,6 +76,7 @@ endif(FREEDV_STATIC_DEPS)

# Link other dependencies
if(APPLE)
target_link_options(FreeDV PRIVATE -F ${CMAKE_CURRENT_BINARY_DIR}/os/sparkle_src)
target_link_libraries(FreeDV ${FREEDV_LINK_LIBS} ${FREEDV_LINK_LIBS_OSX})
elseif(WIN32)
target_link_libraries(freedv ${FREEDV_LINK_LIBS} ws2_32)
Expand Down Expand Up @@ -130,7 +131,7 @@ if(APPLE)
TARGET FreeDV
POST_BUILD
COMMAND rm -rf dist_tmp FreeDV.dmg || true
COMMAND DYLD_LIBRARY_PATH=${CODEC2_BUILD_DIR}/src:${LPCNET_BUILD_DIR}/src:${portaudio_BINARY_DIR}:${samplerate_BINARY_DIR}/src:${DYLD_LIBRARY_PATH} ${CMAKE_SOURCE_DIR}/macdylibbundler/dylibbundler ARGS -od -b -x FreeDV.app/Contents/MacOS/FreeDV -d FreeDV.app/Contents/libs -p @loader_path/../libs/ -i /usr/lib -s ${LPCNET_BUILD_DIR}/src -s ${CODEC2_BUILD_DIR}/src -s ${CMAKE_BINARY_DIR}/LPCNet_build/src -s ${CMAKE_BINARY_DIR}/codec2_build/src -s ${portaudio_BINARY_DIR} -s ${samplerate_BINARY_DIR}/src
COMMAND DYLD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/os/sparkle_src:${CODEC2_BUILD_DIR}/src:${LPCNET_BUILD_DIR}/src:${portaudio_BINARY_DIR}:${samplerate_BINARY_DIR}/src:${DYLD_LIBRARY_PATH} ${CMAKE_SOURCE_DIR}/macdylibbundler/dylibbundler ARGS -od -b -x FreeDV.app/Contents/MacOS/FreeDV -d FreeDV.app/Contents/libs -p @loader_path/../libs/ -i /usr/lib -s ${LPCNET_BUILD_DIR}/src -s ${CODEC2_BUILD_DIR}/src -s ${CMAKE_BINARY_DIR}/LPCNet_build/src -s ${CMAKE_BINARY_DIR}/codec2_build/src -s ${portaudio_BINARY_DIR} -s ${samplerate_BINARY_DIR}/src -f -s ${CMAKE_BINARY_DIR}/src/os/sparkle_src/Sparkle.framework/Versions/Current
COMMAND cp ARGS ${CMAKE_CURRENT_SOURCE_DIR}/freedv.icns FreeDV.app/Contents/Resources
COMMAND codesign --force --options runtime --timestamp --entitlements ${CMAKE_CURRENT_SOURCE_DIR}/entitlements.plist --sign - ${CMAKE_CURRENT_BINARY_DIR}/FreeDV.app
COMMAND mkdir dist_tmp
Expand Down
4 changes: 3 additions & 1 deletion src/info.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
<string>NSApplication</string>
<key>NSRequiresAquaSystemAppearance</key>
<@DARK_MODE_DISABLE@ />
<key>SUFeedURL</key>
<string>https://k6aq.net/freedv-update/appcast.xml</string>
</dict>
</plist>
</plist>
44 changes: 34 additions & 10 deletions src/os/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
# General OS specific hooks
if(APPLE)
set(OS_WRAP_FILES osx_interface.mm)
else(APPLE)
set(OS_WRAP_FILES osx_stubs.cpp)
endif(APPLE)

# Autoupdate handling
if(WIN32)
list(APPEND OS_WRAP_FILES windows_autoupdate.cpp)
elseif(APPLE)
list(APPEND OS_WRAP_FILES macos_autoupdate.mm)
else()
list(APPEND OS_WRAP_FILES no_autoupdate.cpp)
endif()

add_library(fdv_os_wrapper STATIC
${OS_WRAP_FILES}
)

include(ExternalProject)

if(WIN32)
# Auto-update functionality requires winsparkle, so build the DLL for it.
if(CMAKE_CROSSCOMPILING)
set(WINSPARKLE_CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE})
endif()

# Build winsparkle library
include(ExternalProject)
ExternalProject_Add(build_winsparkle
SOURCE_DIR winsparkle_src
SOURCE_SUBDIR cmake
Expand All @@ -35,19 +50,28 @@ if(WIN32)
include_directories(${WINSPARKLE_INCLUDE_DIRS})

# Add SW update related hooks.
list(APPEND OS_WRAP_FILES windows_autoupdate.cpp)
set(AUTOUPDATE_LIBRARY winsparkle)
add_dependencies(winsparkle build_winsparkle)
elseif(APPLE)
# TBD: Sparkle support for updates on macOS.
list(APPEND OS_WRAP_FILES no_autoupdate.cpp)
else()
list(APPEND OS_WRAP_FILES no_autoupdate.cpp)
endif()
# Download Sparkle
ExternalProject_Add(build_sparkle
URL https://github.com/sparkle-project/Sparkle/releases/download/2.5.2/Sparkle-2.5.2.tar.xz
SOURCE_DIR sparkle_src
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
UPDATE_COMMAND "" # Skip annoying updates for every build
INSTALL_COMMAND ""
)
ExternalProject_Get_Property(build_sparkle SOURCE_DIR)
add_library(sparkle SHARED IMPORTED)

add_library(fdv_os_wrapper STATIC
${OS_WRAP_FILES}
)
set(AUTOUPDATE_LIBRARY "-framework Sparkle")

# Ensure that the compile step can find Sparkle.framework.
target_compile_options(fdv_os_wrapper PRIVATE -F ${SOURCE_DIR})
target_link_directories(fdv_os_wrapper PRIVATE ${SOURCE_DIR})
add_dependencies(fdv_os_wrapper build_sparkle)
endif()

target_include_directories(fdv_os_wrapper PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/..)
target_link_libraries(fdv_os_wrapper PRIVATE ${AUTOUPDATE_LIBRARY})
58 changes: 58 additions & 0 deletions src/os/macos_autoupdate.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//==========================================================================
// Name: macos_autoupdate.mm
//
// Purpose: Provides C wrapper to platform-specific autoupdate interface.
// Created: Jan. 27, 2024
// Authors: Mooneer Salem
//
// License:
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General License version 2.1,
// as published by the Free Software Foundation. This program is
// distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//
//==========================================================================

#include <cstdio>
#include "os_interface.h"
#import <Sparkle/Sparkle.h>

@interface AppUpdaterDelegate : NSObject <SPUUpdaterDelegate>

@property (nonatomic) SPUStandardUpdaterController *updaterController;

@end

@implementation AppUpdaterDelegate

- (void)updaterDidNotFindUpdate:(nonnull SPUUpdater *)updater
error:(nonnull NSError *)error
{
NSString* str = [error localizedDescription];
fprintf(stderr, "update error: %s\n", str.UTF8String);
fprintf(stderr, "description: %s\n", error.userInfo.description.UTF8String);
}

@end

static AppUpdaterDelegate* _updaterDelegate;

// Autoupdate: initialize autoupdater.
void initializeAutoUpdate()
{
_updaterDelegate = [[AppUpdaterDelegate alloc] init];
_updaterDelegate.updaterController = [[SPUStandardUpdaterController alloc] initWithStartingUpdater:YES updaterDelegate:_updaterDelegate userDriverDelegate:nil];
}

// Autoupdate: cleanup autoupdater.
void cleanupAutoUpdate()
{
[_updaterDelegate release];
}

0 comments on commit 49cc317

Please sign in to comment.