| 1 |
# ------------------------------------------------------------------------------ |
| 2 |
# FFmpeg+CMake support for CloudCompare |
| 3 |
# ------------------------------------------------------------------------------ |
| 4 |
|
| 5 |
# Find FFmpeg includes |
| 6 |
if( NOT EXISTS "${FFMPEG_INCLUDE_DIR}" ) |
| 7 |
find_path( FFMPEG_AVCODEC_INCLUDE_DIR libavcodec/avcodec.h ) |
| 8 |
set( FFMPEG_INCLUDE_DIR "${FFMPEG_AVCODEC_INCLUDE_DIR}" CACHE PATH "FFmpeg include directory" ) |
| 9 |
|
| 10 |
message( STATUS "Setting FFmpeg include dir: ${FFMPEG_INCLUDE_DIR}" ) |
| 11 |
unset( FFMPEG_AVCODEC_INCLUDE_DIR CACHE ) |
| 12 |
endif() |
| 13 |
|
| 14 |
# Find FFmpeg libraries |
| 15 |
if( NOT EXISTS "${FFMPEG_LIBRARY_DIR}" ) |
| 16 |
find_library( FFMPEG_AVCODEC_LIBRARY_DIR avcodec DOC "FFmpeg library directory" ) |
| 17 |
get_filename_component( FFMPEG_AVCODEC_LIBRARY_DIR ${FFMPEG_AVCODEC_LIBRARY_DIR} DIRECTORY ) |
| 18 |
set( FFMPEG_LIBRARY_DIR "${FFMPEG_AVCODEC_LIBRARY_DIR}" CACHE PATH "FFmpeg library directory" ) |
| 19 |
|
| 20 |
message( STATUS "Setting FFmpeg library dir: ${FFMPEG_LIBRARY_DIR}" ) |
| 21 |
unset( FFMPEG_AVCODEC_LIBRARY_DIR CACHE ) |
| 22 |
endif() |
| 23 |
|
| 24 |
if( NOT EXISTS "${FFMPEG_INCLUDE_DIR}" ) |
| 25 |
message( FATAL_ERROR "FFmpeg include dir does not exist (FFMPEG_INCLUDE_DIR): ${FFMPEG_INCLUDE_DIR}" ) |
| 26 |
endif() |
| 27 |
|
| 28 |
if( NOT EXISTS "${FFMPEG_LIBRARY_DIR}" ) |
| 29 |
message( FATAL_ERROR "FFmpeg library dir does not exist (FFMPEG_LIBRARY_DIR): ${FFMPEG_LIBRARY_DIR}" ) |
| 30 |
endif() |
| 31 |
|
| 32 |
if( WIN32 ) |
| 33 |
if( NOT EXISTS "${FFMPEG_BINARY_DIR}" ) |
| 34 |
get_filename_component( FFMPEG_ROOT_DIR "${FFMPEG_LIBRARY_DIR}/.." ABSOLUTE ) |
| 35 |
set( FFMPEG_BINARY_DIR "${FFMPEG_ROOT_DIR}/bin" CACHE PATH "FFmpeg binary directory (where the DLLs are ;-)" ) |
| 36 |
|
| 37 |
message( STATUS "Setting FFmpeg binary dir: ${FFMPEG_BINARY_DIR}" ) |
| 38 |
unset( FFMPEG_ROOT_DIR CACHE ) |
| 39 |
endif() |
| 40 |
elseif( APPLE ) |
| 41 |
if( NOT EXISTS "${FFMPEG_X264_LIBRARY_DIR}" ) |
| 42 |
find_library( X264_LIBRARY_DIR x264 ) |
| 43 |
get_filename_component( X264_LIBRARY_DIR ${X264_LIBRARY_DIR} DIRECTORY ) |
| 44 |
set( FFMPEG_X264_LIBRARY_DIR "${X264_LIBRARY_DIR}" CACHE PATH "The directory containing the x264 library." ) |
| 45 |
|
| 46 |
message( STATUS "Setting x264 library dir: ${FFMPEG_X264_LIBRARY_DIR}" ) |
| 47 |
unset( X264_LIBRARY_DIR CACHE ) |
| 48 |
endif() |
| 49 |
|
| 50 |
if( NOT EXISTS "${FFMPEG_X264_LIBRARY_DIR}" ) |
| 51 |
message( FATAL_ERROR "x264 library dir does not exist (FFMPEG_X264_LIBRARY_DIR): ${FFMPEG_X264_LIBRARY_DIR}" ) |
| 52 |
endif() |
| 53 |
endif() |
| 54 |
|
| 55 |
# link project with ffmpeg libraries |
| 56 |
function( target_link_ffmpeg ) # 1 argument: ARGV0 = project name |
| 57 |
set( FFMPEG_LIBRARIES "" ) |
| 58 |
set( FFMPEG_LIBRARIES_ROOT_NAME avutil avcodec avformat swscale ) #unused: avdevice avfilter postproc swresample |
| 59 |
|
| 60 |
foreach( libfile ${FFMPEG_LIBRARIES_ROOT_NAME} ) |
| 61 |
if(WIN32) |
| 62 |
list( APPEND FFMPEG_LIBRARIES ${FFMPEG_LIBRARY_DIR}/${libfile}.lib ) |
| 63 |
elseif( APPLE ) |
| 64 |
if( EXISTS "${FFMPEG_LIBRARY_DIR}/lib${libfile}.dylib" ) |
| 65 |
list( APPEND FFMPEG_LIBRARIES ${FFMPEG_LIBRARY_DIR}/lib${libfile}.dylib ) |
| 66 |
else() |
| 67 |
list( APPEND FFMPEG_LIBRARIES ${FFMPEG_LIBRARY_DIR}/lib${libfile}.a ) |
| 68 |
endif() |
| 69 |
else() |
| 70 |
list( APPEND FFMPEG_LIBRARIES ${FFMPEG_LIBRARY_DIR}/lib${libfile}.so ) |
| 71 |
endif() |
| 72 |
endforeach() |
| 73 |
|
| 74 |
target_link_libraries( ${ARGV0} ${FFMPEG_LIBRARIES} ) |
| 75 |
|
| 76 |
if( APPLE ) |
| 77 |
target_link_libraries( ${ARGV0} |
| 78 |
"-liconv" |
| 79 |
"-L${FFMPEG_X264_LIBRARY_DIR} -lx264" |
| 80 |
"-lz" |
| 81 |
"-framework CoreVideo" |
| 82 |
) |
| 83 |
endif() |
| 84 |
|
| 85 |
# Required for some C99 defines |
| 86 |
target_compile_definitions( ${ARGV0} PRIVATE __STDC_CONSTANT_MACROS ) |
| 87 |
|
| 88 |
unset( FFMPEG_LIBRARIES ) |
| 89 |
unset( FFMPEG_LIBRARIES_ROOT_NAME ) |
| 90 |
endfunction() |
| 91 |
|
| 92 |
function( export_ffmpeg_dlls ) # 1 argument: ARGV0 = destination directory |
| 93 |
if( WIN32 ) |
| 94 |
if( EXISTS "${FFMPEG_BINARY_DIR}" ) |
| 95 |
set( FFMPEG_DLL "") |
| 96 |
|
| 97 |
file( GLOB CODEC_DLL ${FFMPEG_BINARY_DIR}/avcodec*.dll ) |
| 98 |
list( APPEND FFMPEG_DLL ${CODEC_DLL} ) |
| 99 |
|
| 100 |
file( GLOB FORMAT_DLL ${FFMPEG_BINARY_DIR}/avformat*.dll ) |
| 101 |
list( APPEND FFMPEG_DLL ${FORMAT_DLL} ) |
| 102 |
|
| 103 |
file( GLOB UTIL_DLL ${FFMPEG_BINARY_DIR}/avutil*.dll ) |
| 104 |
list( APPEND FFMPEG_DLL ${UTIL_DLL} ) |
| 105 |
|
| 106 |
file( GLOB SW_DLLS ${FFMPEG_BINARY_DIR}/sw*.dll ) |
| 107 |
list( APPEND FFMPEG_DLL ${SW_DLLS} ) |
| 108 |
|
| 109 |
copy_files( "${FFMPEG_DLL}" "${ARGV0}" 1 ) #mind the quotes |
| 110 |
else() |
| 111 |
message( FATAL_ERROR "FFmpeg binary dir does not exist (FFMPEG_BINARY_DIR)" ) |
| 112 |
endif() |
| 113 |
endif() |
| 114 |
endfunction() |