Skip to content

Commit

Permalink
ci: link shared library build against static local dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
fdintino committed Sep 12, 2023
1 parent fac3bae commit 4783dcb
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-disable-gtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ext
key: ${{ runner.os }}-disable-gtest-${{ hashFiles('ext/*.cmd') }}
key: ${{ runner.os }}-disable-gtest-${{ hashFiles('CMakeLists.txt', 'ext/*.cmd') }}
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@187efd9581ed20ee4e03c0dfb9ac2cd5896c4835 # v1.14.1
with:
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/ci-unix-shared-installed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ jobs:
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ext
key: ${{ runner.os }}-shared-installed-${{ hashFiles('ext/*.cmd') }}
key: ${{ runner.os }}-shared-installed-${{ hashFiles('CMakeLists.txt', 'ext/*.cmd') }}
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@187efd9581ed20ee4e03c0dfb9ac2cd5896c4835 # v1.14.1
with:
cmake-version: '3.13.x'
- name: Print cmake version
run: cmake --version
- uses: seanmiddleditch/gha-setup-ninja@16b940825621068d98711680b6c3ff92201f8fc0 # v3
- name: Set shared libs
if: steps.cache-ext.outputs.cache-hit != 'true'
working-directory: ./ext
run: sed -i'' -e 's/-DBUILD_SHARED_LIBS=OFF/-DBUILD_SHARED_LIBS=ON/' *.cmd
- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: |
Expand Down
11 changes: 1 addition & 10 deletions .github/workflows/ci-unix-shared-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ext
key: ${{ runner.os }}-shared-local-${{ hashFiles('ext/*.cmd') }}
key: ${{ runner.os }}-shared-local-${{ hashFiles('CMakeLists.txt', 'ext/*.cmd') }}
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@187efd9581ed20ee4e03c0dfb9ac2cd5896c4835 # v1.14.1
with:
Expand All @@ -46,15 +46,6 @@ jobs:
- run: pip install meson
- name: Print ImageMagick version
run: convert --version
- name: Set shared libs
if: steps.cache-ext.outputs.cache-hit != 'true'
working-directory: ./ext
run: >
sed -i'' -e 's/-DBUILD_SHARED_LIBS=OFF/-DBUILD_SHARED_LIBS=ON/' *.cmd
sed -i'' -e 's/--default-library=static/--default-library=shared/' dav1d.cmd
sed -i'' -e 's/ninja yuv/ninja yuv_shared/' libyuv.cmd
- name: Build aom
if: steps.cache-ext.outputs.cache-hit != 'true'
working-directory: ./ext
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-unix-static-av2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ext
key: ${{ runner.os }}-static-av2-${{ hashFiles('ext/*.cmd') }}
key: ${{ runner.os }}-static-av2-${{ hashFiles('CMakeLists.txt', 'ext/*.cmd') }}
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@187efd9581ed20ee4e03c0dfb9ac2cd5896c4835 # v1.14.1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-unix-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ext
key: ${{ runner.os }}-${{ runner.build-type }}-${{ hashFiles('ext/*.cmd') }}
key: ${{ runner.os }}-${{ runner.build-type }}-${{ hashFiles('CMakeLists.txt', 'ext/*.cmd') }}
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@187efd9581ed20ee4e03c0dfb9ac2cd5896c4835 # v1.14.1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ext
key: ${{ runner.os }}-${{ hashFiles('ext/*.cmd') }}
key: ${{ runner.os }}-${{ hashFiles('CMakeLists.txt', 'ext/*.cmd') }}
- name: Print cmake version
run: cmake --version
- uses: ilammy/setup-nasm@321e6ed62a1fc77024a3bd853deb33645e8b22c4 # v1.4.0
Expand Down
31 changes: 11 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ endif()

