Skip to content

Commit

Permalink
Merge branch 'release/0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverepper committed Apr 10, 2023
2 parents 3642a91 + 9a38586 commit fce2a59
Show file tree
Hide file tree
Showing 41 changed files with 2,037 additions and 101 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ cmake-build-debug
.idea
TODO.md
cmake/credentials.cmake
installed
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
cmake_minimum_required(VERSION 3.3)

project(phone VERSION 0.5.0 LANGUAGES C CXX)
project(phone VERSION 0.6.0 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)

set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN true)

if(NOT CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/installed/pjproject/macos-arm64"
CACHE STRING "Path to pjproject dependency")
endif()

include(GNUInstallDirs)

file(RELATIVE_PATH pathToLibs
Expand All @@ -33,4 +38,4 @@ endif()

add_subdirectory(src bin)

install(TARGETS phone_sharedlib)
install(TARGETS phone_sharedlib cpp_cli)
20 changes: 20 additions & 0 deletions build-darwin-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

mkdir -p build
pushd build || exit 1
sh ../scripts/get-ios-toolchain.sh
sh ../scripts/build-opus-darwin.sh "$(pwd)/../installed/opus"
sh ../scripts/build-sdl-darwin.sh "$(pwd)/../installed/sdl"

sh ../scripts/build-pjproject-ios-arm64.sh "$(pwd)/../installed"

sh ../scripts/build-pjproject-simulator-arm64.sh "$(pwd)/../installed"
sh ../scripts/build-pjproject-simulator-x86_64.sh "$(pwd)/../installed"

sh ../scripts/build-pjproject-macos-arm64.sh "$(pwd)/../installed"
sh ../scripts/build-pjproject-macos-x86_64.sh "$(pwd)/../installed"

sh ../scripts/build-pjproject-catalyst-arm64.sh "$(pwd)/../installed"
sh ../scripts/build-pjproject-catalyst-x86_64.sh "$(pwd)/../installed"

popd build || exit 1
95 changes: 95 additions & 0 deletions scripts/build-opus-darwin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env bash
# Oliver Epper <[email protected]>

set -e
env -i

if [ $# -eq 0 ]
then
echo "sh $0 <absolute path>"
exit 1
fi

PREFIX=$1
BUILD_BASE_DIR=build-opus
OPUS_COMMIT=8cf872a186b96085b1bb3a547afd598354ebeb87

if [ -d opus ]
then
pushd opus
git clean -fxd
git reset --hard "${OPUS_COMMIT}"
popd
else
# opus cmake script use .git, so check it out completely
git clone https://gitlab.xiph.org/xiph/opus.git
git -c advice.detachedHead=false -C opus checkout ${OPUS_COMMIT}
fi

function build {
local TOOLCHAIN_PLATFORM_NAME=$1
local INSTALL_PREFIX=$2
local DEPLOYMENT_TARGET=$3
local BUILD_DIR="${BUILD_BASE_DIR}"/"${TOOLCHAIN_PLATFORM_NAME}"

echo "Building for platform ${TOOLCHAIN_PLATFORM_NAME} with deployment target ${DEPLOYMENT_TARGET}"
echo "Building in ${BUILD_DIR}"
echo "Installing to: ${INSTALL_PREFIX}"

case "${TOOLCHAIN_PLATFORM_NAME}" in
*"CATALYST"*|"MAC")
cmake -B"${BUILD_DIR}" \
-Sopus \
-G"Ninja Multi-Config" \
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
-DCMAKE_TOOLCHAIN_FILE=../ios-cmake/ios.toolchain.cmake \
-DPLATFORM="${TOOLCHAIN_PLATFORM_NAME}" \
-DENABLE_BITCODE=OFF \
-DOPUS_INSTALL_CMAKE_CONFIG_MODULE=OFF
;;
*)
cmake -B"${BUILD_DIR}" \
-Sopus \
-G"Ninja Multi-Config" \
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
-DCMAKE_TOOLCHAIN_FILE=../ios-cmake/ios.toolchain.cmake \
-DPLATFORM="${TOOLCHAIN_PLATFORM_NAME}" \
-DCMAKE_OSX_DEPLOYMENT_TARGET="${DEPLOYMENT_TARGET}" \
-DENABLE_BITCODE=OFF \
-DOPUS_INSTALL_CMAKE_CONFIG_MODULE=OFF
;;
esac

cmake --build "${BUILD_DIR}" \
--config Release \
--target install
}


