2021-04-13 15:02:18 +02:00
cmake_minimum_required ( VERSION 3.16.9 )
2014-04-25 18:57:00 +02:00
2023-07-11 20:40:30 +02:00
project ( rpcs3 LANGUAGES C CXX )
2018-09-18 12:07:33 +02:00
2023-07-11 20:40:30 +02:00
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON )
if ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
2021-05-26 21:21:01 +02:00
if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11 )
message ( FATAL_ERROR "RPCS3 requires at least gcc-11." )
2021-04-20 21:11:17 +02:00
endif ( )
2023-07-11 20:40:30 +02:00
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
2021-04-13 15:02:18 +02:00
if ( CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0 )
message ( FATAL_ERROR "RPCS3 requires at least clang-12.0." )
2021-04-20 21:11:17 +02:00
endif ( )
2019-06-23 07:54:42 +02:00
endif ( )
2021-06-05 03:07:09 +02: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 20:08:27 +01:00
option ( BUILD_LLVM "Build LLVM from git submodule" OFF )
2023-04-29 19:59:16 +02: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-05 03:07:09 +02:00
option ( USE_FAUDIO "FAudio audio backend" ON )
option ( USE_LIBEVDEV "libevdev-based joystick support" ON )
2021-12-30 17:39:18 +01:00
option ( USE_DISCORD_RPC "Discord rich presence integration" OFF )
2021-06-05 03:07:09 +02:00
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 )
2022-10-15 21:01:38 +02:00
option ( USE_SDL "Enables SDL input handler" OFF )
option ( USE_SYSTEM_SDL "Prefer system SDL instead of the builtin one" OFF )
2018-09-18 12:07:33 +02:00
2023-07-11 20:40:30 +02:00
set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/buildfiles/cmake" )
2018-09-18 12:07:33 +02:00
include ( CheckCXXCompilerFlag )
2021-09-11 23:55:53 +02:00
get_property ( IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
if ( IS_MULTI_CONFIG )
2022-01-02 08:10:58 +01: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-10 18:46:10 +02:00
endif ( )
2021-09-11 23:55:53 +02: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 23:54:16 +02:00
endif ( )
2021-09-11 23:55:53 +02:00
if ( MSVC )
option ( USE_MSVC_STATIC_CRT "Use static MSVC C runtime" OFF )
2022-01-02 08:10:58 +01:00
# TODO(cjj19970505@live.cn)
2021-09-11 23:55:53 +02:00
# DiscordRPC binary in 3rdparty is compiled /MT
# So theoretically we should enable DiscordRPC in Release and static CRT build
# since we might encounter some rumtime issues when more than one CRT version are presented.
# https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-160#what-problems-exist-if-an-application-uses-more-than-one-crt-version
# Add other DiscordRPC binaries(compiled with /MTd, /MD, /MDd) or compile it from source may address this issue.
2022-01-02 08:10:58 +01:00
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 ( )
2021-09-11 23:55:53 +02:00
endif ( )
2021-11-24 19:41:05 +01:00
2021-09-11 23:55:53 +02:00
if ( USE_MSVC_STATIC_CRT )
set ( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" )
else ( )
# though doc ( https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html )
2021-11-24 19:41:05 +01:00
# says if that property is not set then CMake uses the default value MultiThreaded$<$<CONFIG:Debug>:Debug>DLL
2021-09-11 23:55:53 +02:00
# to select a MSVC runtime library.
# But yaml-cpp set /MT(d) if CMAKE_MSVC_RUNTIME_LIBRARY is undefined
# So we have to define it explicitly
set ( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" )
endif ( )
# TODO(cjj19970505@live.cn)
# offical QT uses dynamic CRT.
# When building our lib with static CRT and debug build type
2023-07-11 20:40:30 +02:00
# and linking with Qt with dynamic CRT and debug build,
2021-11-24 19:41:05 +01:00
# error is encountered in runtime (which is expected).
# But building our lib with static CRT and release build type,
# and linking with Qt with dynamic CRT and release build seems to be working,
2021-09-11 23:55:53 +02:00
# which is the same config with VS solution.
# (though technically it might still have some hidden errors).
# So we allow static CRT in both relase and debug build, but prompt warning in debug build.
# For more info:
# https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-160#what-problems-exist-if-an-application-uses-more-than-one-crt-version
# https://wiki.qt.io/Technical_FAQ#Why_does_a_statically_built_Qt_use_the_dynamic_Visual_Studio_runtime_libraries_.3F_Do_I_need_to_deploy_those_with_my_application_.3F
2022-01-02 08:10:58 +01:00
if ( USE_MSVC_STATIC_CRT )
if ( IS_MULTI_CONFIG OR CMAKE_BUILD_TYPE MATCHES "Debug" )
message ( AUTHOR_WARNING "Debug build currently can not work with static CRT." )
endif ( )
2021-09-11 23:55:53 +02:00
endif ( )
2023-07-11 20:40:30 +02:00
add_compile_options ( /MP )
2021-09-11 23:55:53 +02:00
endif ( )
2014-07-10 18:46:10 +02:00
if ( NOT CMAKE_SIZEOF_VOID_P EQUAL 8 )
2021-04-20 21:11:17 +02:00
message ( FATAL_ERROR "RPCS3 can only be compiled on 64-bit platforms." )
2014-07-10 18:46:10 +02:00
endif ( )
2017-03-02 22:49:42 +01:00
find_program ( CCACHE_FOUND ccache )
2021-04-18 16:36:00 +02:00
if ( CCACHE_FOUND )
2023-07-11 20:40:30 +02:00
set ( CMAKE_CXX_COMPILER_LAUNCHER ccache )
2017-03-02 22:49:42 +01:00
endif ( )
2018-09-18 12:07:33 +02:00
if ( WIN32 )
2023-07-11 20:40:30 +02:00
add_compile_definitions ( UNICODE )
add_compile_definitions ( _WIN32_WINNT=0x0602 )
2018-06-14 21:39:48 +02:00
endif ( )
2022-09-26 19:07:05 +02:00
if ( APPLE AND CMAKE_OSX_ARCHITECTURES STREQUAL "arm64" )
include_directories ( /opt/homebrew/include )
link_directories ( /opt/homebrew/lib )
2018-11-10 15:43:38 +01:00
endif ( )
2023-07-11 20:40:30 +02:00
set ( LLVM_ENABLE_WARNINGS OFF CACHE BOOL "Enable compiler warnings." )
2019-06-28 06:15:49 +02:00
if ( MSVC )
2021-04-20 21:11:17 +02:00
add_compile_options ( /wd4530 /utf-8 ) # C++ exception handler used, but unwind semantics are not enabled
2019-06-28 06:15:49 +02:00
endif ( )
2018-09-18 12:07:33 +02:00
add_subdirectory ( 3rdparty )
2019-06-28 06:15:49 +02: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 ( )
2021-04-18 16:36:00 +02:00
if ( NOT WIN32 )
2021-04-20 21:11:17 +02:00
add_compile_options ( -pthread )
2019-07-07 15:15:06 +02:00
endif ( )
2015-08-07 23:53:39 +02: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 22:05:32 +02:00
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${PROJECT_BINARY_DIR}/bin" )
2017-06-12 20:45:29 +02:00
2018-05-02 01:10:19 +02:00
add_subdirectory ( rpcs3 )
2023-07-11 20:40:30 +02:00
set_directory_properties ( PROPERTIES VS_STARTUP_PROJECT rpcs3 )