Last active
July 12, 2023 09:35
-
-
Save JPGygax68/dea13b31f34231d069d2 to your computer and use it in GitHub Desktop.
#CMake: how to add the #FFmpeg libraries to a target
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Detect architecture | |
if (CMAKE_SIZEOF_VOID_P MATCHES 8) | |
set( PROJECT_ARCH "x86_64" ) | |
else(CMAKE_SIZEOF_VOID_P MATCHES 8) | |
set( PROJECT_ARCH "x86" ) | |
endif(CMAKE_SIZEOF_VOID_P MATCHES 8) | |
# FFmpeg | |
set(FFmpeg_ROOT "" CACHE PATH "Root of FFmpeg library (libAV)") | |
foreach (lib "avformat" "avcodec" "avutil" "swscale") | |
# Library files | |
find_library(${lib}_LIB_RELEASE "${lib}" PATHS ${FFmpeg_ROOT}/lib/${PROJECT_ARCH} ${FFmpeg_ROOT}/lib) | |
if (NOT ${lib}_LIB_RELEASE) | |
message(FATAL_ERROR "Could not find release version of library \"${lib}\"") | |
endif() | |
find_library(${lib}_LIB_DEBUG "${lib}" PATH ${FFmpeg_ROOT}/lib/${PROJECT_ARCH} ${FFmpeg_ROOT}/lib) | |
if (NOT ${lib}_LIB_DEBUG) | |
message(FATAL_ERROR "Could not find debug version of library \"${lib}\"") | |
endif() | |
target_link_libraries(${PROJECT_NAME} PUBLIC | |
$<$<CONFIG:Release>:${${lib}_LIB_RELEASE}> | |
$<$<CONFIG:Debug>:${${lib}_LIB_DEBUG}> | |
) | |
# Header file | |
find_path(${lib}_INCLUDE "lib${lib}/${lib}.h" PATHS ${FFmpeg_ROOT}/include) | |
if (NOT ${lib}_INCLUDE) | |
message(FATAL_ERROR "Could not find header file of library \"${lib}\"") | |
endif() | |
target_include_directories(${PROJECT_NAME} PRIVATE ${${lib}_INCLUDE}) | |
endforeach() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!