if(BUILD_SHARED_LIBS)
set(AVIF_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}")
set(AVIF_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}")
else()
set(AVIF_LIBRARY_PREFIX "${CMAKE_STATIC_LIBRARY_PREFIX}")
set(AVIF_LIBRARY_SUFFIX "${CMAKE_STATIC_LIBRARY_SUFFIX}")
# This is needed to get shared libraries (e.g. pixbufloader-avif) to compile against a static libavif.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
Expand Down Expand Up @@ -118,7 +116,7 @@ if(AVIF_LOCAL_ZLIBPNG)
set(PREV_ANDROID ${ANDROID})
set(ANDROID TRUE)
set(PNG_BUILD_ZLIB "${CMAKE_CURRENT_SOURCE_DIR}/ext/zlib" CACHE STRING "" FORCE)
set(PNG_SHARED ${BUILD_SHARED_LIBS} CACHE BOOL "")
set(PNG_SHARED OFF CACHE BOOL "")
set(PNG_TESTS OFF CACHE BOOL "")
add_subdirectory(ext/libpng)
set(PNG_PNG_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/libpng")
Expand All @@ -141,7 +139,7 @@ if(AVIF_LOCAL_JPEG)
endif()
option(AVIF_LOCAL_LIBYUV "Build libyuv by providing your own copy inside the ext subdir." OFF)
if(AVIF_LOCAL_LIBYUV)
set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/libyuv/build/${AVIF_LIBRARY_PREFIX}yuv${AVIF_LIBRARY_SUFFIX}")
set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/libyuv/build/${AVIF_LIBRARY_PREFIX}yuv${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif(AVIF_LOCAL_LIBYUV): ${LIB_FILENAME} is missing, bailing out")
endif()
Expand All @@ -152,13 +150,6 @@ if(AVIF_LOCAL_LIBYUV)
set(LIBYUV_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/libyuv/include" PARENT_SCOPE)
set(LIBYUV_LIBRARY ${LIB_FILENAME} PARENT_SCOPE)
endif()
if(BUILD_SHARED_LIBS)
# Fix "libyuv.so: undefined reference to `jpeg_read_raw_data'" errors.
if(NOT AVIF_LOCAL_JPEG)
find_package(JPEG REQUIRED)
endif()
set(LIBYUV_LIBRARY ${LIBYUV_LIBRARY} ${JPEG_LIBRARY})
endif()
set(libyuv_FOUND TRUE)
message(STATUS "libavif: local libyuv found; libyuv-based fast paths enabled.")
else(AVIF_LOCAL_LIBYUV)
Expand Down Expand Up @@ -190,7 +181,7 @@ if(libyuv_FOUND)
endif(libyuv_FOUND)
option(AVIF_LOCAL_LIBSHARPYUV "Build libsharpyuv by providing your own copy inside the ext subdir." OFF)
if(AVIF_LOCAL_LIBSHARPYUV)
set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/libwebp/build/libsharpyuv${AVIF_LIBRARY_SUFFIX}")
set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/libwebp/build/libsharpyuv${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif(AVIF_LOCAL_LIBSHARPYUV): ${LIB_FILENAME} is missing, bailing out")
endif()
Expand Down Expand Up @@ -326,16 +317,16 @@ if(AVIF_CODEC_DAV1D)
if(DEFINED ANDROID_ABI)
set(AVIF_DAV1D_BUILD_DIR "${AVIF_DAV1D_BUILD_DIR}/${ANDROID_ABI}")
endif()
set(LIB_FILENAME "${AVIF_DAV1D_BUILD_DIR}/src/libdav1d${AVIF_LIBRARY_SUFFIX}")
set(LIB_FILENAME "${AVIF_DAV1D_BUILD_DIR}/src/libdav1d${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(NOT EXISTS "${LIB_FILENAME}")
if("${AVIF_LIBRARY_SUFFIX}" STREQUAL ".a")
if("${CMAKE_STATIC_LIBRARY_SUFFIX}" STREQUAL ".a")
message(FATAL_ERROR "libavif: ${LIB_FILENAME} is missing, bailing out")
else()
# On windows, meson will produce a libdav1d.a instead of the expected libdav1d.dll/.lib.
# See https://github.com/mesonbuild/meson/issues/8153.
set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/dav1d/build/src/libdav1d.a")
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif: ${LIB_FILENAME} (or libdav1d${AVIF_LIBRARY_SUFFIX}) is missing, bailing out")
message(FATAL_ERROR "libavif: ${LIB_FILENAME} (or libdav1d${CMAKE_STATIC_LIBRARY_SUFFIX}) is missing, bailing out")
endif()
endif()
endif()
Expand Down Expand Up @@ -370,7 +361,7 @@ if(AVIF_CODEC_LIBGAV1)
if(DEFINED ANDROID_ABI)
set(AVIF_LIBGAV1_BUILD_DIR "${AVIF_LIBGAV1_BUILD_DIR}/${ANDROID_ABI}")
endif()
set(LIB_FILENAME "${AVIF_LIBGAV1_BUILD_DIR}/libgav1${AVIF_LIBRARY_SUFFIX}")
set(LIB_FILENAME "${AVIF_LIBGAV1_BUILD_DIR}/libgav1${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif: ${LIB_FILENAME} is missing, bailing out")
endif()
Expand All @@ -395,7 +386,7 @@ if(AVIF_CODEC_RAV1E)

if(AVIF_LOCAL_RAV1E)
set(LIB_FILENAME
"${CMAKE_CURRENT_SOURCE_DIR}/ext/rav1e/build.libavif/usr/lib/${AVIF_LIBRARY_PREFIX}rav1e${AVIF_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_SOURCE_DIR}/ext/rav1e/build.libavif/usr/lib/${AVIF_LIBRARY_PREFIX}rav1e${CMAKE_STATIC_LIBRARY_SUFFIX}"
)
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif: compiled rav1e library is missing (in ext/rav1e/build.libavif/usr/lib), bailing out")
Expand Down Expand Up @@ -428,7 +419,7 @@ if(AVIF_CODEC_SVT)

if(AVIF_LOCAL_SVT)
set(LIB_FILENAME
"${CMAKE_CURRENT_SOURCE_DIR}/ext/SVT-AV1/Bin/Release/${AVIF_LIBRARY_PREFIX}SvtAv1Enc${AVIF_LIBRARY_SUFFIX}"
"${CMAKE_CURRENT_SOURCE_DIR}/ext/SVT-AV1/Bin/Release/${AVIF_LIBRARY_PREFIX}SvtAv1Enc${CMAKE_STATIC_LIBRARY_SUFFIX}"
)
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif: compiled svt library is missing (in ext/SVT-AV1/Bin/Release), bailing out")
Expand Down Expand Up @@ -467,7 +458,7 @@ if(AVIF_CODEC_AOM)
endif()
set(AVIF_SRCS ${AVIF_SRCS} src/codec_aom.c)
if(AVIF_LOCAL_AOM)
set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/aom/build.libavif/${AVIF_LIBRARY_PREFIX}aom${AVIF_LIBRARY_SUFFIX}")
set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/aom/build.libavif/${AVIF_LIBRARY_PREFIX}aom${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif: ${LIB_FILENAME} is missing, bailing out")
endif()
Expand Down Expand Up @@ -499,7 +490,7 @@ if(AVIF_CODEC_AVM)
set(AVIF_SRCS ${AVIF_SRCS} src/codec_avm.c)
if(AVIF_LOCAL_AVM)
# Building the avm repository generates files such as "libaom.a" because it is a fork of aom.
set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/avm/build.libavif/${AVIF_LIBRARY_PREFIX}aom${AVIF_LIBRARY_SUFFIX}")
set(LIB_FILENAME "${CMAKE_CURRENT_SOURCE_DIR}/ext/avm/build.libavif/${AVIF_LIBRARY_PREFIX}aom${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(NOT EXISTS "${LIB_FILENAME}")
message(FATAL_ERROR "libavif: ${LIB_FILENAME} (from avm) is missing, bailing out")
endif()
Expand Down
2 changes: 1 addition & 1 deletion ext/libyuv.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ git checkout 464c51a0
mkdir build
cd build

cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF ..
ninja yuv
cd ../..
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ add_test(NAME repro_avif_decode_fuzzer COMMAND repro_avif_decode_fuzzer
if(AVIF_ENABLE_GTEST)
if(AVIF_LOCAL_GTEST)
set(GTEST_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/ext/googletest/googletest/include)
set(GTEST_LIBRARIES ${CMAKE_SOURCE_DIR}/ext/googletest/build/lib/${AVIF_LIBRARY_PREFIX}gtest${AVIF_LIBRARY_SUFFIX})
set(GTEST_LIBRARIES ${CMAKE_SOURCE_DIR}/ext/googletest/build/lib/${AVIF_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX})
set(GTEST_MAIN_LIBRARIES
${CMAKE_SOURCE_DIR}/ext/googletest/build/lib/${AVIF_LIBRARY_PREFIX}gtest_main${AVIF_LIBRARY_SUFFIX}
${CMAKE_SOURCE_DIR}/ext/googletest/build/lib/${AVIF_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX}
)
set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
if(NOT EXISTS ${GTEST_INCLUDE_DIRS}/gtest/gtest.h)
Expand Down

0 comments on commit 4783dcb

Please sign in to comment.