# build for iOS on arm64
IOS_ARM64_INSTALL_PREFIX="${PREFIX}/ios-arm64"
build OS64 "${IOS_ARM64_INSTALL_PREFIX}" 13.0

# build for iOS simulator on arm64
SIMULATOR_ARM64_INSTALL_PREFIX="${PREFIX}/simulator-arm64"
build SIMULATORARM64 "${SIMULATOR_ARM64_INSTALL_PREFIX}" 13.0

# build for iOS simulator on x86_64
SIMULATOR_X86_64_INSTALL_PREFIX="${PREFIX}/simulator-x86_64"
build SIMULATOR64 "${SIMULATOR_X86_64_INSTALL_PREFIX}" 13.0

# build for Catalyst on arm64
MACCATALYST_ARM64_INSTALL_PREFIX="${PREFIX}/maccatalyst-arm64"
build MAC_CATALYST_ARM64 "${MACCATALYST_ARM64_INSTALL_PREFIX}" 13.1

# build for Catalyst on x86_64
MACCATALYST_X86_64_INSTALL_PREFIX="${PREFIX}/maccatalyst-x86_64"
build MAC_CATALYST "${MACCATALYST_X86_64_INSTALL_PREFIX}" 13.1

# build for macOS on arm64
MACOS_UNIVERSAL_INSTALL_PREFIX="${PREFIX}/macos-arm64"
build MAC_ARM64 "${MACOS_UNIVERSAL_INSTALL_PREFIX}" 11.0

# build for macOS on x86_64
MACOS_X86_64_INSTALL_PREFIX="${PREFIX}/macos-x86_64"
build MAC "${MACOS_X86_64_INSTALL_PREFIX}" 11.0
32 changes: 32 additions & 0 deletions scripts/build-pjproject-catalyst-arm64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# Oliver Epper <[email protected]>

source "$(dirname $0)"/build-pjproject-darwin-base.sh

PREFIX="${PREFIX}/catalyst-arm64"
rm -rf "${PREFIX}"

pushd pjproject || exit 1
prepare YES

