Skip to content

Commit

Permalink
Merge pull request #6 from RyeMutt/rye/universal
Browse files Browse the repository at this point in the history
Add macOS universal library build support
  • Loading branch information
RyeMutt authored Nov 22, 2024
2 parents 37fac3d + d9150d9 commit 693348d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 63 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ jobs:
build:
strategy:
matrix:
os: [windows-2022, macos-12, ubuntu-22.04]
os: [windows-2022, macos-15, ubuntu-22.04]
addrsize: ["64"]
include:
- os: windows-2022
addrsize: "32"
runs-on: ${{ matrix.os }}
steps:
- name: Setup Homebrew Packages
if: ${{ runner.os == 'macOS' }}
shell: bash
run: brew install ninja
- name: Setup Linux Build Dependencies
if: ${{ runner.os == 'Linux' }}
shell: bash
run: sudo apt-get install libwebp-dev
- uses: secondlife/action-autobuild@v4
run: |
sudo apt-get update
sudo apt-get -y install ninja-build libwebp-dev
- uses: secondlife/action-autobuild@v5
with:
addrsize: ${{ matrix.addrsize }}
release:
Expand Down
139 changes: 79 additions & 60 deletions build-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,18 @@ set -u

OPENJPEG_SOURCE_DIR="openjpeg"

if false
then
openjpeg="openjpeg"
verfile="$openjpeg/CMakeLists.txt"
OPENJPEG_VERSION_MAJOR="$(sed -n -E '/^.*OPENJPEG_VERSION_MAJOR ([0-9]+)\)/s//\1/p' "$verfile")"
OPENJPEG_VERSION_MINOR="$(sed -n -E '/^.*OPENJPEG_VERSION_MINOR ([0-9]+)\)/s//\1/p' "$verfile")"
OPENJPEG_VERSION_BUILD="$(sed -n -E '/^.*OPENJPEG_VERSION_BUILD ([0-9]+)\)/s//\1/p' "$verfile")"
OPENJPEG_VERSION="$OPENJPEG_VERSION_MAJOR.$OPENJPEG_VERSION_MINOR.$OPENJPEG_VERSION_BUILD"
else # openjpeg 2.0+
openjpeg="openjp2"
verfile="openjpeg/CMakeLists.txt"
OPENJPEG_VERSION_MAJOR="$(sed -n -E '/^.*OPENJPEG_VERSION_MAJOR ([0-9]+)\)/s//\1/p' "$verfile")"
OPENJPEG_VERSION_MINOR="$(sed -n -E '/^.*OPENJPEG_VERSION_MINOR ([0-9]+)\)/s//\1/p' "$verfile")"
OPENJPEG_VERSION_BUILD="$(sed -n -E '/^.*OPENJPEG_VERSION_BUILD ([0-9]+)\)/s//\1/p' "$verfile")"
OPENJPEG_VERSION="$OPENJPEG_VERSION_MAJOR.$OPENJPEG_VERSION_MINOR.$OPENJPEG_VERSION_BUILD"
fi

if [ -z "$AUTOBUILD" ] ; then
openjpeg="openjp2"
verfile="openjpeg/CMakeLists.txt"
OPENJPEG_VERSION_MAJOR="$(sed -n -E '/^.*OPENJPEG_VERSION_MAJOR ([0-9]+)\)/s//\1/p' "$verfile")"
OPENJPEG_VERSION_MINOR="$(sed -n -E '/^.*OPENJPEG_VERSION_MINOR ([0-9]+)\)/s//\1/p' "$verfile")"
OPENJPEG_VERSION_BUILD="$(sed -n -E '/^.*OPENJPEG_VERSION_BUILD ([0-9]+)\)/s//\1/p' "$verfile")"
OPENJPEG_VERSION="$OPENJPEG_VERSION_MAJOR.$OPENJPEG_VERSION_MINOR.$OPENJPEG_VERSION_BUILD"

if [ -z "$AUTOBUILD" ] ; then
exit 1
fi

if [ "$OSTYPE" = "cygwin" ] ; then
if [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" ]] ; then
autobuild="$(cygpath -u $AUTOBUILD)"
else
autobuild="$AUTOBUILD"
Expand Down Expand Up @@ -85,52 +75,81 @@ pushd "$OPENJPEG_SOURCE_DIR"
;;

darwin*)
cmake . -GXcode -D'CMAKE_OSX_ARCHITECTURES:STRING=$AUTOBUILD_CONFIGURE_ARCH' \
-D'BUILD_SHARED_LIBS:bool=off' -D'BUILD_CODEC:bool=off' \
-DCMAKE_INSTALL_PREFIX=$stage \
-DCMAKE_C_FLAGS="$(remove_cxxstd $LL_BUILD_RELEASE)"
xcodebuild -configuration Release -target $openjpeg -project openjpeg.xcodeproj
xcodebuild -configuration Release -target install -project openjpeg.xcodeproj
mkdir -p "$stage/lib/release"
mkdir -p "$stage/include/openjpeg"
# As of openjpeg 2.0, build products are now installed into
# directories with version-stamped names. The actual pathname can
# be found in install_manifest.txt.
mv -v "$(grep "/libopenjp2.a$" install_manifest.txt)" "$stage/lib/release/libopenjp2.a"

