2025-03-31 20:03:28 -07:00
cmake_minimum_required ( VERSION 3.28 )
2014-04-25 18:57:00 +02:00
2025-06-08 16:33:45 +02:00
find_program ( CCACHE_PATH ccache HINTS ENV PATH )
if ( CCACHE_PATH )
message ( STATUS "Using ccache: ${CCACHE_PATH}" )
set ( CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PATH}" )
set ( CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PATH}" )
endif ()
2023-07-11 20:40:30 +02:00
project ( rpcs3 LANGUAGES C CXX )
2018-09-18 13:07:33 +03:00
2023-07-11 20:40:30 +02:00
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON )
2025-03-15 10:02:46 +09:00
set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
2023-07-11 20:40:30 +02:00
2026-08-19 09:04:13 -04:00
# Keep the builder's absolute paths out of the shipped binary.
#
# __FILE__ expands to whatever path the compiler was handed, and RPCS3 prints source locations in
# ensure() failures, fmt::throw_exception and assertions -- so every one of those lines carried the
# full build directory into EVERY USER'S LOG. On a developer's machine that is a home directory:
# the shipped core contained 2500 copies of one username. Someone else's crash report is not the
# place to publish where we build.
#
# -ffile-prefix-map rewrites the prefix at compile time, covering both __FILE__ (macro-prefix-map)
# and debug info (debug-prefix-map). Paths become relative-looking (./rpcs3/Emu/...), which is what
# a log wants to show anyway. Costs nothing at runtime.
#
# Applied here, before any add_subdirectory, so third-party targets built in-tree are covered too --
# they embed the same root.
if ( NOT MSVC )
include ( CheckCXXCompilerFlag )
check_cxx_compiler_flag ( "-ffile-prefix-map=${CMAKE_SOURCE_DIR}=." COMPILER_HAS_FILE_PREFIX_MAP )
if ( COMPILER_HAS_FILE_PREFIX_MAP )
add_compile_options ( "$<$<COMPILE_LANGUAGE:C,CXX>:-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.>" )
endif ()
endif ()
2023-07-11 20:40:30 +02:00
if ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
2026-02-20 12:33:54 +01:00
if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13 )
message ( FATAL_ERROR "RPCS3 requires at least gcc-13." )
2021-04-20 20:11:17 +01:00
endif ()
2023-07-11 20:40:30 +02:00
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
2026-02-20 12:33:54 +01:00
if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0 )
message ( FATAL_ERROR "RPCS3 requires at least clang-19.0." )
2021-04-20 20:11:17 +01:00
endif ()
2019-06-22 22:54:42 -07:00
endif ()
2025-05-07 01:10:23 +09:00
if ( APPLE OR WIN32 )
set ( USE_SYSTEM_OPENAL_DEFAULT OFF )
else ()
set ( USE_SYSTEM_OPENAL_DEFAULT ON )
endif ()
2021-06-04 18:07:09 -07:00
option ( USE_NATIVE_INSTRUCTIONS "USE_NATIVE_INSTRUCTIONS makes rpcs3 compile with -march=native, which is useful for local builds, but not good for packages." ON )
option ( WITH_LLVM "Enable usage of LLVM library" ON )
2023-03-11 22:08:27 +03:00
option ( BUILD_LLVM "Build LLVM from git submodule" OFF )
2023-04-29 10:59:16 -07:00
option ( STATIC_LINK_LLVM "Link against LLVM statically. This will get set to ON if you build LLVM from the submodule." OFF )
2021-06-04 18:07:09 -07:00
option ( USE_FAUDIO "FAudio audio backend" ON )
option ( USE_LIBEVDEV "libevdev-based joystick support" ON )
2021-12-30 19:39:18 +03:00
option ( USE_DISCORD_RPC "Discord rich presence integration" OFF )
2021-06-04 18:07:09 -07:00
option ( USE_VULKAN "Vulkan render backend" ON )
option ( USE_PRECOMPILED_HEADERS "Use precompiled headers" OFF )
2026-03-16 01:07:29 +01:00
option ( USE_SDL "Enables SDL input handler" ON )
2025-05-24 18:51:09 +02:00
option ( USE_SYSTEM_CUBEB "Prefer system cubeb instead of the builtin one" OFF )
2025-06-16 08:21:26 +02:00
option ( USE_SYSTEM_CURL "Prefer system Curl instead of the prebuild one" ON )
option ( USE_SYSTEM_FAUDIO "Prefer system FAudio instead of the builtin one" OFF )
option ( USE_SYSTEM_FFMPEG "Prefer system ffmpeg instead of the prebuild one" OFF )
2026-01-24 08:37:47 +00:00
option ( USE_SYSTEM_PROTOBUF "Prefer system protobuf instead of the builtin one" OFF )
2025-08-02 17:15:31 +02:00
option ( USE_SYSTEM_GLSLANG "Prefer system glslang instead of the builtin one" OFF )
2025-08-02 17:33:28 +02:00
option ( USE_SYSTEM_HIDAPI "Prefer system hidapi instead of the builtin one" OFF )
2025-06-16 08:21:26 +02:00
option ( USE_SYSTEM_LIBPNG "Prefer system libpng instead of the builtin one" OFF )
option ( USE_SYSTEM_LIBUSB "Prefer system libusb instead of the builtin one" OFF )
2025-08-02 12:28:40 +02:00
option ( USE_SYSTEM_MINIUPNPC "Prefer system MiniUPnPc instead of the builtin one" OFF )
2025-06-16 08:21:26 +02:00
option ( USE_SYSTEM_MVK "Prefer system MoltenVK instead of the builtin one" OFF )
2025-05-07 01:10:23 +09:00
option ( USE_SYSTEM_OPENAL "Prefer system OpenAL instead of the prebuild one" ${ USE_SYSTEM_OPENAL_DEFAULT } )
2025-06-16 08:21:26 +02:00
option ( USE_SYSTEM_OPENCV "Prefer system OpenCV instead of the builtin one" ON )
option ( USE_SYSTEM_PUGIXML "Prefer system pugixml instead of the builtin one" OFF )
2025-08-02 12:33:20 +02:00
option ( USE_SYSTEM_RTMIDI "Prefer system RtMidi instead of the builtin one" OFF )
2025-06-16 08:21:26 +02:00
option ( USE_SYSTEM_SDL "Prefer system SDL instead of the builtin one" ON )
2025-08-02 18:34:46 +02:00
option ( USE_SYSTEM_VULKAN_MEMORY_ALLOCATOR "Prefer system Vulkan Memory Allocator instead of the builtin one" OFF )
2025-08-02 19:57:33 +02:00
option ( USE_SYSTEM_WOLFSSL "Prefer system wolfSSL instead of the builtin one" OFF )
2025-06-16 08:21:26 +02:00
option ( USE_SYSTEM_ZLIB "Prefer system ZLIB instead of the builtin one" ON )
2025-08-02 17:29:47 +02:00
option ( USE_SYSTEM_ZSTD "Prefer system zstd instead of the builtin one" OFF )
2025-03-01 17:08:10 +01:00
option ( HAS_MEMORY_BREAKPOINTS "Add support for memory breakpoints to the interpreter" OFF )
2025-02-13 09:02:12 +01:00
option ( USE_LTO "Use LTO for building" ON )
2025-04-26 21:30:27 +02:00
option ( BUILD_RPCS3_TESTS "Build RPCS3 unit tests." OFF )
2025-04-29 21:40:22 +02:00
option ( RUN_RPCS3_TESTS "Run RPCS3 unit tests. Requires BUILD_RPCS3_TESTS" OFF )
2025-08-17 18:03:31 -04:00
option ( USE_GAMEMODE "Choose whether to enable GameMode features or not." ON )
2018-09-18 13:07:33 +03:00
2023-07-11 20:40:30 +02:00
set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/buildfiles/cmake" )
2018-09-18 13:07:33 +03:00
include ( CheckCXXCompilerFlag )
2021-09-12 05:55:53 +08:00
get_property ( IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
if ( IS_MULTI_CONFIG )
2022-01-02 15:10:58 +08:00
# TODO(cjj19970505@live.cn)
# Currently DicordRPC is included as a binary compiled with /MT flag.
# We need all 4 binaries(/MT /MTd /MD /MDd) or including the source instead of binary.
set ( USE_DISCORD_RPC OFF CACHE BOOL "Discord RPC is only avaliable with single-config generator" FORCE )
else ()
if ( NOT CMAKE_BUILD_TYPE )
message ( STATUS "No build type selected, default to Release" )
set ( CMAKE_BUILD_TYPE "Release" )
endif ()
2014-07-11 02:46:10 +10:00
endif ()
2021-09-12 05:55:53 +08:00
if ( CMAKE_BUILD_TYPE MATCHES "Debug" AND NOT MSVC )
2023-07-11 20:40:30 +02:00
add_compile_definitions ( _DEBUG )
2018-09-21 21:54:16 +00:00
endif ()
2021-09-12 05:55:53 +08:00
if ( MSVC )
2026-02-15 15:01:22 +01:00
add_compile_options ( "$<$<COMPILE_LANGUAGE:C,CXX>:/MP>" )
2021-09-12 05:55:53 +08:00
endif ()
2014-07-11 02:46:10 +10:00
if ( NOT CMAKE_SIZEOF_VOID_P EQUAL 8 )
2025-11-16 15:17:12 +01:00
message ( FATAL_ERROR "RPCS3 can only be compiled on 64-bit platforms." )
2014-07-11 02:46:10 +10:00
endif ()
2022-09-26 19:07:05 +02:00
if ( APPLE AND CMAKE_OSX_ARCHITECTURES STREQUAL "arm64" )
2026-05-04 11:35:31 +04:00
list ( APPEND CMAKE_PREFIX_PATH "/opt/homebrew" )
list ( APPEND CMAKE_SYSTEM_PREFIX_PATH "/opt/homebrew" )
2018-11-10 17:43:38 +03:00
endif ()
2019-06-28 07:15:49 +03:00
if ( MSVC )
2026-02-15 15:01:22 +01:00
add_compile_options ( "$<$<COMPILE_LANGUAGE:C,CXX>:/wd4530;/utf-8>" ) # C++ exception handler used, but unwind semantics are not enabled
2019-06-28 07:15:49 +03:00
endif ()
2026-08-06 08:59:52 -04:00
# ARMSX3: upstream skips its FFMPEG block on Android (3rdparty/CMakeLists.txt
# `if(NOT ANDROID)`) but still aliases 3rdparty::ffmpeg -> 3rdparty_ffmpeg
# unguarded, so the target has to exist before 3rdparty/ is processed.
if ( ANDROID )
include ( ${ CMAKE_CURRENT_SOURCE_DIR } /android/ffmpeg.cmake )
endif ()
2018-09-18 13:07:33 +03:00
add_subdirectory ( 3rdparty )
2019-06-28 07:15:49 +03:00
2022-05-15 18:37:53 +02:00
if ( DISABLE_LTO )
if ( CMAKE_C_FLAGS )
string ( REGEX REPLACE "-flto[^ ]*" "" CMAKE_C_FLAGS ${ CMAKE_C_FLAGS } )
endif ()
if ( CMAKE_CXX_FLAGS )
string ( REGEX REPLACE "-flto[^ ]*" "" CMAKE_CXX_FLAGS ${ CMAKE_CXX_FLAGS } )
endif ()
endif ()
string ( FIND "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}" "-flto" FOUND_LTO )
if ( NOT FOUND_LTO EQUAL -1 )
2023-07-11 20:40:30 +02:00
message ( FATAL_ERROR "RPCS3 doesn't support building with LTO, use -DDISABLE_LTO=TRUE to force-disable it" )
2022-05-15 18:37:53 +02:00
endif ()
2025-07-06 05:50:03 -04:00
## Look for Gamemode if its installed on Linux
if ( LINUX )
2025-08-17 18:03:31 -04:00
## User chooses whether to Enable GameMode features or not
if ( USE_GAMEMODE )
2025-07-06 05:50:03 -04:00
add_compile_definitions ( GAMEMODE_AVAILABLE )
endif ()
endif ()
2015-08-08 00:53:39 +03:00
# TODO: do real installation, including copying directory structure
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}/bin" )
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}/bin" )
2017-06-22 13:05:32 -07:00
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${PROJECT_BINARY_DIR}/bin" )
2017-06-12 11:45:29 -07:00
2025-04-30 17:14:05 +02:00
if ( BUILD_RPCS3_TESTS )
enable_testing ()
endif ()
2018-05-02 01:10:19 +02:00
add_subdirectory ( rpcs3 )
2023-07-11 20:40:30 +02:00
2026-08-06 08:59:52 -04:00
# ARMSX3: the Android JNI shared library. Kept behind ANDROID so desktop builds
# are byte-for-byte unaffected.
if ( ANDROID )
add_subdirectory ( android )
endif ()
2023-07-11 20:40:30 +02:00
set_directory_properties ( PROPERTIES VS_STARTUP_PROJECT rpcs3 )