OPUS=("$(pwd)"/../../installed/opus/maccatalyst-arm64)
OPUS_LATEST=${OPUS[${#OPUS[@]} - 1]}
if [[ -d "${OPUS_LATEST}" ]]
then
CONFIGURE_EXTRA_PARAMS+=("--with-opus=${OPUS_LATEST}")
fi

SDKPATH=$(xcrun -sdk macosx --show-sdk-path)
ARCH="arm64"
CFLAGS="-isysroot $SDKPATH -isystem ${SDKPATH}/System/iOSSupport/usr/include -iframework ${SDKPATH}/System/iOSSupport/System/Library/Frameworks -miphoneos-version-min=13.1 -DPJ_SDK_NAME=\"\\\"$(basename "$SDKPATH")\\\"\" -arch $ARCH -target ${ARCH}-apple-ios-macabi" \
LDFLAGS="-isysroot $SDKPATH -isystem ${SDKPATH}/System/iOSSupport/usr/include -iframework ${SDKPATH}/System/iOSSupport/System/Library/Frameworks -framework Network -framework Security -framework Foundation -arch $ARCH -target ${ARCH}-apple-ios-macabi" \
./aconfigure --prefix="${PREFIX}" --host="${ARCH}"-apple-darwin_ios "${CONFIGURE_EXTRA_PARAMS[@]}" --disable-sdl

make dep && make clean
make VERBOSE=1
make install


create_lib "${PREFIX}/lib"
pkgconfig_ios "${PREFIX}"
popd || exit 1
32 changes: 32 additions & 0 deletions scripts/build-pjproject-catalyst-x86_64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# Oliver Epper <[email protected]>

source "$(dirname "$0")"/build-pjproject-darwin-base.sh

PREFIX="${PREFIX}/catalyst-x86_64"
rm -rf "${PREFIX}"

pushd pjproject || exit 1
prepare YES

OPUS=("$(pwd)"/../../installed/opus/maccatalyst-x86_64)
OPUS_LATEST=${OPUS[${#OPUS[@]} - 1]}
if [[ -d "${OPUS_LATEST}" ]]
then
CONFIGURE_EXTRA_PARAMS+=("--with-opus=${OPUS_LATEST}")
fi

SDKPATH=$(xcrun -sdk macosx --show-sdk-path)
ARCH="x86_64"
CFLAGS="-isysroot $SDKPATH -isystem ${SDKPATH}/System/iOSSupport/usr/include -iframework ${SDKPATH}/System/iOSSupport/System/Library/Frameworks -miphoneos-version-min=13.1 -DPJ_SDK_NAME=\"\\\"$(basename "$SDKPATH")\\\"\" -arch $ARCH -target ${ARCH}-apple-ios-macabi" \
LDFLAGS="-isysroot $SDKPATH -isystem ${SDKPATH}/System/iOSSupport/usr/include -iframework ${SDKPATH}/System/iOSSupport/System/Library/Frameworks -framework Network -framework Security -framework Foundation -arch $ARCH -target ${ARCH}-apple-ios-macabi" \
./aconfigure --prefix="${PREFIX}" --host="${ARCH}"-apple-darwin_ios "${CONFIGURE_EXTRA_PARAMS[@]}" --disable-sdl

make dep && make clean
make VERBOSE=1
make install


create_lib "${PREFIX}/lib"
pkgconfig_ios "${PREFIX}"
popd || exit 1
146 changes: 146 additions & 0 deletions scripts/build-pjproject-darwin-base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/bin/bash
# Oliver Epper <[email protected]>

set -e
env -i

if [ $# -eq 0 ]
then
echo "sh $(basename "$0") <absolute path>"
exit 1
fi

export PREFIX="$1/pjproject"
PJPROJECT_VERSION=2.13

#IOS_ARM64_INSTALL_PREFIX="${PREFIX}/ios-arm64"
#
#SIMULATOR_ARM64_INSTALL_PREFIX="${PREFIX}"/simulator-arm64
#
##IOS_ARM64_SIMULATOR_INSTALL_PREFIX="${PREFIX}/ios-arm64-simulator"
##IOS_X86_64_SIMULATOR_INSTALL_PREFIX="${PREFIX}/ios-x86_64-simulator"
##IOS_ARM64_X86_64_SIMULATOR_INSTALL_PREFIX="${PREFIX}/ios-arm64_x86_64-simulator"
#
#
#IOS_ARM64_MACCATALYST_INSTALL_PREFIX="${PREFIX}/ios-arm64-maccatalyst"
#IOS_X86_64_MACCATALYST_INSTALL_PREFIX="${PREFIX}/ios-x86_64-maccatalyst"
#IOS_ARM64_X86_64_MACCATALYST_INSTALL_PREFIX="${PREFIX}/ios-arm64_x86_64-maccatalyst"
#
#MACOS_ARM64_INSTALL_PREFIX="${PREFIX}/macos-arm64"
#MACOS_X86_64_INSTALL_PREFIX="${PREFIX}/macos-x86_64"
#MACOS_ARM64_X86_64_INSTALL_PREFIX="${PREFIX}/macos-arm64_x86_64"
#MACOS_ARM64_DEBUG_INSTALL_PREFIX="${PREFIX}/macos-arm64-debug"

if [ -d pjproject ]
then
pushd pjproject
git reset --hard "${PJPROJECT_VERSION}"
popd
else
git -c advice.detachedHead=false clone --depth 1 --branch "${PJPROJECT_VERSION}" https://github.com/pjsip/pjproject # > /dev/null 2>&1
fi

# create base configuration for pjproject build
pushd pjproject
cat << EOF > pjlib/include/pj/config_site.h
#define PJ_HAS_SSL_SOCK 1
#undef PJ_SSL_SOCK_IMP
#define PJ_SSL_SOCK_IMP PJ_SSL_SOCK_IMP_APPLE
#include <pj/config_site_sample.h>
EOF
popd

function prepare {
local WANTS_IPHONE=$1
local WANTS_VIDEO=$2

git reset --hard
git clean -fxd

cat << EOF > pjlib/include/pj/config_site.h
#define PJ_HAS_SSL_SOCK 1
#undef PJ_SSL_SOCK_IMP
#define PJ_SSL_SOCK_IMP PJ_SSL_SOCK_IMP_APPLE
#include <pj/config_site_sample.h>
EOF

if [[ "${WANTS_IPHONE}" = "YES" ]]; then
echo "🔧 adding iPhone support"
sed -i '' -e '1i\
#define PJ_CONFIG_IPHONE 1
' pjlib/include/pj/config_site.h
fi

if [[ "${WANTS_VIDEO}" = "YES" ]]; then
echo "🔧 adding video support"
sed -i '' -e '1i\
#define PJMEDIA_HAS_VIDEO 1 \
#define PJMEDIA_HAS_VID_TOOLBOX_CODEC 1
' pjlib/include/pj/config_site.h
fi
}

function create_lib {
pushd "$1"
EXTRA_LIBS=()
if [ -d "${OPUS_LATEST}" ]; then
EXTRA_LIBS+=("${OPUS_LATEST}/lib/libopus.a")
unset OPUS
unset OPUS_LATEST
fi
if [[ -d "${SDL_LATEST}" ]]; then
EXTRA_LIBS+=("${SDL_LATEST}/lib/libSDL2.a")
unset SDL
unset SDL_LATEST
fi

LLVM=(/opt/homebrew/Cellar/llvm/*)
LLVM_LATEST=${LLVM[${#LLVM[@]} - 1]}
if [[ -d "${LLVM_LATEST}" ]]
then
"${LLVM_LATEST}"/bin/llvm-libtool-darwin -static -o libpjproject.a ./*.a "${EXTRA_LIBS[@]}"
touch libpjproject_is_sane
else
libtool -static -o libpjproject.a ./*.a "${EXTRA_LIBS[@]}"
touch libpjproject_is_broken
fi
popd
}

function pkgconfig_ios {
BASEPATH="$1"
PCPATH="${BASEPATH}/lib/pkgconfig"
mkdir -p "${PCPATH}"
PCFILE="${BASEPATH}/lib/pkgconfig/libpjproject.pc"
cat << 'EOF' > "${PCFILE}"
Name: libpjproject
Description: Multimedia communication library
URL: http://www.pjsip.org
EOF

cat << EOF >> "${PCFILE}"
Version: ${PJPROJECT_VERSION}
Libs: -L$(realpath "${BASEPATH}"/lib) -lpjproject -framework CFNetwork -framework UIKit -framework Foundation -framework Security -framework Network -framework AVFoundation -framework CoreMedia -framework CoreAudio -framework CoreVideo -framework AudioToolbox -framework VideoToolbox
Cflags: -I$(realpath "${BASEPATH}"/include) -DPJ_AUTOCONF=1 -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1
EOF
}

function pkgconfig_macos {
BASEPATH="$1"
PCPATH="${BASEPATH}/lib/pkgconfig"
mkdir -p "${PCPATH}"
PCFILE="${BASEPATH}/lib/pkgconfig/libpjproject.pc"
cat << 'EOF' > "${PCFILE}"
Name: libpjproject
Description: Multimedia communication library
URL: http://www.pjsip.org
EOF

cat << EOF >> "${PCFILE}"
Version: ${PJPROJECT_VERSION}
Libs: -L$(realpath "${BASEPATH}"/lib) -lpjproject -framework Carbon -framework AppKit -framework Security -framework Network -framework AVFoundation -framework CoreMedia -framework CoreAudio -framework CoreVideo -framework AudioToolbox -framework VideoToolbox -framework Metal -framework IOKit
Cflags: -I$(realpath "${BASEPATH}"/include) -DPJ_AUTOCONF=1 -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1
EOF
}
31 changes: 31 additions & 0 deletions scripts/build-pjproject-ios-arm64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Oliver Epper <[email protected]>

source "$(dirname "$0")"/build-pjproject-darwin-base.sh

PREFIX="${PREFIX}/ios-arm64"
rm -rf "${PREFIX}"

pushd pjproject || exit 1
prepare YES

OPUS=("$(pwd)"/../../installed/opus/ios-arm64)
OPUS_LATEST=${OPUS[${#OPUS[@]} - 1]}
if [[ -d "${OPUS_LATEST}" ]]
then
CONFIGURE_EXTRA_PARAMS+=("--with-opus=${OPUS_LATEST}")
fi

SDKPATH=$(xcrun -sdk iphoneos --show-sdk-path)
ARCH="arm64"
CFLAGS="-isysroot $SDKPATH -miphoneos-version-min=13 -DPJ_SDK_NAME=\"\\\"$(basename "$SDKPATH")\\\"\" -arch $ARCH" \
LDFLAGS="-isysroot $SDKPATH -framework AudioToolbox -framework Foundation -framework Network -framework Security -arch $ARCH" \
./aconfigure --prefix="${PREFIX}" --host="${ARCH}"-apple-darwin_ios "${CONFIGURE_EXTRA_PARAMS[@]}" --disable-sdl

make dep && make clean
make
make install

create_lib "${PREFIX}/lib"
pkgconfig_ios "${PREFIX}"
popd || exit 1
Loading

0 comments on commit fce2a59

Please sign in to comment.