|
| 1 | +cmake_minimum_required(VERSION 3.31) |
| 2 | +set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES .devcontainer/cmake/xproinc.cmake) |
| 3 | +project(FFmpeg) |
| 4 | +include(GNUInstallDirs) |
| 5 | +include(xpflags) |
| 6 | +set(libs # libraries, in linking order |
| 7 | + # https://github.com/FFmpeg/FFmpeg/blob/n2.6.2/configure#L2667-L2675 |
| 8 | + avdevice |
| 9 | + avfilter |
| 10 | + avformat |
| 11 | + avcodec |
| 12 | + swresample |
| 13 | + swscale |
| 14 | + avutil |
| 15 | + ) |
| 16 | +string(JOIN "\n" EXT1 |
| 17 | + "# libraries, in linking order" |
| 18 | + "# https://github.com/FFmpeg/FFmpeg/blob/n2.6.2/configure#L2667-L2675" |
| 19 | + "# TRICKY ffmpeg_all_libs used by FFmpeg-targets.cmake" |
| 20 | + "set(ffmpeg_all_libs ${libs})" |
| 21 | + "string(REPLACE \";\" \" \" ffmpeg_all_libs \"\${ffmpeg_all_libs}\")" |
| 22 | + "# FFMPEG_LIBRARIES - the FFmpeg libraries" |
| 23 | + "set(FFMPEG_LIBRARIES \${ffmpeg_all_libs})" |
| 24 | + "list(TRANSFORM FFMPEG_LIBRARIES PREPEND ffmpeg::)" |
| 25 | + "list(APPEND reqVars FFMPEG_LIBRARIES)" |
| 26 | + "" |
| 27 | + ) |
| 28 | +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 29 | + foreach(lib ${libs}) |
| 30 | + string(TOUPPER ${lib} LIB) |
| 31 | + file(READ "lib${lib}/version.h" VERSION_H_CONTENTS) |
| 32 | + string(REGEX MATCH "#define[ \t]+LIB${LIB}_VERSION_MAJOR[ \t]+([0-9]+)" _ ${VERSION_H_CONTENTS}) |
| 33 | + set(VERSION_MAJOR ${CMAKE_MATCH_1}) |
| 34 | + list(APPEND dlls ${lib}-${VERSION_MAJOR}.dll) |
| 35 | + endforeach() |
| 36 | + string(JOIN "\n" EXT3 |
| 37 | + "# FFMPEG_DLLNAMES - the FFmpeg shared object names (dll, so)" |
| 38 | + "set(FFMPEG_DLLNAMES ${dlls})" |
| 39 | + "string(REPLACE \";\" \" \" FFMPEG_DLLNAMES \"\${FFMPEG_DLLNAMES}\")" |
| 40 | + "# FFMPEG_DLLS - the full path to FFmpeg shared objects (dll, so)" |
| 41 | + "set(FFMPEG_DLLS \${FFMPEG_DLLNAMES})" |
| 42 | + "list(TRANSFORM FFMPEG_DLLS PREPEND \${XP_ROOTDIR}/${CMAKE_INSTALL_BINDIR}/)" |
| 43 | + "list(APPEND reqVars FFMPEG_DLLNAMES FFMPEG_DLLS)" |
| 44 | + "" |
| 45 | + ) |
| 46 | +endif() |
| 47 | +if(NOT DEFINED XP_INSTALL_CMAKEDIR) |
| 48 | + set(XP_INSTALL_CMAKEDIR ${CMAKE_INSTALL_DATADIR}/cmake) |
| 49 | +endif() |
| 50 | +set(targetsFile ${PROJECT_NAME}-targets) |
| 51 | +xpPackageDevel(TARGETS_FILE ${targetsFile} DEPS openh264) |
| 52 | +install(FILES cmake/${targetsFile}.cmake DESTINATION ${XP_INSTALL_CMAKEDIR}) |
| 53 | +string(TOLOWER ${PROJECT_NAME} prj) |
| 54 | +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 55 | + set(mswLibs ${libs}) |
| 56 | + list(TRANSFORM mswLibs PREPEND "mswbin/bin/") |
| 57 | + list(TRANSFORM mswLibs APPEND "${CMAKE_STATIC_LIBRARY_SUFFIX}") |
| 58 | + set(mswDlls ${dlls}) |
| 59 | + list(TRANSFORM mswDlls PREPEND "mswbin/bin/") |
| 60 | + install(FILES ${mswLibs} DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 61 | + install(PROGRAMS ${mswDlls} DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 62 | + set(incDir ${CMAKE_INSTALL_INCLUDEDIR}/${prj}) |
| 63 | + foreach(lib ${libs}) |
| 64 | + add_subdirectory(lib${lib}) # each library installs headers to incDir |
| 65 | + endforeach() |
| 66 | +else() |
| 67 | + find_package(openh264) |
| 68 | + find_package(yasm) |
| 69 | + get_filename_component(yasmBinDir ${xpuse-yasm_DIR}/../../bin ABSOLUTE) |
| 70 | + configure_file(${xpuse-openh264_DIR}/openh264.pc.in ${CMAKE_BINARY_DIR}/openh264.pc @ONLY) |
| 71 | + set(XP_CONFIGURE ${CMAKE_COMMAND} -E env PKG_CONFIG_PATH=${CMAKE_BINARY_DIR} |
| 72 | + PATH=${yasmBinDir}:$ENV{PATH} # prepend path to yasm |
| 73 | + <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> #--enable-shared --disable-static |
| 74 | + --enable-pic --disable-bzlib --disable-iconv |
| 75 | + --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-libxcb-shape |
| 76 | + --disable-lzma --disable-xlib --disable-zlib |
| 77 | + ) |
| 78 | + list(APPEND XP_CONFIGURE --enable-libopenh264 --disable-sdl) |
| 79 | + list(APPEND XP_CONFIGURE --disable-debug) |
| 80 | + xpVerboseListing("[CONFIGURE]" "${XP_CONFIGURE}") |
| 81 | + include(ExternalProject) |
| 82 | + set_property(DIRECTORY PROPERTY EP_BASE ${CMAKE_BINARY_DIR}/epbase) |
| 83 | + ExternalProject_Add(${PROJECT_NAME} |
| 84 | + SOURCE_DIR ${CMAKE_SOURCE_DIR} |
| 85 | + CONFIGURE_COMMAND ${XP_CONFIGURE} |
| 86 | + BUILD_COMMAND ${CMAKE_COMMAND} -E env PATH=${yasmBinDir}:$ENV{PATH} make # prepend path to yasm |
| 87 | + INSTALL_COMMAND # use default |
| 88 | + ) |
| 89 | + ExternalProject_Get_Property(${PROJECT_NAME} INSTALL_DIR) |
| 90 | + install(DIRECTORY ${INSTALL_DIR}/bin/ DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 91 | + install(DIRECTORY ${INSTALL_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${prj}) |
| 92 | + list(TRANSFORM libs PREPEND "${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}") |
| 93 | + list(TRANSFORM libs APPEND "${CMAKE_STATIC_LIBRARY_SUFFIX}") |
| 94 | + install(FILES ${libs} DESTINATION lib) # TRICKY: NOT ${CMAKE_INSTALL_LIBDIR} because FFmpeg-targets expects lib |
| 95 | + install(DIRECTORY ${INSTALL_DIR}/share/ DESTINATION ${CMAKE_INSTALL_DATADIR}) |
| 96 | +endif() |
0 commit comments