Skip to content

Instantly share code, notes, and snippets.

@JPGygax68
Last active July 12, 2023 09:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPGygax68/dea13b31f34231d069d2 to your computer and use it in GitHub Desktop.
Save JPGygax68/dea13b31f34231d069d2 to your computer and use it in GitHub Desktop.
#CMake: how to add the #FFmpeg libraries to a target
# 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()
@Yurter
Copy link

Yurter commented Jul 12, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment