libhevc-mirror/cmake/utils.cmake
Harish Mahendrakar 4a8c3163e3
Some checks failed
CMake / build (cmake, aarch64-linux-gnu-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch64_toolchain.cmake, aarch64-linux-gnu-g++, ubuntu-latest-cross-aarch64-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, arm-linux-gnueabihf-gcc, -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/aarch32_toolchain.cmake, arm-linux-gnueabihf-g++, ubuntu-latest-cross-aarch32-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, macos-latest-clang-cmake, macos-latest) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-24.04-arm-clang-cmake, ubuntu-24.04-arm) (push) Has been cancelled
CMake / build (cmake, clang, , clang++, ubuntu-latest-clang-cmake, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -DSANITIZE=fuzzer-no-link,address, clang++, ubuntu-latest-clang-cmake-asan-fuzzer, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, clang, -G Ninja, clang++, ubuntu-latest-clang-cmake-ninja, ubuntu-latest) (push) Has been cancelled
CMake / build (cmake, gcc, , g++, ubuntu-latest-gcc-cmake, ubuntu-latest) (push) Has been cancelled
Add initial tests for decoder and encoder
Encoder tests currently do not dump recon as ihevce_plugin doesn't yet support recon dump.
This will be enabled once the recon dump is supported.

Decoder tests currently validate just a few files from big buck bunny.

Use "ctest" run all the tests when using cmake.
This downloads the required media files and uses them in the tests.

If running the tests directly using the test binaries, then download the media files
and export HEVC_TEST_DIR to the extracted folder before running the binaries directly.
2026-07-27 13:15:45 -07:00

160 lines
5.1 KiB
CMake