cp src/lib/$openjpeg/*.h "$stage/include/openjpeg/"
export MACOSX_DEPLOYMENT_TARGET="$LL_BUILD_DARWIN_DEPLOY_TARGET"

for arch in x86_64 arm64 ; do
ARCH_ARGS="-arch $arch"
opts="${TARGET_OPTS:-$ARCH_ARGS $LL_BUILD_RELEASE}"
cc_opts="$(remove_cxxstd $opts)"
cc_opts="$(remove_switch -stdlib=libc++ $cc_opts)"
ld_opts="$ARCH_ARGS"

mkdir -p "build_$arch"
pushd "build_$arch"
CFLAGS="$cc_opts" \
CXXFLAGS="$opts" \
LDFLAGS="$ld_opts" \
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_CODEC=OFF \
-DCMAKE_C_FLAGS="$cc_opts" \
-DCMAKE_CXX_FLAGS="$opts" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$stage" \
-DCMAKE_INSTALL_LIBDIR="$stage/lib/release/$arch" \
-DCMAKE_OSX_ARCHITECTURES:STRING="$arch" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}

cmake --build . --config Release
cmake --install . --config Release

# conditionally run unit tests
if [ "${DISABLE_UNIT_TESTS:-0}" = "0" ]; then
ctest -C Release
fi
popd
done

# Create universal library
lipo -create -output "$stage/lib/release/libopenjp2.a" "$stage/lib/release/x86_64/libopenjp2.a" "$stage/lib/release/arm64/libopenjp2.a"

# Rename to unversioned include dir
mv "$stage"/include/openjpeg-2.5 "$stage"/include/openjpeg
;;

linux*)
# Force 4.6
#export CC=gcc-4.6
#export CXX=g++-4.6

# Inhibit '--sysroot' nonsense
export CPPFLAGS=""

cmake -G"Unix Makefiles" \
-DCMAKE_INSTALL_PREFIX="$stage" \
-DBUILD_SHARED_LIBS:bool=off \
-DCMAKE_INSTALL_DEBUG_LIBRARIES=1 \
-DCMAKE_C_FLAGS="$(remove_cxxstd $LL_BUILD_RELEASE)" .
# From 1.4.0:
# CFLAGS="-m32" CPPFLAGS="-m32" LDFLAGS="-m32" ./configure --target=i686-linux-gnu --prefix="$stage" --enable-png=no --enable-lcms1=no --enable-lcms2=no --enable-tiff=no
make
make install
# conditionally run unit tests
if [ "${DISABLE_UNIT_TESTS:-0}" = "0" ]; then
echo "No unit tests yet"
opts="${TARGET_OPTS:--m$AUTOBUILD_ADDRSIZE $LL_BUILD_RELEASE}"
plainopts="$(remove_cxxstd $opts)"

# Handle any deliberate platform targeting
if [ -z "${TARGET_CPPFLAGS:-}" ]; then
# Remove sysroot contamination from build environment
unset CPPFLAGS
else
# Incorporate special pre-processing flags
export CPPFLAGS="$TARGET_CPPFLAGS"
fi

mkdir -p "$stage/lib/release"
mkdir -p "$stage/include/openjpeg"
# As of openjpeg 2.0, build products are now installed into
# directories with version-stamped names. The actual pathname can
# be found in install_manifest.txt.
mv -v "$(grep "/libopenjp2.a$" install_manifest.txt)" "$stage/lib/release/libopenjp2.a"

cp src/lib/$openjpeg/*.h "$stage/include/openjpeg/"
mkdir -p "build"
pushd "build"
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$stage" \
-DCMAKE_INSTALL_LIBDIR="$stage/lib/release" \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_C_FLAGS="$plainopts" \
-DCMAKE_CXX_FLAGS="$opts"

cmake --build . --config Release
cmake --install . --config Release

# conditionally run unit tests
if [ "${DISABLE_UNIT_TESTS:-0}" = "0" ]; then
ctest -C Release
fi
popd

# Rename to unversioned include dir
mv "$stage"/include/openjpeg-2.5 "$stage"/include/openjpeg
;;
esac
mkdir -p "$stage/LICENSES"
Expand Down

0 comments on commit 693348d

Please sign in to comment.