2023-06-23 02:28:14 +02:00
cmake_minimum_required ( VERSION 3.20 )
project ( rpcsx )
2025-10-04 11:06:57 +02:00
if ( CMAKE_CROSSCOMPILING )
if ( ${ CMAKE_SYSTEM_NAME } STREQUAL "Windows" AND NOT ${ CMAKE_HOST_SYSTEM_NAME } STREQUAL "Windows" AND ${ CMAKE_CXX_COMPILER_ID } STREQUAL "Clang" )
message ( STATUS "!!! Cross compilation for Windows !!!" )
add_link_options ( -fuse-ld=lld -static-libgcc -static-libstdc++ )
else ( )
message ( FATAL "Cross compilation for Windows is supported with Clang compiler only" )
endif ( )
endif ( )
if ( CMAKE_CROSSCOMPILING )
function ( rpcsx_setup_crosscompiling )
add_custom_command (
O U T P U T " $ { R P C S X _ N A T I V E _ R O O T _ D I R } / C M a k e C a c h e . t x t "
C O M M A N D $ { C M A K E _ C O M M A N D } - G " $ { C M A K E _ G E N E R A T O R } "
- B $ { R P C S X _ N A T I V E _ R O O T _ D I R }
- D C M A K E _ M A K E _ P R O G R A M = " $ { C M A K E _ M A K E _ P R O G R A M } "
- D C M A K E _ C _ C O M P I L E R _ L A U N C H E R = " $ { C M A K E _ C _ C O M P I L E R _ L A U N C H E R } "
- D C M A K E _ C X X _ C O M P I L E R _ L A U N C H E R = " $ { C M A K E _ C X X _ C O M P I L E R _ L A U N C H E R } "
- D C M A K E _ R U N T I M E _ O U T P U T _ D I R E C T O R Y = " $ { R P C S X _ N A T I V E _ R O O T _ D I R } / b i n "
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ S O U R C E _ D I R } "
C O M M E N T " C o n f i g u r i n g n a t i v e p r o j e c t . . . "
U S E S _ T E R M I N A L
)
unset ( CMAKE_EXECUTABLE_SUFFIX )
include ( Platform/ ${ CMAKE_HOST_SYSTEM_NAME } OPTIONAL RESULT_VARIABLE platformIncluded )
if ( platformIncluded )
set ( RPCSX_HOST_EXECUTABLE_SUFFIX ${ CMAKE_EXECUTABLE_SUFFIX } PARENT_SCOPE )
endif ( )
endfunction ( )
set ( RPCSX_NATIVE_ROOT_DIR ${ CMAKE_BINARY_DIR } /native )
rpcsx_setup_crosscompiling ( )
add_custom_target ( RPCSX_CONFIGURE_NATIVE DEPENDS "${RPCSX_NATIVE_ROOT_DIR}/CMakeCache.txt" )
endif ( )
function ( import_native_executable_target target )
set ( options )
set ( one_value_keywords EXECUTABLE )
set ( multi_value_keywords )
cmake_parse_arguments (
a r g
" $ { o p t i o n s } "
" $ { o n e _ v a l u e _ k e y w o r d s } "
" $ { m u l t i _ v a l u e _ k e y w o r d s } "
$ { A R G N }
)
if ( CMAKE_CROSSCOMPILING )
if ( NOT DEFINED arg_EXECUTABLE )
set ( arg_EXECUTABLE ${ target } )
endif ( )
set ( binary_path "${RPCSX_NATIVE_ROOT_DIR}/bin/${arg_EXECUTABLE}${RPCSX_HOST_EXECUTABLE_SUFFIX}" )
set ( ${ target } _BINARY_PATH "${binary_path}" PARENT_SCOPE )
if ( NOT TARGET ${ target } _NATIVE )
if ( CMAKE_GENERATOR MATCHES "Make" )
set ( build_command "$(MAKE)" "-C" "${RPCSX_NATIVE_ROOT_DIR}" "${target}" )
else ( )
set ( build_command ${ CMAKE_COMMAND } --build ${ bin_dir } --target ${ target } --parallel )
endif ( )
add_custom_command ( OUTPUT "${binary_path}"
C O M M A N D $ { b u i l d _ c o m m a n d }
D E P E N D S R P C S X _ C O N F I G U R E _ N A T I V E
W O R K I N G _ D I R E C T O R Y " $ { R P C S X _ N A T I V E _ R O O T _ D I R } "
C O M M E N T " B u i l d i n g n a t i v e $ { t a r g e t } . . . "
U S E S _ T E R M I N A L
)
add_custom_target ( ${ target } _NATIVE DEPENDS ${ binary_path } )
endif ( )
else ( )
set ( ${ target } _BINARY_PATH "$<TARGET_FILE:${target}>" PARENT_SCOPE )
if ( NOT TARGET ${ target } _NATIVE )
add_custom_target ( ${ target } _NATIVE )
endif ( )
endif ( )
endfunction ( )
function ( add_precompiled_vulkan_spirv target )
import_native_executable_target ( glslang-standalone EXECUTABLE glslang )
add_library ( ${ target } INTERFACE )
set ( SPIRV_GEN_ROOT_DIR "spirv-gen/include/" )
set ( SPIRV_GEN_DIR "${SPIRV_GEN_ROOT_DIR}/shaders" )
cmake_path ( ABSOLUTE_PATH SPIRV_GEN_ROOT_DIR BASE_DIRECTORY ${ CMAKE_CURRENT_BINARY_DIR } NORMALIZE OUTPUT_VARIABLE outputrootdir )
cmake_path ( ABSOLUTE_PATH SPIRV_GEN_DIR BASE_DIRECTORY ${ CMAKE_CURRENT_BINARY_DIR } NORMALIZE OUTPUT_VARIABLE outputdir )
file ( MAKE_DIRECTORY ${ outputrootdir } )
file ( MAKE_DIRECTORY ${ outputdir } )
target_include_directories ( ${ target } INTERFACE ${ outputrootdir } )
foreach ( input IN LISTS ARGN )
cmake_path ( GET input FILENAME inputname )
cmake_path ( REPLACE_EXTENSION inputname LAST_ONLY .h OUTPUT_VARIABLE outputname )
cmake_path ( APPEND outputdir ${ outputname } OUTPUT_VARIABLE outputpath )
cmake_path ( REMOVE_EXTENSION inputname LAST_ONLY OUTPUT_VARIABLE varname )
string ( REPLACE "." "_" varname ${ varname } )
string ( PREPEND varname "spirv_" )
add_custom_command (
O U T P U T $ { o u t p u t p a t h }
C O M M A N D $ { g l s l a n g - s t a n d a l o n e _ B I N A R Y _ P A T H } - V - - t a r g e t - e n v v u l k a n 1 . 2 - - v n " $ { v a r n a m e } " - o " $ { o u t p u t p a t h } " " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / $ { i n p u t } "
D E P E N D S " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / $ { i n p u t } " g l s l a n g - s t a n d a l o n e _ N A T I V E
C O M M E N T " G e n e r a t i n g $ { o u t p u t n a m e } . . . "
)
set ( subtarget ".${target}-subtarget-${outputname}" )
add_custom_target ( ${ subtarget } DEPENDS ${ outputpath } )
add_dependencies ( ${ target } ${ subtarget } )
endforeach ( )
endfunction ( )
function ( target_base_address target address )
set_target_properties ( ${ target } PROPERTIES POSITION_INDEPENDENT_CODE off )
if ( CMAKE_CXX_COMPILER_LINKER_ID MATCHES "^(LLD|MOLD)$" )
target_link_options ( ${ target } PUBLIC "LINKER:--image-base=${address}" )
else ( )
target_link_options ( ${ target } PUBLIC "LINKER:-Ttext-segment,${address}" )
endif ( )
endfunction ( )
2025-04-06 22:55:46 +02:00
option ( WITH_RPCSX "Enable RPCSX" ON )
option ( WITH_RPCS3 "Enable RPCS3" OFF )
option ( WITH_RPCS3_QT_UI "Enable RPCS3 UI" OFF )
option ( WITHOUT_OPENGL "Disable OpenGL" OFF )
option ( WITHOUT_OPENGLEW "Disable OpenGLEW" OFF )
2025-04-08 01:08:17 +02:00
option ( WITHOUT_OPENAL "Disable OpenAL" OFF )
2025-04-09 01:26:30 +02:00
option ( COMPILE_FFMPEG "Compile FFmpeg" ON )
2025-04-06 22:55:46 +02:00
2025-04-07 17:23:43 +02:00
# rpcs3 options
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 )
option ( BUILD_LLVM "Build LLVM from git submodule" OFF )
option ( STATIC_LINK_LLVM "Link against LLVM statically. This will get set to ON if you build LLVM from the submodule." OFF )
option ( USE_FAUDIO "FAudio audio backend" ON )
option ( USE_LIBEVDEV "libevdev-based joystick support" ON )
option ( USE_DISCORD_RPC "Discord rich presence integration" OFF )
option ( USE_SYSTEM_ZLIB "Prefer system ZLIB instead of the builtin one" ON )
option ( USE_VULKAN "Vulkan render backend" ON )
option ( USE_PRECOMPILED_HEADERS "Use precompiled headers" OFF )
option ( USE_SDL "Enables SDL input handler" OFF )
option ( USE_SYSTEM_SDL "Prefer system SDL instead of the builtin one" ON )
option ( USE_SYSTEM_FFMPEG "Prefer system ffmpeg instead of the prebuild one" OFF )
option ( USE_SYSTEM_OPENAL "Prefer system OpenAL instead of the prebuild one" ON )
option ( USE_SYSTEM_CURL "Prefer system Curl instead of the prebuild one" ON )
option ( USE_SYSTEM_OPENCV "Prefer system OpenCV instead of the builtin one" ON )
option ( HAS_MEMORY_BREAKPOINTS "Add support for memory breakpoints to the interpreter" OFF )
option ( USE_LTO "Use LTO for building" ON )
2025-04-08 01:08:17 +02:00
if ( NOT WITH_RPCS3 )
set ( WITHOUT_OPENGL on )
set ( WITHOUT_OPENGLEW on )
set ( WITHOUT_OPENAL on )
set ( WITH_LLVM off )
set ( USE_FAUDIO off )
set ( USE_LIBEVDEV off )
set ( USE_DISCORD_RPC off )
set ( USE_SYSTEM_ZLIB off )
set ( USE_VULKAN off )
set ( USE_PRECOMPILED_HEADERS off )
set ( USE_SDL off )
set ( USE_SYSTEM_SDL off )
set ( USE_SYSTEM_FFMPEG off )
set ( USE_SYSTEM_OPENAL off )
set ( USE_SYSTEM_CURL off )
set ( USE_SYSTEM_OPENCV off )
set ( HAS_MEMORY_BREAKPOINTS off )
endif ( )
2023-06-23 02:28:14 +02:00
set ( CMAKE_CXX_EXTENSIONS off )
set ( CMAKE_CXX_STANDARD 23 )
2024-09-25 15:00:55 +02:00
set ( CMAKE_CXX_STANDARD_REQUIRED on )
set ( CMAKE_BUILD_RPATH_USE_ORIGIN on )
2023-06-23 02:28:14 +02:00
2024-09-14 13:45:07 +02:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" )
2025-04-08 01:08:17 +02:00
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON )
if ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11 )
message ( FATAL_ERROR "RPCS3 requires at least gcc-11." )
endif ( )
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0 )
message ( FATAL_ERROR "RPCS3 requires at least clang-12.0." )
endif ( )
endif ( )
include ( CheckCXXCompilerFlag )
get_property ( IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
if ( IS_MULTI_CONFIG )
set ( USE_DISCORD_RPC OFF CACHE BOOL "Discord RPC is only available 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 ( )
endif ( )
if ( CMAKE_BUILD_TYPE MATCHES "Debug" AND NOT MSVC )
add_compile_definitions ( _DEBUG )
endif ( )
if ( MSVC )
option ( USE_MSVC_STATIC_CRT "Use static MSVC C runtime" OFF )
if ( NOT IS_MULTI_CONFIG )
if ( NOT(CMAKE_BUILD_TYPE MATCHES "Release" AND USE_MSVC_STATIC_CRT ) )
set ( USE_DISCORD_RPC OFF CACHE BOOL "Discord RPC is only available in Release and static CRT build." FORCE )
endif ( )
endif ( )
if ( USE_MSVC_STATIC_CRT )
set ( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded" )
else ( )
set ( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL" )
endif ( )
add_compile_options ( /MP )
endif ( )
find_program ( CCACHE_FOUND ccache )
if ( CCACHE_FOUND )
set ( CMAKE_CXX_COMPILER_LAUNCHER ccache )
endif ( )
if ( APPLE AND CMAKE_OSX_ARCHITECTURES STREQUAL "arm64" )
include_directories ( /opt/homebrew/include )
link_directories ( /opt/homebrew/lib )
endif ( )
if ( MSVC )
add_compile_options ( /wd4530 /utf-8 ) # C++ exception handler used, but unwind semantics are not enabled
endif ( )
2024-09-03 08:43:58 +02:00
add_subdirectory ( 3rdparty EXCLUDE_FROM_ALL )
2025-04-08 01:08:17 +02:00
add_subdirectory ( rx EXCLUDE_FROM_ALL )
2025-04-09 02:05:11 +02:00
2025-04-24 12:41:04 +02:00
include ( 3rdparty/llvm/CMakeLists.txt )
2025-04-09 02:05:11 +02:00
if ( NOT RX_TAG )
set ( RX_TAG 0 )
endif ( )
if ( NOT RX_TAG_VERSION )
set ( RX_TAG_VERSION 0 )
endif ( )
2025-04-08 01:08:17 +02:00
target_compile_definitions ( rx PRIVATE
2025-04-09 02:05:11 +02:00
R X _ T A G = $ { R X _ T A G }
R X _ T A G _ V E R S I O N = $ { R X _ T A G _ V E R S I O N }
2025-04-08 01:08:17 +02:00
)
2024-09-03 14:31:53 +02:00
2025-04-06 22:55:46 +02:00
if ( WITH_RPCSX )
find_package ( nlohmann_json CONFIG )
add_subdirectory ( tools )
add_subdirectory ( orbis-kernel )
endif ( )
2025-04-24 12:41:04 +02:00
add_subdirectory ( rpcsx )
2025-04-06 22:55:46 +02:00
if ( WITH_RPCS3 )
2025-04-10 04:28:31 +02:00
include ( ConfigureCompiler )
include ( CheckFunctionExists )
2025-04-06 22:55:46 +02:00
add_subdirectory ( rpcs3 )
2025-04-08 18:46:57 +02:00
add_subdirectory ( ps3fw )
2025-04-06 22:55:46 +02:00
endif ( )
if ( NOT ANDROID AND WITH_RPCS3_QT_UI AND WITH_RPCS3 )
add_subdirectory ( rpcs3qt-legacy )
endif ( )