87 lines
3.3 KiB
CMake
87 lines
3.3 KiB
CMake
cmake_minimum_required(VERSION 3.16)
|
|
project(fr LANGUAGES CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
# ── Source files ──────────────────────────────────────────────────────────────
|
|
|
|
add_executable(fr
|
|
main.cpp
|
|
frame_extractor.cpp
|
|
tiff_writer.cpp
|
|
platform_utils.cpp
|
|
)
|
|
|
|
# ── FFmpeg (libav) ────────────────────────────────────────────────────────────
|
|
#
|
|
# Strategy (in order of precedence):
|
|
# 1. pkg-config — works out of the box on most Linux/macOS (Homebrew) setups.
|
|
# 2. Manual paths via CMake cache variables FFMPEG_INCLUDE_DIR / FFMPEG_LIB_DIR.
|
|
# Useful on Windows (vcpkg, manual builds, etc.).
|
|
|
|
find_package(PkgConfig QUIET)
|
|
|
|
if(PkgConfig_FOUND)
|
|
pkg_check_modules(AVCODEC REQUIRED IMPORTED_TARGET libavcodec)
|
|
pkg_check_modules(AVFORMAT REQUIRED IMPORTED_TARGET libavformat)
|
|
pkg_check_modules(AVUTIL REQUIRED IMPORTED_TARGET libavutil)
|
|
pkg_check_modules(SWSCALE REQUIRED IMPORTED_TARGET libswscale)
|
|
|
|
target_link_libraries(fr PRIVATE
|
|
PkgConfig::AVCODEC
|
|
PkgConfig::AVFORMAT
|
|
PkgConfig::AVUTIL
|
|
PkgConfig::SWSCALE
|
|
)
|
|
else()
|
|
# ── Fallback: manual path configuration ──────────────────────────────────
|
|
# Set these variables when invoking CMake, e.g.:
|
|
# cmake -DFFMPEG_INCLUDE_DIR=C:/ffmpeg/include \
|
|
# -DFFMPEG_LIB_DIR=C:/ffmpeg/lib ..
|
|
|
|
set(FFMPEG_INCLUDE_DIR "" CACHE PATH "FFmpeg include directory")
|
|
set(FFMPEG_LIB_DIR "" CACHE PATH "FFmpeg library directory")
|
|
|
|
if(NOT FFMPEG_INCLUDE_DIR OR NOT FFMPEG_LIB_DIR)
|
|
message(FATAL_ERROR
|
|
"pkg-config not found and FFMPEG_INCLUDE_DIR / FFMPEG_LIB_DIR are not set.\n"
|
|
"Please install pkg-config or pass the FFmpeg paths manually.")
|
|
endif()
|
|
|
|
target_include_directories(fr PRIVATE "${FFMPEG_INCLUDE_DIR}")
|
|
|
|
foreach(_lib avcodec avformat avutil swscale)
|
|
find_library(_found_${_lib}
|
|
NAMES ${_lib}
|
|
PATHS "${FFMPEG_LIB_DIR}"
|
|
NO_DEFAULT_PATH
|
|
)
|
|
if(NOT _found_${_lib})
|
|
message(FATAL_ERROR "Could not find lib${_lib} in ${FFMPEG_LIB_DIR}")
|
|
endif()
|
|
target_link_libraries(fr PRIVATE "${_found_${_lib}}")
|
|
endforeach()
|
|
endif()
|
|
|
|
# ── Platform-specific adjustments ────────────────────────────────────────────
|
|
|
|
if(WIN32)
|
|
# Suppress MSVC warnings about C runtime functions and enable Unicode APIs
|
|
target_compile_definitions(fr PRIVATE
|
|
_CRT_SECURE_NO_WARNINGS
|
|
UNICODE
|
|
_UNICODE
|
|
)
|
|
endif()
|
|
|
|
if(APPLE)
|
|
# Silence deprecation warnings that FFmpeg headers can trigger on macOS
|
|
target_compile_options(fr PRIVATE -Wno-deprecated-declarations)
|
|
endif()
|
|
|
|
# ── Install ───────────────────────────────────────────────────────────────────
|
|
|
|
install(TARGETS fr RUNTIME DESTINATION bin)
|