summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt220
1 files changed, 3 insertions, 217 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a810e11c2..7d9056aa3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -508,13 +508,13 @@ set(FFmpeg_COMPONENTS
508 avutil 508 avutil
509 swscale) 509 swscale)
510 510
511if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 511if (UNIX AND NOT APPLE)
512 Include(FindPkgConfig REQUIRED) 512 Include(FindPkgConfig REQUIRED)
513 pkg_check_modules(LIBVA libva) 513 pkg_check_modules(LIBVA libva)
514endif() 514endif()
515if (NOT YUZU_USE_BUNDLED_FFMPEG) 515if (NOT YUZU_USE_BUNDLED_FFMPEG)
516 # Use system installed FFmpeg 516 # Use system installed FFmpeg
517 find_package(FFmpeg QUIET COMPONENTS ${FFmpeg_COMPONENTS}) 517 find_package(FFmpeg 4.3 QUIET COMPONENTS ${FFmpeg_COMPONENTS})
518 518
519 if (FFmpeg_FOUND) 519 if (FFmpeg_FOUND)
520 # Overwrite aggregate defines from FFmpeg module to avoid over-linking libraries. 520 # Overwrite aggregate defines from FFmpeg module to avoid over-linking libraries.
@@ -527,225 +527,11 @@ if (NOT YUZU_USE_BUNDLED_FFMPEG)
527 set(FFmpeg_INCLUDE_DIR ${FFmpeg_INCLUDE_DIR} ${FFmpeg_INCLUDE_${COMPONENT}} CACHE PATH "Path to FFmpeg headers" FORCE) 527 set(FFmpeg_INCLUDE_DIR ${FFmpeg_INCLUDE_DIR} ${FFmpeg_INCLUDE_${COMPONENT}} CACHE PATH "Path to FFmpeg headers" FORCE)
528 endforeach() 528 endforeach()
529 else() 529 else()
530 message(WARNING "FFmpeg not found, falling back to externals") 530 message(WARNING "FFmpeg not found or too old, falling back to externals")
531 set(YUZU_USE_BUNDLED_FFMPEG ON) 531 set(YUZU_USE_BUNDLED_FFMPEG ON)
532 endif() 532 endif()
533endif() 533endif()
534 534
535if (YUZU_USE_BUNDLED_FFMPEG)
536 if (NOT WIN32)
537 # TODO(lat9nq): Move this to externals/ffmpeg/CMakeLists.txt (and move externals/ffmpeg to
538 # externals/ffmpeg/ffmpeg)
539
540 # Build FFmpeg from externals
541 message(STATUS "Using FFmpeg from externals")
542
543 # FFmpeg has source that requires one of nasm or yasm to assemble it.
544 # REQUIRED throws an error if not found here during configuration rather than during compilation.
545 find_program(ASSEMBLER NAMES nasm yasm)
546 if ("${ASSEMBLER}" STREQUAL "ASSEMBLER-NOTFOUND")
547 message(FATAL_ERROR "One of either `nasm` or `yasm` not found but is required.")
548 endif()
549
550 find_program(AUTOCONF autoconf)
551 if ("${AUTOCONF}" STREQUAL "AUTOCONF-NOTFOUND")
552 message(FATAL_ERROR "Required program `autoconf` not found.")
553 endif()
554
555 set(FFmpeg_PREFIX ${PROJECT_SOURCE_DIR}/externals/ffmpeg)
556 set(FFmpeg_BUILD_DIR ${PROJECT_BINARY_DIR}/externals/ffmpeg)
557 set(FFmpeg_MAKEFILE ${FFmpeg_BUILD_DIR}/Makefile)
558 make_directory(${FFmpeg_BUILD_DIR})
559
560 # Read version string from external
561 file(READ ${FFmpeg_PREFIX}/RELEASE FFmpeg_VERSION)
562 set(FFmpeg_FOUND NO)
563 if (NOT FFmpeg_VERSION STREQUAL "")
564 set(FFmpeg_FOUND YES)
565 endif()
566
567 unset(FFmpeg_LIBRARIES CACHE)
568 foreach(COMPONENT ${FFmpeg_COMPONENTS})
569 set(FFmpeg_${COMPONENT}_PREFIX "${FFmpeg_BUILD_DIR}/lib${COMPONENT}")
570 set(FFmpeg_${COMPONENT}_LIB_NAME "lib${COMPONENT}.a")
571 set(FFmpeg_${COMPONENT}_LIBRARY "${FFmpeg_${COMPONENT}_PREFIX}/${FFmpeg_${COMPONENT}_LIB_NAME}")
572
573 set(FFmpeg_LIBRARIES
574 ${FFmpeg_LIBRARIES}
575 ${FFmpeg_${COMPONENT}_LIBRARY}
576 CACHE PATH "Paths to FFmpeg libraries" FORCE)
577 endforeach()
578
579 Include(FindPkgConfig REQUIRED)
580 pkg_check_modules(LIBVA libva)
581 pkg_check_modules(CUDA cuda)
582 pkg_check_modules(FFNVCODEC ffnvcodec)
583 pkg_check_modules(VDPAU vdpau)
584
585 set(FFmpeg_HWACCEL_LIBRARIES)
586 set(FFmpeg_HWACCEL_FLAGS)
587 set(FFmpeg_HWACCEL_INCLUDE_DIRS)
588 set(FFmpeg_HWACCEL_LDFLAGS)
589
590 if(LIBVA_FOUND)
591 pkg_check_modules(LIBDRM libdrm REQUIRED)
592 find_package(X11 REQUIRED)
593 pkg_check_modules(LIBVA-DRM libva-drm REQUIRED)
594 pkg_check_modules(LIBVA-X11 libva-x11 REQUIRED)
595 list(APPEND FFmpeg_HWACCEL_LIBRARIES
596 ${LIBDRM_LIBRARIES}
597 ${X11_LIBRARIES}
598 ${LIBVA-DRM_LIBRARIES}
599 ${LIBVA-X11_LIBRARIES}
600 ${LIBVA_LIBRARIES})
601 set(FFmpeg_HWACCEL_FLAGS
602 --enable-hwaccel=h264_vaapi
603 --enable-hwaccel=vp8_vaapi
604 --enable-hwaccel=vp9_vaapi
605 --enable-libdrm)
606 list(APPEND FFmpeg_HWACCEL_INCLUDE_DIRS
607 ${LIBDRM_INCLUDE_DIRS}
608 ${X11_INCLUDE_DIRS}
609 ${LIBVA-DRM_INCLUDE_DIRS}
610 ${LIBVA-X11_INCLUDE_DIRS}
611 ${LIBVA_INCLUDE_DIRS}
612 )
613 message(STATUS "VA-API found")
614 else()
615 set(FFmpeg_HWACCEL_FLAGS --disable-vaapi)
616 endif()
617
618 if (FFNVCODEC_FOUND AND CUDA_FOUND)
619 list(APPEND FFmpeg_HWACCEL_FLAGS
620 --enable-cuvid
621 --enable-ffnvcodec
622 --enable-nvdec
623 --enable-hwaccel=h264_nvdec
624 --enable-hwaccel=vp8_nvdec
625 --enable-hwaccel=vp9_nvdec
626 --extra-cflags=-I${CUDA_INCLUDE_DIRS}
627 )
628 list(APPEND FFmpeg_HWACCEL_LIBRARIES
629 ${FFNVCODEC_LIBRARIES}
630 ${CUDA_LIBRARIES}
631 )
632 list(APPEND FFmpeg_HWACCEL_INCLUDE_DIRS
633 ${FFNVCODEC_INCLUDE_DIRS}
634 ${CUDA_INCLUDE_DIRS}
635 )
636 list(APPEND FFmpeg_HWACCEL_LDFLAGS
637 ${FFNVCODEC_LDFLAGS}
638 ${CUDA_LDFLAGS}
639 )
640 message(STATUS "ffnvcodec libraries version ${FFNVCODEC_VERSION} found")
641 endif()
642
643 if (VDPAU_FOUND)
644 list(APPEND FFmpeg_HWACCEL_FLAGS
645 --enable-vdpau
646 --enable-hwaccel=h264_vdpau
647 --enable-hwaccel=vp9_vdpau
648 )
649 list(APPEND FFmpeg_HWACCEL_LIBRARIES ${VDPAU_LIBRARIES})
650 list(APPEND FFmpeg_HWACCEL_INCLUDE_DIRS ${VDPAU_INCLUDE_DIRS})
651 list(APPEND FFmpeg_HWACCEL_LDFLAGS ${VDPAU_LDFLAGS})
652 message(STATUS "vdpau libraries version ${VDPAU_VERSION} found")
653 else()
654 list(APPEND FFmpeg_HWACCEL_FLAGS --disable-vdpau)
655 endif()
656
657 # `configure` parameters builds only exactly what yuzu needs from FFmpeg
658 # `--disable-vdpau` is needed to avoid linking issues
659 add_custom_command(
660 OUTPUT
661 ${FFmpeg_MAKEFILE}
662 COMMAND
663 /bin/bash ${FFmpeg_PREFIX}/configure
664 --disable-avdevice
665 --disable-avfilter
666 --disable-avformat
667 --disable-doc
668 --disable-everything
669 --disable-ffmpeg
670 --disable-ffprobe
671 --disable-network
672 --disable-postproc
673 --disable-swresample
674 --enable-decoder=h264
675 --enable-decoder=vp8
676 --enable-decoder=vp9
677 --cc="${CMAKE_C_COMPILER}"
678 --cxx="${CMAKE_CXX_COMPILER}"
679 ${FFmpeg_HWACCEL_FLAGS}
680 WORKING_DIRECTORY
681 ${FFmpeg_BUILD_DIR}
682 )
683 unset(FFmpeg_HWACCEL_FLAGS)
684
685 # Workaround for Ubuntu 18.04's older version of make not being able to call make as a child
686 # with context of the jobserver. Also helps ninja users.
687 execute_process(
688 COMMAND
689 nproc
690 OUTPUT_VARIABLE
691 SYSTEM_THREADS)
692
693 set(FFmpeg_BUILD_LIBRARIES ${FFmpeg_LIBRARIES})
694 add_custom_command(
695 OUTPUT
696 ${FFmpeg_BUILD_LIBRARIES}
697 COMMAND
698 make -j${SYSTEM_THREADS}
699 WORKING_DIRECTORY
700 ${FFmpeg_BUILD_DIR}
701 )
702
703 set(FFmpeg_INCLUDE_DIR
704 "${FFmpeg_PREFIX};${FFmpeg_BUILD_DIR};${FFmpeg_HWACCEL_INCLUDE_DIRS}"
705 CACHE PATH "Path to FFmpeg headers" FORCE)
706
707 set(FFmpeg_LDFLAGS
708 "${FFmpeg_HWACCEL_LDFLAGS}"
709 CACHE STRING "FFmpeg linker flags" FORCE)
710
711 # ALL makes this custom target build every time
712 # but it won't actually build if the DEPENDS parameter is up to date
713 add_custom_target(ffmpeg-configure ALL DEPENDS ${FFmpeg_MAKEFILE})
714 add_custom_target(ffmpeg-build ALL DEPENDS ${FFmpeg_BUILD_LIBRARIES} ffmpeg-configure)
715 link_libraries(${FFmpeg_LIBVA_LIBRARIES})
716 set(FFmpeg_LIBRARIES ${FFmpeg_BUILD_LIBRARIES} ${FFmpeg_HWACCEL_LIBRARIES}
717 CACHE PATH "Paths to FFmpeg libraries" FORCE)
718 unset(FFmpeg_BUILD_LIBRARIES)
719 unset(FFmpeg_HWACCEL_FLAGS)
720 unset(FFmpeg_HWACCEL_INCLUDE_DIRS)
721 unset(FFmpeg_HWACCEL_LDFLAGS)
722 unset(FFmpeg_HWACCEL_LIBRARIES)
723
724 if (FFmpeg_FOUND)
725 message(STATUS "Found FFmpeg version ${FFmpeg_VERSION}")
726 else()
727 message(FATAL_ERROR "FFmpeg not found")
728 endif()
729 else() # WIN32
730 # Use yuzu FFmpeg binaries
731 set(FFmpeg_EXT_NAME "ffmpeg-4.4")
732 set(FFmpeg_PATH "${CMAKE_BINARY_DIR}/externals/${FFmpeg_EXT_NAME}")
733 download_bundled_external("ffmpeg/" ${FFmpeg_EXT_NAME} "")
734 set(FFmpeg_FOUND YES)
735 set(FFmpeg_INCLUDE_DIR "${FFmpeg_PATH}/include" CACHE PATH "Path to FFmpeg headers" FORCE)
736 set(FFmpeg_LIBRARY_DIR "${FFmpeg_PATH}/bin" CACHE PATH "Path to FFmpeg library directory" FORCE)
737 set(FFmpeg_LDFLAGS "" CACHE STRING "FFmpeg linker flags" FORCE)
738 set(FFmpeg_DLL_DIR "${FFmpeg_PATH}/bin" CACHE PATH "Path to FFmpeg dll's" FORCE)
739 set(FFmpeg_LIBRARIES
740 ${FFmpeg_LIBRARY_DIR}/swscale.lib
741 ${FFmpeg_LIBRARY_DIR}/avcodec.lib
742 ${FFmpeg_LIBRARY_DIR}/avutil.lib
743 CACHE PATH "Paths to FFmpeg libraries" FORCE)
744 endif()
745endif()
746
747unset(FFmpeg_COMPONENTS)
748
749# Prefer the -pthread flag on Linux. 535# Prefer the -pthread flag on Linux.
750set(THREADS_PREFER_PTHREAD_FLAG ON) 536set(THREADS_PREFER_PTHREAD_FLAG ON)
751find_package(Threads REQUIRED) 537find_package(Threads REQUIRED)