2021-04-17 22:29:55 +00:00
# Extra preprocessor definitions that will be added to all pcsx2 builds
set ( PCSX2_DEFS "" )
2015-01-06 22:45:43 +00:00
#-------------------------------------------------------------------------------
# Misc option
#-------------------------------------------------------------------------------
2015-07-27 18:00:47 +00:00
option ( DISABLE_BUILD_DATE "Disable including the binary compile date" )
2020-08-19 08:19:28 +00:00
option ( ENABLE_TESTS "Enables building the unit tests" ON )
2021-09-02 03:32:14 +00:00
option ( LTO_PCSX2_CORE "Enable LTO/IPO/LTCG on the subset of pcsx2 that benefits most from it but not anything else" )
2021-06-20 03:59:14 +00:00
option ( USE_VTUNE "Plug VTUNE to profile GS JIT." )
2016-11-18 21:40:52 +00:00
2014-07-05 12:54:56 +00:00
#-------------------------------------------------------------------------------
# Graphical option
#-------------------------------------------------------------------------------
2022-04-03 04:49:49 +00:00
option ( USE_OPENGL "Enable OpenGL GS renderer" ON )
2021-11-06 06:53:01 +00:00
option ( USE_VULKAN "Enable Vulkan GS renderer" ON )
2014-07-05 12:54:56 +00:00
#-------------------------------------------------------------------------------
# Path and lib option
#-------------------------------------------------------------------------------
2021-10-16 00:14:34 +00:00
if ( UNIX AND NOT APPLE )
2023-01-02 03:13:12 +00:00
option ( ENABLE_SETCAP "Enable networking capability for DEV9" OFF )
2021-10-16 00:14:34 +00:00
option ( X11_API "Enable X11 support" ON )
2023-01-02 03:13:12 +00:00
option ( WAYLAND_API "Enable Wayland support" ON )
2023-06-27 05:18:56 +00:00
endif ( )
if ( UNIX )
2023-06-06 08:24:58 +00:00
option ( USE_LINKED_FFMPEG "Links with ffmpeg instead of using dynamic loading" OFF )
2021-10-16 00:14:34 +00:00
endif ( )
2020-05-24 06:19:47 +00:00
if ( APPLE )
2021-07-04 05:24:21 +00:00
option ( OSX_USE_DEFAULT_SEARCH_PATH "Don't prioritize system library paths" OFF )
option ( SKIP_POSTPROCESS_BUNDLE "Skip postprocessing bundle for redistributability" OFF )
2020-05-24 06:19:47 +00:00
endif ( )
2014-07-12 14:04:57 +00:00
#-------------------------------------------------------------------------------
# Compiler extra
#-------------------------------------------------------------------------------
2014-07-12 17:57:26 +00:00
option ( USE_ASAN "Enable address sanitizer" )
2014-07-12 14:04:57 +00:00
2022-08-13 03:18:06 +00:00
if ( MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
set ( USE_CLANG_CL TRUE )
message ( STATUS "Building with Clang-CL." )
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
2021-07-04 05:24:21 +00:00
set ( USE_CLANG TRUE )
message ( STATUS "Building with Clang/LLVM." )
2016-07-28 08:35:21 +00:00
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
2021-07-04 05:24:21 +00:00
set ( USE_GCC TRUE )
message ( STATUS "Building with GNU GCC" )
2021-08-04 05:43:25 +00:00
elseif ( MSVC )
message ( STATUS "Building with MSVC" )
2016-07-28 08:35:21 +00:00
else ( )
2021-07-04 05:24:21 +00:00
message ( FATAL_ERROR "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}" )
2014-12-28 09:05:22 +00:00
endif ( )
2016-05-17 17:31:39 +00:00
#-------------------------------------------------------------------------------
# if no build type is set, use Devel as default
# Note without the CMAKE_BUILD_TYPE options the value is still defined to ""
# Ensure that the value set by the User is correct to avoid some bad behavior later
#-------------------------------------------------------------------------------
2021-04-17 22:29:55 +00:00
if ( NOT CMAKE_BUILD_TYPE MATCHES "Debug|Devel|MinSizeRel|RelWithDebInfo|Release" )
2016-05-17 17:31:39 +00:00
set ( CMAKE_BUILD_TYPE Devel )
message ( STATUS "BuildType set to ${CMAKE_BUILD_TYPE} by default" )
endif ( )
2021-04-17 22:29:55 +00:00
# Add Devel build type
set ( CMAKE_C_FLAGS_DEVEL "${CMAKE_C_FLAGS_RELWITHDEBINFO}"
C A C H E S T R I N G " F l a g s u s e d b y t h e C c o m p i l e r d u r i n g d e v e l o p m e n t b u i l d s " F O R C E )
set ( CMAKE_CXX_FLAGS_DEVEL "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}"
C A C H E S T R I N G " F l a g s u s e d b y t h e C + + c o m p i l e r d u r i n g d e v e l o p m e n t b u i l d s " F O R C E )
set ( CMAKE_LINKER_FLAGS_DEVEL "${CMAKE_LINKER_FLAGS_RELWITHDEBINFO}"
C A C H E S T R I N G " F l a g s u s e d f o r l i n k i n g b i n a r i e s d u r i n g d e v e l o p m e n t b u i l d s " F O R C E )
set ( CMAKE_SHARED_LINKER_FLAGS_DEVEL "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}"
C A C H E S T R I N G " F l a g s u s e d f o r l i n k i n g s h a r e d l i b r a r i e s d u r i n g d e v e l o p m e n t b u i l d s " F O R C E )
2021-08-04 05:43:25 +00:00
set ( CMAKE_EXE_LINKER_FLAGS_DEVEL "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}"
C A C H E S T R I N G " F l a g s u s e d f o r l i n k i n g e x e c u t a b l e s d u r i n g d e v e l o p m e n t b u i l d s " F O R C E )
2021-04-17 22:29:55 +00:00
if ( CMAKE_CONFIGURATION_TYPES )
list ( INSERT CMAKE_CONFIGURATION_TYPES 0 Devel )
endif ( )
2021-09-04 02:33:11 +00:00
mark_as_advanced ( CMAKE_C_FLAGS_DEVEL CMAKE_CXX_FLAGS_DEVEL CMAKE_LINKER_FLAGS_DEVEL CMAKE_SHARED_LINKER_FLAGS_DEVEL CMAKE_EXE_LINKER_FLAGS_DEVEL )
2016-05-17 17:31:39 +00:00
2014-07-05 12:54:56 +00:00
#-------------------------------------------------------------------------------
# Select the architecture
#-------------------------------------------------------------------------------
2014-11-11 13:50:56 +00:00
option ( DISABLE_ADVANCE_SIMD "Disable advance use of SIMD (SSE2+ & AVX)" OFF )
2014-07-05 12:54:56 +00:00
2014-12-25 02:18:28 +00:00
# Print if we are cross compiling.
if ( CMAKE_CROSSCOMPILING )
2021-07-04 05:24:21 +00:00
message ( STATUS "Cross compilation is enabled." )
2014-12-25 02:18:28 +00:00
else ( )
2021-07-04 05:24:21 +00:00
message ( STATUS "Cross compilation is disabled." )
2014-12-25 02:18:28 +00:00
endif ( )
2014-07-05 12:54:56 +00:00
# Architecture bitness detection
2014-12-24 20:39:51 +00:00
include ( TargetArch )
target_architecture ( PCSX2_TARGET_ARCHITECTURES )
2022-03-19 22:21:05 +00:00
if ( ${ PCSX2_TARGET_ARCHITECTURES } MATCHES "x86_64" )
2014-12-24 22:12:34 +00:00
message ( STATUS "Compiling a ${PCSX2_TARGET_ARCHITECTURES} build on a ${CMAKE_HOST_SYSTEM_PROCESSOR} host." )
2014-07-05 12:54:56 +00:00
2021-07-04 05:24:21 +00:00
# x86_64 requires -fPIC
set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
2021-08-04 05:43:25 +00:00
if ( NOT DEFINED ARCH_FLAG AND NOT MSVC )
2021-07-04 05:24:21 +00:00
if ( DISABLE_ADVANCE_SIMD )
2023-04-25 08:28:47 +00:00
set ( ARCH_FLAG "-msse -msse2 -msse4.1 -mfxsr" )
2021-07-04 05:24:21 +00:00
else ( )
#set(ARCH_FLAG "-march=native -fabi-version=6")
set ( ARCH_FLAG "-march=native" )
endif ( )
2022-08-13 03:18:06 +00:00
elseif ( NOT DEFINED ARCH_FLAG AND USE_CLANG_CL )
set ( ARCH_FLAG "-msse4.1" )
2021-07-04 05:24:21 +00:00
endif ( )
2023-05-13 08:04:14 +00:00
list ( APPEND PCSX2_DEFS _M_X86=1 )
2021-07-04 05:24:21 +00:00
set ( _M_X86 1 )
2014-07-05 12:54:56 +00:00
else ( )
2021-07-04 05:24:21 +00:00
message ( FATAL_ERROR "Unsupported architecture: ${PCSX2_TARGET_ARCHITECTURES}" )
2014-07-05 12:54:56 +00:00
endif ( )
2021-04-17 22:29:55 +00:00
string ( REPLACE " " ";" ARCH_FLAG_LIST "${ARCH_FLAG}" )
add_compile_options ( "${ARCH_FLAG_LIST}" )
2014-07-05 12:54:56 +00:00
2011-10-29 11:39:06 +00:00
#-------------------------------------------------------------------------------
2011-10-30 00:32:22 +00:00
# Set some default compiler flags
2011-10-29 11:39:06 +00:00
#-------------------------------------------------------------------------------
2016-12-05 15:57:53 +00:00
option ( USE_PGO_GENERATE "Enable PGO optimization (generate profile)" )
option ( USE_PGO_OPTIMIZE "Enable PGO optimization (use profile)" )
2015-11-15 12:54:47 +00:00
2023-07-19 13:49:18 +00:00
# Require C++20.
set ( CMAKE_CXX_STANDARD 20 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
2022-08-13 03:18:06 +00:00
if ( MSVC AND NOT USE_CLANG_CL )
2023-05-13 08:04:14 +00:00
add_compile_options (
" $ < $ < C O M P I L E _ L A N G U A G E : C X X > : / Z c : e x t e r n C o n s t e x p r > "
" $ < $ < C O M P I L E _ L A N G U A G E : C X X > : / Z c : _ _ c p l u s p l u s > "
" $ < $ < C O M P I L E _ L A N G U A G E : C X X > : / p e r m i s s i v e - > "
" / Z o "
" / u t f - 8 "
)
2022-12-28 14:02:53 +00:00
endif ( )
if ( MSVC )
# Disable RTTI
string ( REPLACE "/GR" "" CMAKE_CXX_FLAGS ${ CMAKE_CXX_FLAGS } )
# Disable Exceptions
string ( REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${ CMAKE_CXX_FLAGS } )
else ( )
2023-06-28 13:41:30 +00:00
add_compile_options ( -pipe -fvisibility=hidden -pthread )
2022-12-28 14:02:53 +00:00
add_compile_options (
" $ < $ < C O M P I L E _ L A N G U A G E : C X X > : - f n o - r t t i > "
" $ < $ < C O M P I L E _ L A N G U A G E : C X X > : - f n o - e x c e p t i o n s > "
)
2021-08-04 05:43:25 +00:00
endif ( )
2022-08-14 21:21:23 +00:00
set ( CONFIG_REL_NO_DEB $< OR:$<CONFIG:Release > , $< CONFIG:MinSizeRel > > )
set ( CONFIG_ANY_REL $< OR:$<CONFIG:Release > , $< CONFIG:MinSizeRel > , $< CONFIG:RelWithDebInfo > > )
2021-08-04 05:43:25 +00:00
if ( WIN32 )
2021-09-04 02:33:11 +00:00
add_compile_definitions (
$ < $ < C O N F I G : D e b u g > : _ I T E R A T O R _ D E B U G _ L E V E L = 2 >
$ < $ < C O N F I G : D e v e l > : _ I T E R A T O R _ D E B U G _ L E V E L = 1 >
2022-08-14 21:21:23 +00:00
$ < $ { C O N F I G _ A N Y _ R E L } : _ I T E R A T O R _ D E B U G _ L E V E L = 0 >
2022-12-28 14:02:53 +00:00
_ H A S _ E X C E P T I O N S = 0
2021-09-04 02:33:11 +00:00
)
2022-12-28 14:02:53 +00:00
list ( APPEND PCSX2_DEFS _SCL_SECURE_NO_WARNINGS _UNICODE UNICODE )
2021-08-04 05:43:25 +00:00
endif ( )
2019-08-25 01:47:49 +00:00
2023-03-19 15:33:15 +00:00
# Enable debug information in release builds for Linux.
# Makes the backtrace actually meaningful.
if ( UNIX AND NOT APPLE )
2023-03-21 12:42:28 +00:00
add_compile_options ( $< $<CONFIG:Release > :-g1> )
2023-03-19 15:33:15 +00:00
endif ( )
2022-08-14 21:21:23 +00:00
if ( MSVC )
# Enable PDB generation in release builds
add_compile_options (
$ < $ { C O N F I G _ R E L _ N O _ D E B } : / Z i >
)
add_link_options (
$ < $ { C O N F I G _ R E L _ N O _ D E B } : / D E B U G >
$ < $ { C O N F I G _ R E L _ N O _ D E B } : / O P T : R E F >
$ < $ { C O N F I G _ R E L _ N O _ D E B } : / O P T : I C F >
)
endif ( )
2016-12-04 17:46:02 +00:00
if ( USE_VTUNE )
2021-04-17 22:29:55 +00:00
list ( APPEND PCSX2_DEFS ENABLE_VTUNE )
2019-08-25 01:47:49 +00:00
endif ( )
2022-04-03 04:49:49 +00:00
if ( USE_OPENGL )
list ( APPEND PCSX2_DEFS ENABLE_OPENGL )
endif ( )
2021-11-06 06:53:01 +00:00
if ( USE_VULKAN )
list ( APPEND PCSX2_DEFS ENABLE_VULKAN )
endif ( )
2021-10-16 00:14:34 +00:00
if ( X11_API )
list ( APPEND PCSX2_DEFS X11_API )
endif ( )
if ( WAYLAND_API )
list ( APPEND PCSX2_DEFS WAYLAND_API )
endif ( )
2014-04-18 21:39:12 +00:00
# -Wno-attributes: "always_inline function might not be inlinable" <= real spam (thousand of warnings!!!)
# -Wno-missing-field-initializers: standard allow to init only the begin of struct/array in static init. Just a silly warning.
cmake: add -Wextra warning on GCC
Add 3 new warnings (first one must be fixed I think)
pcsx2/gui/MessageBoxes.cpp: In copy constructor ‘BaseMessageBoxEvent::BaseMessageBoxEvent(const BaseMessageBoxEvent&)’:
pcsx2/gui/MessageBoxes.cpp:62:1: warning: base class ‘class pxActionEvent’ should be explicitly initialized in the copy constructor [-Wextra]
BaseMessageBoxEvent::BaseMessageBoxEvent( const BaseMessageBoxEvent& event )
plugins/GSdx/GSPng.cpp: In function ‘bool GSPng::SaveFile(const string&, GSPng::Format, uint8*, uint8*, int, int, int, int, bool, bool)’:
/home/gregory/playstation/emulateur/pcsx2_merge/plugins/GSdx/GSPng.cpp:64:14: warning: variable ‘success’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered]
bool success = false;
^
plugins/GSdx/GSPng.cpp:44:58: warning: argument ‘image’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered]
bool SaveFile(const string& file, Format fmt, uint8* image, uint8* row,
2016-08-12 17:27:24 +00:00
# Note: future GCC (aka GCC 5.1.1) has less false positive so warning could maybe put back
2014-04-18 21:39:12 +00:00
# -Wno-unused-function: warn for function not used in release build
2014-08-02 06:42:28 +00:00
# -Wno-unused-value: lots of warning for this kind of statements "0 && ...". There are used to disable some parts of code in release/dev build.
2020-11-27 15:57:28 +00:00
# -Wno-format*: Yeah, these need to be taken care of, but...
2020-11-21 18:29:06 +00:00
# -Wno-stringop-truncation: Who comes up with these compiler warnings, anyways?
# -Wno-stringop-overflow: Probably the same people as this one...
2023-01-05 02:22:47 +00:00
# -Wno-maybe-uninitialized: Lots of gcc warnings like "‘ test.GSVector8i::<anonymous>.GSVector8i::<unnamed union>::m’ may be used uninitialized" if this is removed.
2020-11-14 04:42:18 +00:00
2021-08-04 05:43:25 +00:00
if ( MSVC )
set ( DEFAULT_WARNINGS )
else ( )
2023-04-25 08:28:47 +00:00
set ( DEFAULT_WARNINGS -Wall -Wextra -Wno-attributes -Wno-unused-function -Wno-unused-parameter -Wno-missing-field-initializers -Wno-format -Wno-format-security -Wno-unused-value )
2016-07-28 08:35:21 +00:00
endif ( )
2020-11-21 18:29:06 +00:00
if ( USE_GCC )
2023-01-07 18:18:33 +00:00
list ( APPEND DEFAULT_WARNINGS -Wno-stringop-truncation -Wno-stringop-overflow -Wno-maybe-uninitialized )
2020-11-21 18:29:06 +00:00
endif ( )
2016-12-10 21:51:21 +00:00
if ( USE_PGO_GENERATE OR USE_PGO_OPTIMIZE )
2021-04-17 22:29:55 +00:00
add_compile_options ( "-fprofile-dir=${CMAKE_SOURCE_DIR}/profile" )
2016-12-10 21:51:21 +00:00
endif ( )
2016-12-05 15:57:53 +00:00
if ( USE_PGO_GENERATE )
2021-04-17 22:29:55 +00:00
add_compile_options ( -fprofile-generate )
2016-12-05 15:57:53 +00:00
endif ( )
if ( USE_PGO_OPTIMIZE )
2021-04-17 22:29:55 +00:00
add_compile_options ( -fprofile-use )
2016-12-05 15:57:53 +00:00
endif ( )
2021-04-17 22:29:55 +00:00
list ( APPEND PCSX2_DEFS
" $ < $ < C O N F I G : D e b u g > : P C S X 2 _ D E V B U I L D ; P C S X 2 _ D E B U G ; _ D E B U G > "
" $ < $ < C O N F I G : D e v e l > : P C S X 2 _ D E V B U I L D ; _ D E V E L > " )
2014-07-11 21:33:09 +00:00
2014-07-12 17:57:26 +00:00
if ( USE_ASAN )
2021-04-17 22:29:55 +00:00
add_compile_options ( -fsanitize=address )
2022-01-06 14:44:04 +00:00
add_link_options ( -fsanitize=address )
2021-04-17 22:29:55 +00:00
list ( APPEND PCSX2_DEFS ASAN_WORKAROUND )
2014-07-12 17:57:26 +00:00
endif ( )
2021-04-17 22:29:55 +00:00
if ( USE_CLANG AND TIMETRACE )
add_compile_options ( -ftime-trace )
2015-08-08 13:25:17 +00:00
endif ( )
2023-04-25 09:10:44 +00:00
set ( PCSX2_WARNINGS ${ DEFAULT_WARNINGS } )
2015-11-14 08:47:29 +00:00
2023-01-02 03:13:12 +00:00
if ( DISABLE_BUILD_DATE )
message ( STATUS "Disabling the inclusion of the binary compile date." )
list ( APPEND PCSX2_DEFS DISABLE_BUILD_DATE )
2021-08-15 06:54:37 +00:00
endif ( )
2020-05-24 06:19:47 +00:00
#-------------------------------------------------------------------------------
# MacOS-specific things
#-------------------------------------------------------------------------------
2021-11-16 11:17:30 +00:00
if ( NOT CMAKE_GENERATOR MATCHES "Xcode" )
# Assume Xcode builds aren't being used for distribution
# Helpful because Xcode builds don't build multiple metallibs for different macOS versions
# Also helpful because Xcode's interactive shader debugger requires apps be built for the latest macOS
2023-07-19 13:49:18 +00:00
set ( CMAKE_OSX_DEPLOYMENT_TARGET 10.14 )
2020-10-22 01:43:25 +00:00
endif ( )
2020-05-24 06:19:47 +00:00
# CMake defaults the suffix for modules to .so on macOS but wx tells us that the
# extension is .dylib (so that's what we search for)
if ( APPLE )
2021-07-04 05:24:21 +00:00
set ( CMAKE_SHARED_MODULE_SUFFIX ".dylib" )
2020-05-24 06:19:47 +00:00
endif ( )
if ( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
2021-07-04 05:24:21 +00:00
if ( NOT OSX_USE_DEFAULT_SEARCH_PATH )
# Hack up the path to prioritize the path to built-in OS libraries to
# increase the chance of not depending on a bunch of copies of them
# installed by MacPorts, Fink, Homebrew, etc, and ending up copying
# them into the bundle. Since we depend on libraries which are not
# part of OS X (wx, etc.), however, don't remove the default path
# entirely. This is still kinda evil, since it defeats the user's
# path settings...
# See http://www.cmake.org/cmake/help/v3.0/command/find_program.html
list ( APPEND CMAKE_PREFIX_PATH "/usr" )
endif ( )
2021-04-17 22:29:55 +00:00
add_link_options ( -Wl,-dead_strip,-dead_strip_dylibs )
2020-11-27 15:57:28 +00:00
endif ( )