summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt146
1 files changed, 135 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 27aa56780..ac7c3ce90 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,6 +18,8 @@ CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_QT "Download bundled Qt binaries" ON "EN
18 18
19option(ENABLE_WEB_SERVICE "Enable web services (telemetry, etc.)" ON) 19option(ENABLE_WEB_SERVICE "Enable web services (telemetry, etc.)" ON)
20 20
21CMAKE_DEPENDENT_OPTION(YUZU_USE_BUNDLED_FFMPEG "Download/Build bundled yuzu" ON "WIN32" OFF)
22
21option(YUZU_USE_QT_WEB_ENGINE "Use QtWebEngine for web applet implementation" OFF) 23option(YUZU_USE_QT_WEB_ENGINE "Use QtWebEngine for web applet implementation" OFF)
22 24
23option(YUZU_ENABLE_BOXCAT "Enable the Boxcat service, a yuzu high-level implementation of BCAT" ON) 25option(YUZU_ENABLE_BOXCAT "Enable the Boxcat service, a yuzu high-level implementation of BCAT" ON)
@@ -384,19 +386,141 @@ if (NOT LIBUSB_FOUND)
384 set(LIBUSB_LIBRARIES usb) 386 set(LIBUSB_LIBRARIES usb)
385endif() 387endif()
386 388
387# Use system installed ffmpeg. 389# List of all FFmpeg components required
388if (NOT MSVC) 390set(FFmpeg_COMPONENTS
389 find_package(FFmpeg REQUIRED) 391 avcodec
390else() 392 avutil
391 set(FFMPEG_EXT_NAME "ffmpeg-4.2.1") 393 swscale)
392 set(FFMPEG_PATH "${CMAKE_BINARY_DIR}/externals/${FFMPEG_EXT_NAME}") 394
393 download_bundled_external("ffmpeg/" ${FFMPEG_EXT_NAME} "") 395if (NOT YUZU_USE_BUNDLED_FFMPEG)
394 set(FFMPEG_FOUND YES) 396 # Use system installed FFmpeg
395 set(FFMPEG_INCLUDE_DIR "${FFMPEG_PATH}/include" CACHE PATH "Path to FFmpeg headers" FORCE) 397 find_package(FFmpeg REQUIRED COMPONENTS ${FFmpeg_COMPONENTS})
396 set(FFMPEG_LIBRARY_DIR "${FFMPEG_PATH}/bin" CACHE PATH "Path to FFmpeg library" FORCE) 398
397 set(FFMPEG_DLL_DIR "${FFMPEG_PATH}/bin" CACHE PATH "Path to FFmpeg dll's" FORCE) 399 if (FFmpeg_FOUND)
400 # Overwrite aggregate defines from FFmpeg module to avoid over-linking libraries.
401 # Prevents shipping too many libraries with the AppImage.
402 set(FFmpeg_LIBRARIES "")
403 set(FFmpeg_INCLUDE_DIR "")
404
405 foreach(COMPONENT ${FFmpeg_COMPONENTS})
406 set(FFmpeg_LIBRARIES ${FFmpeg_LIBRARIES} ${FFmpeg_LIBRARY_${COMPONENT}} CACHE PATH "Paths to FFmpeg libraries" FORCE)
407 set(FFmpeg_INCLUDE_DIR ${FFmpeg_INCLUDE_DIR} ${FFmpeg_INCLUDE_${COMPONENT}} CACHE PATH "Path to FFmpeg headers" FORCE)
408 endforeach()
409 else()
410 message(WARNING "FFmpeg not found, falling back to externals")
411 set(YUZU_USE_BUNDLED_FFMPEG ON)
412 endif()
413endif()
414
415if (YUZU_USE_BUNDLED_FFMPEG)
416 if (NOT WIN32)
417 # Build FFmpeg from externals
418 message(STATUS "Using FFmpeg from externals")
419
420 # FFmpeg has source that requires one of nasm or yasm to assemble it.
421 # REQUIRED throws an error if not found here during configuration rather than during compilation.
422 find_program(ASSEMBLER NAMES nasm yasm REQUIRED)
423
424 set(FFmpeg_PREFIX ${PROJECT_SOURCE_DIR}/externals/ffmpeg)
425 set(FFmpeg_BUILD_DIR ${PROJECT_BINARY_DIR}/externals/ffmpeg)
426 set(FFmpeg_MAKEFILE ${FFmpeg_BUILD_DIR}/Makefile)
427 make_directory(${FFmpeg_BUILD_DIR})
428
429 # Read version string from external
430 file(READ ${FFmpeg_PREFIX}/RELEASE FFmpeg_VERSION)
431 set(FFmpeg_FOUND NO)
432 if (NOT FFmpeg_VERSION STREQUAL "")
433 set(FFmpeg_FOUND YES)
434 endif()
435
436 foreach(COMPONENT ${FFmpeg_COMPONENTS})
437 set(FFmpeg_${COMPONENT}_PREFIX "${FFmpeg_BUILD_DIR}/lib${COMPONENT}")
438 set(FFmpeg_${COMPONENT}_LIB_NAME "lib${COMPONENT}.a")
439 set(FFmpeg_${COMPONENT}_LIBRARY "${FFmpeg_${COMPONENT}_PREFIX}/${FFmpeg_${COMPONENT}_LIB_NAME}")
440
441 set(FFmpeg_LIBRARIES
442 ${FFmpeg_LIBRARIES}
443 ${FFmpeg_${COMPONENT}_LIBRARY}
444 CACHE PATH "Paths to FFmpeg libraries" FORCE)
445 endforeach()
446
447 set(FFmpeg_INCLUDE_DIR
448 ${FFmpeg_PREFIX}
449 CACHE PATH "Path to FFmpeg headers" FORCE)
450
451 # `configure` parameters builds only exactly what yuzu needs from FFmpeg
452 # `--disable-{vaapi,vdpau}` is needed to avoid linking issues
453 add_custom_command(
454 OUTPUT
455 ${FFmpeg_MAKEFILE}
456 COMMAND
457 /bin/bash ${FFmpeg_PREFIX}/configure
458 --disable-avdevice
459 --disable-avfilter
460 --disable-avformat
461 --disable-doc
462 --disable-everything
463 --disable-ffmpeg
464 --disable-ffprobe
465 --disable-network
466 --disable-postproc
467 --disable-swresample
468 --disable-vaapi
469 --disable-vdpau
470 --enable-decoder=h264
471 --enable-decoder=vp9
472 WORKING_DIRECTORY
473 ${FFmpeg_BUILD_DIR}
474 )
475
476 # Workaround for Ubuntu 18.04's older version of make not being able to call make as a child
477 # with context of the jobserver. Also helps ninja users.
478 execute_process(
479 COMMAND
480 nproc
481 OUTPUT_VARIABLE
482 SYSTEM_THREADS)
483
484 add_custom_command(
485 OUTPUT
486 ${FFmpeg_LIBRARIES}
487 COMMAND
488 make -j${SYSTEM_THREADS}
489 WORKING_DIRECTORY
490 ${FFmpeg_BUILD_DIR}
491 )
492
493 # ALL makes this custom target build every time
494 # but it won't actually build if the DEPENDS parameter is up to date
495 add_custom_target(ffmpeg-build ALL DEPENDS ${FFmpeg_LIBRARIES})
496 add_custom_target(ffmpeg-configure ALL DEPENDS ${FFmpeg_MAKEFILE})
497
498 if (FFmpeg_FOUND)
499 message(STATUS "Found FFmpeg version ${FFmpeg_VERSION}")
500
501 add_dependencies(ffmpeg-build ffmpeg-configure)
502 else()
503 message(FATAL_ERROR "FFmpeg not found")
504 endif()
505 else() # WIN32
506 # Use yuzu FFmpeg binaries
507 set(FFmpeg_EXT_NAME "ffmpeg-4.3.1")
508 set(FFmpeg_PATH "${CMAKE_BINARY_DIR}/externals/${FFmpeg_EXT_NAME}")
509 download_bundled_external("ffmpeg/" ${FFmpeg_EXT_NAME} "")
510 set(FFmpeg_FOUND YES)
511 set(FFmpeg_INCLUDE_DIR "${FFmpeg_PATH}/include" CACHE PATH "Path to FFmpeg headers" FORCE)
512 set(FFmpeg_LIBRARY_DIR "${FFmpeg_PATH}/bin" CACHE PATH "Path to FFmpeg library directory" FORCE)
513 set(FFmpeg_DLL_DIR "${FFmpeg_PATH}/bin" CACHE PATH "Path to FFmpeg dll's" FORCE)
514 set(FFmpeg_LIBRARIES
515 ${FFmpeg_LIBRARY_DIR}/swscale.lib
516 ${FFmpeg_LIBRARY_DIR}/avcodec.lib
517 ${FFmpeg_LIBRARY_DIR}/avutil.lib
518 CACHE PATH "Paths to FFmpeg libraries" FORCE)
519 endif()
398endif() 520endif()
399 521
522unset(FFmpeg_COMPONENTS)
523
400# Prefer the -pthread flag on Linux. 524# Prefer the -pthread flag on Linux.
401set(THREADS_PREFER_PTHREAD_FLAG ON) 525set(THREADS_PREFER_PTHREAD_FLAG ON)
402find_package(Threads REQUIRED) 526find_package(Threads REQUIRED)