mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2025-12-08 01:36:47 +08:00
When `libyuv` is built with `jpeg` support it does not directly link
`libjpeg` in any form. As a result dynamic loading of the library
fails as:
>>> import pillow_avif._avif
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/lib/libyuv.so: undefined symbol: jpeg_resync_to_restart
We can reproduce the same problem at build time if we build `libyuv` with
`LDFLAGS=-Wl,--no-undefined`:
[ 99%] Linking CXX executable yuvconstants
ld: CMakeFiles/yuv_shared.dir/source/mjpeg_decoder.cc.o: in function `libyuv::MJpegDecoder::MJpegDecoder()':
mjpeg_decoder.cc:(.text+0xfc): undefined reference to `jpeg_resync_to_restart'
ld: mjpeg_decoder.cc:(.text+0x136): undefined reference to `jpeg_std_error'
ld: mjpeg_decoder.cc:(.text+0x194): undefined reference to `jpeg_CreateDecompress'
The change links `libgpeg` against `libyuv` itself to make it a
self-contained library. This fixes both loading if the library
itself and fixes linking of the library against other binaries
without explicit need for passing `-ljpeg`.
Change-Id: I044acb3799920e1536bdb3388442a40d4839348b
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/4050883
Reviewed-by: Frank Barchard <fbarchard@chromium.org>
Reviewed-by: Mirko Bonadei <mbonadei@chromium.org>
Commit-Queue: Frank Barchard <fbarchard@chromium.org>
102 lines
3.5 KiB
CMake
102 lines
3.5 KiB
CMake
# CMakeLists for libyuv
|
|
# Originally created for "roxlu build system" to compile libyuv on windows
|
|
# Run with -DTEST=ON to build unit tests
|
|
|
|
PROJECT ( YUV C CXX ) # "C" is required even for C++ projects
|
|
CMAKE_MINIMUM_REQUIRED( VERSION 2.8.12 )
|
|
OPTION( TEST "Built unit tests" OFF )
|
|
|
|
SET ( ly_base_dir ${PROJECT_SOURCE_DIR} )
|
|
SET ( ly_src_dir ${ly_base_dir}/source )
|
|
SET ( ly_inc_dir ${ly_base_dir}/include )
|
|
SET ( ly_tst_dir ${ly_base_dir}/unit_test )
|
|
SET ( ly_lib_name yuv )
|
|
SET ( ly_lib_static ${ly_lib_name} )
|
|
SET ( ly_lib_shared ${ly_lib_name}_shared )
|
|
|
|
FILE ( GLOB_RECURSE ly_source_files ${ly_src_dir}/*.cc )
|
|
LIST ( SORT ly_source_files )
|
|
|
|
FILE ( GLOB_RECURSE ly_unittest_sources ${ly_tst_dir}/*.cc )
|
|
LIST ( SORT ly_unittest_sources )
|
|
|
|
INCLUDE_DIRECTORIES( BEFORE ${ly_inc_dir} )
|
|
|
|
if(MSVC)
|
|
ADD_DEFINITIONS ( -D_CRT_SECURE_NO_WARNINGS )
|
|
endif()
|
|
|
|
# this creates the static library (.a)
|
|
ADD_LIBRARY ( ${ly_lib_static} STATIC ${ly_source_files} )
|
|
|
|
# this creates the shared library (.so)
|
|
ADD_LIBRARY ( ${ly_lib_shared} SHARED ${ly_source_files} )
|
|
SET_TARGET_PROPERTIES ( ${ly_lib_shared} PROPERTIES OUTPUT_NAME "${ly_lib_name}" )
|
|
SET_TARGET_PROPERTIES ( ${ly_lib_shared} PROPERTIES PREFIX "lib" )
|
|
if(WIN32)
|
|
SET_TARGET_PROPERTIES ( ${ly_lib_shared} PROPERTIES IMPORT_PREFIX "lib" )
|
|
endif()
|
|
|
|
# this creates the conversion tool
|
|
ADD_EXECUTABLE ( yuvconvert ${ly_base_dir}/util/yuvconvert.cc )
|
|
TARGET_LINK_LIBRARIES ( yuvconvert ${ly_lib_static} )
|
|
|
|
# this creates the yuvconstants tool
|
|
ADD_EXECUTABLE ( yuvconstants ${ly_base_dir}/util/yuvconstants.c )
|
|
TARGET_LINK_LIBRARIES ( yuvconstants ${ly_lib_static} )
|
|
|
|
find_package ( JPEG )
|
|
if (JPEG_FOUND)
|
|
include_directories( ${JPEG_INCLUDE_DIR} )
|
|
target_link_libraries( ${ly_lib_shared} ${JPEG_LIBRARY} )
|
|
add_definitions( -DHAVE_JPEG )
|
|
endif()
|
|
|
|
if(TEST)
|
|
find_library(GTEST_LIBRARY gtest)
|
|
if(GTEST_LIBRARY STREQUAL "GTEST_LIBRARY-NOTFOUND")
|
|
set(GTEST_SRC_DIR /usr/src/gtest CACHE STRING "Location of gtest sources")
|
|
if(EXISTS ${GTEST_SRC_DIR}/src/gtest-all.cc)
|
|
message(STATUS "building gtest from sources in ${GTEST_SRC_DIR}")
|
|
set(gtest_sources ${GTEST_SRC_DIR}/src/gtest-all.cc)
|
|
add_library(gtest STATIC ${gtest_sources})
|
|
include_directories(${GTEST_SRC_DIR})
|
|
include_directories(${GTEST_SRC_DIR}/include)
|
|
set(GTEST_LIBRARY gtest)
|
|
else()
|
|
message(FATAL_ERROR "TEST is set but unable to find gtest library")
|
|
endif()
|
|
endif()
|
|
|
|
add_executable(libyuv_unittest ${ly_unittest_sources})
|
|
target_link_libraries(libyuv_unittest ${ly_lib_name} ${GTEST_LIBRARY})
|
|
find_library(PTHREAD_LIBRARY pthread)
|
|
if(NOT PTHREAD_LIBRARY STREQUAL "PTHREAD_LIBRARY-NOTFOUND")
|
|
target_link_libraries(libyuv_unittest pthread)
|
|
endif()
|
|
if (JPEG_FOUND)
|
|
target_link_libraries(libyuv_unittest ${JPEG_LIBRARY})
|
|
endif()
|
|
|
|
if(NACL AND NACL_LIBC STREQUAL "newlib")
|
|
target_link_libraries(libyuv_unittest glibc-compat)
|
|
endif()
|
|
|
|
find_library(GFLAGS_LIBRARY gflags)
|
|
if(NOT GFLAGS_LIBRARY STREQUAL "GFLAGS_LIBRARY-NOTFOUND")
|
|
target_link_libraries(libyuv_unittest gflags)
|
|
add_definitions(-DLIBYUV_USE_GFLAGS)
|
|
endif()
|
|
endif()
|
|
|
|
|
|
# install the conversion tool, .so, .a, and all the header files
|
|
INSTALL ( PROGRAMS ${CMAKE_BINARY_DIR}/yuvconvert DESTINATION bin )
|
|
INSTALL ( TARGETS ${ly_lib_static} DESTINATION lib )
|
|
INSTALL ( TARGETS ${ly_lib_shared} LIBRARY DESTINATION lib RUNTIME DESTINATION bin )
|
|
INSTALL ( DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include )
|
|
|
|
# create the .deb and .rpm packages using cpack
|
|
INCLUDE ( CM_linux_packages.cmake )
|
|
|