include(CheckCXXCompilerFlag)
# Adds compiler options for all targets
function(libhevc_add_compile_options)
if("${SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${SYSTEM_PROCESSOR}" STREQUAL "arm64")
add_compile_options(-march=armv8-a)
elseif("${SYSTEM_PROCESSOR}" STREQUAL "aarch32")
add_compile_options(-march=armv7-a -mfpu=neon -marm)
else()
add_compile_options(-msse4.2 -mno-avx)
endif()
set(CMAKE_REQUIRED_FLAGS -fsanitize=fuzzer-no-link)
check_cxx_compiler_flag(-fsanitize=fuzzer-no-link
COMPILER_HAS_SANITIZE_FUZZER)
unset(CMAKE_REQUIRED_FLAGS)
if(DEFINED SANITIZE)
set(CMAKE_REQUIRED_FLAGS -fsanitize=${SANITIZE})
check_cxx_compiler_flag(-fsanitize=${SANITIZE} COMPILER_HAS_SANITIZER)
unset(CMAKE_REQUIRED_FLAGS)
if(NOT COMPILER_HAS_SANITIZER)
message(
FATAL_ERROR "ERROR: Compiler doesn't support -fsanitize=${SANITIZE}")
return()
endif()
add_compile_options(-fno-omit-frame-pointer -fsanitize=${SANITIZE})
endif()
if(ENABLE_COVERAGE)
add_compile_options(--coverage)
endif()
endfunction()
# Adds defintions for all targets
function(libhevc_add_definitions)
if("${SYSTEM_NAME}" STREQUAL "Darwin")
if("${SYSTEM_PROCESSOR}" STREQUAL "arm64")
add_definitions(-DARMV8 -DDARWIN -DDEFAULT_ARCH=D_ARCH_ARMV8_GENERIC)
else()
add_definitions(-DX86 -DDARWIN -DDISABLE_AVX2 -DDEFAULT_ARCH=D_ARCH_X86_GENERIC)
endif()
elseif("${SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${SYSTEM_PROCESSOR}" STREQUAL "arm64")
add_definitions(-DARMV8 -DDEFAULT_ARCH=D_ARCH_ARMV8_GENERIC -DENABLE_NEON)
elseif("${SYSTEM_PROCESSOR}" STREQUAL "aarch32")
add_definitions(-DARMV7 -DDEFAULT_ARCH=D_ARCH_ARM_A9Q -DENABLE_NEON
-DDISABLE_NEONINTR)
else()
add_definitions(-DX86 -DX86_LINUX=1 -DDISABLE_AVX2
-DDEFAULT_ARCH=D_ARCH_X86_SSE42)
endif()
endfunction()
# Adds libraries needed for executables
function(libhevc_set_link_libraries)
if(ENABLE_COVERAGE)
link_libraries(Threads::Threads m --coverage)
else()
link_libraries(Threads::Threads m)
endif()
endfunction()
# cmake-format: off
# Adds a target for an executable
#
# Arguments:
# NAME: Name of the executatble
# LIB: Library that executable depends on
# SOURCES: Source files
#
# Optional Arguments:
# INCLUDES: Include paths
# LIBS: Additional libraries
# FUZZER: flag to specify if the target is a fuzzer binary
# cmake-format: on
function(libhevc_add_executable NAME LIB)
set(multi_value_args SOURCES INCLUDES LIBS)
set(optional_args FUZZER)
cmake_parse_arguments(ARG "${optional_args}" "${single_value_args}"
"${multi_value_args}" ${ARGN})
# Check if compiler supports -fsanitize=fuzzer. If not, skip building fuzzer
# binary
if(ARG_FUZZER)
if(NOT COMPILER_HAS_SANITIZE_FUZZER)
message("Compiler doesn't support -fsanitize=fuzzer. Skipping ${NAME}")
return()
endif()
endif()
add_executable(${NAME} ${ARG_SOURCES})
target_include_directories(${NAME} PRIVATE ${ARG_INCLUDES})
add_dependencies(${NAME} ${LIB} ${ARG_LIBS})
target_link_libraries(${NAME} ${LIB} ${ARG_LIBS})
if(ARG_FUZZER)
target_compile_options(${NAME}
PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>)
if(DEFINED ENV{LIB_FUZZING_ENGINE})
set_target_properties(${NAME} PROPERTIES LINK_FLAGS
$ENV{LIB_FUZZING_ENGINE})
elseif(DEFINED SANITIZE)
set_target_properties(${NAME} PROPERTIES LINK_FLAGS
-fsanitize=fuzzer,${SANITIZE})
else()
set_target_properties(${NAME} PROPERTIES LINK_FLAGS -fsanitize=fuzzer)
endif()
else()
if(DEFINED SANITIZE)
set_target_properties(${NAME} PROPERTIES LINK_FLAGS
-fsanitize=${SANITIZE})
endif()
endif()
endfunction()
# cmake-format: off
# Adds a target for a fuzzer binary
# Calls libhevc_add_executable with all arguments with FUZZER set to 1
# Arguments:
# Refer to libhevc_add_executable's arguments
# cmake-format: on
function(libhevc_add_fuzzer NAME LIB)
libhevc_add_executable(${NAME} ${LIB} FUZZER 1 ${ARGV})
endfunction()
# Adds GoogleTest and Threads dependency
function(libhevc_add_gtest)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endfunction()
# cmake-format: off
# Adds a target for a gtest executable
#
# Arguments:
# NAME: Name of the executable
#
# Optional Arguments:
# SOURCES: Additional source files
# cmake-format: on
function(libhevc_add_gtest_executable NAME)
set(multi_value_args SOURCES)
cmake_parse_arguments(ARG "" "" "${multi_value_args}" ${ARGN})
libhevc_add_executable(
${NAME} libhevcdec
SOURCES ${HEVC_ROOT}/tests/common/func_selector.cc
${HEVC_ROOT}/tests/common/TestCommon.cc ${ARG_SOURCES}
LIBS GTest::gtest_main)
add_test(NAME ${NAME} COMMAND ${NAME})
endfunction()