2010-06-03 17:28:20 +00:00
### Select the build type
2011-10-31 10:25:24 +00:00
# Use Release/Devel/Debug : -DCMAKE_BUILD_TYPE=Release|Devel|Debug
2011-10-30 00:32:22 +00:00
# Enable/disable the stripping : -DCMAKE_BUILD_STRIP=TRUE|FALSE
2011-10-31 10:25:24 +00:00
# generation .po based on src : -DCMAKE_BUILD_PO=TRUE|FALSE
2011-10-30 00:32:22 +00:00
2011-07-17 11:25:17 +00:00
### GCC optimization options
2010-07-07 11:36:54 +00:00
# control C flags : -DUSER_CMAKE_C_FLAGS="cflags"
# control C++ flags : -DUSER_CMAKE_CXX_FLAGS="cxxflags"
2010-07-13 09:16:13 +00:00
# control link flags : -DUSER_CMAKE_LD_FLAGS="ldflags"
2010-06-03 17:28:20 +00:00
#-------------------------------------------------------------------------------
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 )
2020-12-06 19:39:25 +00:00
option ( USE_SYSTEM_YAML "Uses a system version of yaml, if found" )
2015-07-27 18:00:47 +00:00
if ( DISABLE_BUILD_DATE OR openSUSE )
message ( STATUS "Disabling the inclusion of the binary compile date." )
add_definitions ( -DDISABLE_BUILD_DATE )
endif ( )
2015-01-06 22:45:43 +00:00
2016-11-18 21:40:52 +00:00
option ( USE_VTUNE "Plug VTUNE to profile GSdx JIT." )
2014-07-05 12:54:56 +00:00
#-------------------------------------------------------------------------------
# Graphical option
#-------------------------------------------------------------------------------
2015-07-27 22:54:04 +00:00
option ( REBUILD_SHADER "Rebuild GLSL/CG shader (developer option)" )
2014-07-05 12:54:56 +00:00
option ( BUILD_REPLAY_LOADERS "Build GS replayer to ease testing (developer option)" )
#-------------------------------------------------------------------------------
# Path and lib option
#-------------------------------------------------------------------------------
option ( PACKAGE_MODE "Use this option to ease packaging of PCSX2 (developer/distribution option)" )
2015-08-07 06:39:39 +00:00
option ( DISABLE_CHEATS_ZIP "Disable including the cheats_ws.zip file" )
option ( DISABLE_PCSX2_WRAPPER "Disable including the PCSX2-linux.sh file" )
2020-10-30 05:25:41 +00:00
option ( DISABLE_SETCAP "Do not set files capabilities" )
2014-07-05 12:54:56 +00:00
option ( XDG_STD "Use XDG standard path instead of the standard PCSX2 path" )
2021-02-23 15:45:47 +00:00
option ( PORTAUDIO_API "Build portaudio support on SPU2" ON )
2020-12-17 23:48:33 +00:00
option ( SDL2_API "Use SDL2 on SPU2 and PAD Linux (wxWidget mustn't be built with SDL1.2 support" ON )
2020-10-30 05:30:03 +00:00
option ( GTK2_API "Use GTK2 api (legacy)" )
2014-07-05 12:54:56 +00:00
if ( PACKAGE_MODE )
2014-12-21 15:48:41 +00:00
# Compile all source codes with those defines
2020-11-30 15:07:51 +00:00
add_definitions (
- D P L U G I N _ D I R _ C O M P I L A T I O N = $ { C M A K E _ I N S T A L L _ F U L L _ L I B D I R } / P C S X 2
- D G A M E I N D E X _ D I R _ C O M P I L A T I O N = $ { C M A K E _ I N S T A L L _ F U L L _ D A T A D I R } / P C S X 2
- D D O C _ D I R _ C O M P I L A T I O N = $ { C M A K E _ I N S T A L L _ F U L L _ D O C D I R }
)
2014-12-21 15:48:41 +00:00
endif ( )
2014-07-05 12:54:56 +00:00
2020-05-24 06:19:47 +00:00
if ( APPLE )
option ( OSX_USE_DEFAULT_SEARCH_PATH "Don't prioritize system library paths" OFF )
option ( SKIP_POSTPROCESS_BUNDLE "Skip postprocessing bundle for redistributability" OFF )
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
2015-01-04 03:07:16 +00:00
if ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
2014-12-28 09:05:22 +00:00
set ( USE_CLANG TRUE )
2015-01-04 05:56:47 +00:00
message ( STATUS "Building with Clang/LLVM." )
2016-07-28 08:35:21 +00:00
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
set ( USE_ICC TRUE )
message ( STATUS "Building with Intel's ICC." )
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
set ( USE_GCC TRUE )
message ( STATUS "Building with GNU GCC" )
else ( )
2019-06-18 18:33:03 +00:00
message ( FATAL_ERROR "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}" )
2014-12-28 09:05:22 +00:00
endif ( )
2016-03-30 08:19:54 +00:00
#-------------------------------------------------------------------------------
# Select the support of plugin
#-------------------------------------------------------------------------------
option ( BUILTIN_GS "Disable support of GS plugin (developer option)" )
option ( BUILTIN_PAD "Disable support of PAD plugin (developer option)" )
option ( BUILTIN_USB "Disable support of USB plugin (developer option)" )
set ( PLUGIN_SUPPORT "" )
if ( BUILTIN_GS )
set ( PLUGIN_SUPPORT "${PLUGIN_SUPPORT} -DBUILTIN_GS_PLUGIN" )
endif ( )
if ( BUILTIN_PAD )
set ( PLUGIN_SUPPORT "${PLUGIN_SUPPORT} -DBUILTIN_PAD_PLUGIN" )
endif ( )
if ( BUILTIN_USB )
set ( PLUGIN_SUPPORT "${PLUGIN_SUPPORT} -DBUILTIN_USB_PLUGIN" )
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
#-------------------------------------------------------------------------------
if ( NOT CMAKE_BUILD_TYPE MATCHES "Debug|Devel|Release|Prof" )
set ( CMAKE_BUILD_TYPE Devel )
message ( STATUS "BuildType set to ${CMAKE_BUILD_TYPE} by default" )
endif ( )
# AVX2 doesn't play well with gdb
if ( CMAKE_BUILD_TYPE MATCHES "Debug" )
SET ( DISABLE_ADVANCE_SIMD ON )
endif ( )
# Initially strip was disabled on release build but it is not stackstrace friendly!
# It only cost several MB so disbable it by default
option ( CMAKE_BUILD_STRIP "Srip binaries to save a couple of MB (developer option)" )
if ( NOT DEFINED CMAKE_BUILD_PO )
if ( CMAKE_BUILD_TYPE STREQUAL "Release" )
set ( CMAKE_BUILD_PO TRUE )
message ( STATUS "Enable the building of po files by default in ${CMAKE_BUILD_TYPE} build !!!" )
else ( )
set ( CMAKE_BUILD_PO FALSE )
message ( STATUS "Disable the building of po files by default in ${CMAKE_BUILD_TYPE} build !!!" )
endif ( )
endif ( )
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 )
message ( STATUS "Cross compilation is enabled." )
else ( )
message ( STATUS "Cross compilation is disabled." )
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 )
2014-12-24 22:12:34 +00:00
if ( ${ PCSX2_TARGET_ARCHITECTURES } MATCHES "x86_64" OR ${ PCSX2_TARGET_ARCHITECTURES } MATCHES "i386" )
message ( STATUS "Compiling a ${PCSX2_TARGET_ARCHITECTURES} build on a ${CMAKE_HOST_SYSTEM_PROCESSOR} host." )
2014-12-24 20:39:51 +00:00
else ( )
message ( FATAL_ERROR "Unsupported architecture: ${PCSX2_TARGET_ARCHITECTURES}" )
2014-07-05 12:54:56 +00:00
endif ( )
2014-12-24 22:12:34 +00:00
if ( ${ PCSX2_TARGET_ARCHITECTURES } MATCHES "i386" )
# * -fPIC option was removed for multiple reasons.
# - Code only supports the x86 architecture.
# - code uses the ebx register so it's not compliant with PIC.
# - Impacts the performance too much.
# - Only plugins. No package will link to them.
set ( CMAKE_POSITION_INDEPENDENT_CODE OFF )
2014-07-05 12:54:56 +00:00
2015-08-08 13:25:17 +00:00
if ( NOT DEFINED ARCH_FLAG )
if ( DISABLE_ADVANCE_SIMD )
2016-07-28 10:59:32 +00:00
if ( USE_ICC )
2021-05-13 08:24:04 +00:00
set ( ARCH_FLAG "-msse2 -msse4.1" )
2016-07-28 10:59:32 +00:00
else ( )
2021-05-13 08:24:04 +00:00
set ( ARCH_FLAG "-msse -msse2 -msse4.1 -mfxsr -march=i686" )
2016-07-28 10:59:32 +00:00
endif ( )
2015-08-08 13:25:17 +00:00
else ( )
# AVX requires some fix of the ABI (mangling) (default 2)
# Note: V6 requires GCC 4.7
#set(ARCH_FLAG "-march=native -fabi-version=6")
2020-08-31 02:15:22 +00:00
set ( ARCH_FLAG "-mfxsr -march=native" )
2015-08-08 13:25:17 +00:00
endif ( )
2014-07-05 12:54:56 +00:00
endif ( )
2015-08-08 13:25:17 +00:00
2014-12-24 22:12:34 +00:00
add_definitions ( -D_ARCH_32=1 -D_M_X86=1 -D_M_X86_32=1 )
set ( _ARCH_32 1 )
set ( _M_X86 1 )
set ( _M_X86_32 1 )
elseif ( ${ PCSX2_TARGET_ARCHITECTURES } MATCHES "x86_64" )
2014-07-15 22:25:34 +00:00
# x86_64 requires -fPIC
set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
2015-08-08 13:25:17 +00:00
if ( NOT DEFINED ARCH_FLAG )
if ( DISABLE_ADVANCE_SIMD )
2016-07-28 10:59:32 +00:00
if ( USE_ICC )
2021-05-13 08:24:04 +00:00
set ( ARCH_FLAG "-msse2 -msse4.1" )
2016-07-28 10:59:32 +00:00
else ( )
2021-05-13 08:24:04 +00:00
set ( ARCH_FLAG "-msse -msse2 -msse4.1 -mfxsr" )
2016-07-28 10:59:32 +00:00
endif ( )
2015-08-08 13:25:17 +00:00
else ( )
#set(ARCH_FLAG "-march=native -fabi-version=6")
set ( ARCH_FLAG "-march=native" )
endif ( )
2014-10-26 13:36:34 +00:00
endif ( )
2020-08-19 08:19:28 +00:00
add_definitions ( -D_ARCH_64=1 -D_M_X86=1 -D_M_X86_64=1 -D__M_X86_64=1 )
2014-07-15 04:00:31 +00:00
set ( _ARCH_64 1 )
set ( _M_X86 1 )
set ( _M_X86_64 1 )
2014-07-05 12:54:56 +00:00
else ( )
2014-12-24 22:12:34 +00:00
# All but i386 requires -fPIC
set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
message ( FATAL_ERROR "Unsupported architecture: ${PCSX2_TARGET_ARCHITECTURES}" )
2014-07-05 12:54:56 +00:00
endif ( )
2010-07-13 09:16:13 +00:00
#-------------------------------------------------------------------------------
# Control GCC flags
#-------------------------------------------------------------------------------
2010-07-04 12:37:42 +00:00
### Cmake set default value for various compilation variable
### Here the list of default value for documentation purpose
# ${CMAKE_SHARED_LIBRARY_CXX_FLAGS} = "-fPIC"
# ${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} = "-rdynamic"
2014-07-05 12:54:56 +00:00
#
2010-07-07 11:08:05 +00:00
# ${CMAKE_C_FLAGS} = "-g -O2"
# ${CMAKE_CXX_FLAGS} = "-g -O2"
2010-07-04 12:37:42 +00:00
# Use in debug mode
# ${CMAKE_CXX_FLAGS_DEBUG} = "-g"
# Use in release mode
# ${CMAKE_CXX_FLAGS_RELEASE} = "-O3 -DNDEBUG"
2010-07-07 11:08:05 +00:00
#-------------------------------------------------------------------------------
# Do not use default cmake flags
#-------------------------------------------------------------------------------
set ( CMAKE_C_FLAGS_DEBUG "" )
set ( CMAKE_CXX_FLAGS_DEBUG "" )
2010-07-07 11:36:54 +00:00
set ( CMAKE_C_FLAGS_DEVEL "" )
set ( CMAKE_CXX_FLAGS_DEVEL "" )
2010-07-07 11:08:05 +00:00
set ( CMAKE_C_FLAGS_RELEASE "" )
set ( CMAKE_CXX_FLAGS_RELEASE "" )
2010-07-04 12:37:42 +00:00
#-------------------------------------------------------------------------------
# Remove bad default option
#-------------------------------------------------------------------------------
# Remove -rdynamic option that can some segmentation fault when openining pcsx2 plugins
2010-07-07 11:36:54 +00:00
set ( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "" )
set ( CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "" )
2014-12-24 22:12:34 +00:00
if ( ${ PCSX2_TARGET_ARCHITECTURES } MATCHES "i386" )
2014-07-15 22:25:34 +00:00
# Remove -fPIC option on 32bit architectures.
# No good reason to use it for plugins, also it impacts performance.
set ( CMAKE_SHARED_LIBRARY_C_FLAGS "" )
set ( CMAKE_SHARED_LIBRARY_CXX_FLAGS "" )
endif ( )
2010-06-10 07:14:53 +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
#-------------------------------------------------------------------------------
2017-01-01 00:01:14 +00:00
option ( USE_LTO "Enable LTO optimization" )
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
2016-02-09 17:24:12 +00:00
# Note1: Builtin strcmp/memcmp was proved to be slower on Mesa than stdlib version.
# Note2: float operation SSE is impacted by the PCSX2 SSE configuration. In particular, flush to zero denormal.
2021-05-11 17:37:04 +00:00
set ( COMMON_FLAG "-pipe -fvisibility=hidden -pthread -fno-builtin-strcmp -fno-builtin-memcmp -mfpmath=sse -fno-operator-names" )
2019-08-25 01:47:49 +00:00
2016-12-04 17:46:02 +00:00
if ( USE_VTUNE )
set ( COMMON_FLAG "${COMMON_FLAG} -DENABLE_VTUNE" )
endif ( )
2019-08-25 01:47:49 +00:00
# Remove FORTIFY_SOURCE when compiling as debug, because it spams a lot of warnings on clang due to no optimization.
# Should probably be checked on gcc as well, as the USE_CLANG might not be needed.
if ( USE_CLANG AND CMAKE_BUILD_TYPE MATCHES "Debug" )
set ( HARDENING_FLAG "-Wformat -Wformat-security" )
else ( )
2014-07-14 11:58:06 +00:00
set ( HARDENING_FLAG "-D_FORTIFY_SOURCE=2 -Wformat -Wformat-security" )
2019-08-25 01:47:49 +00:00
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.
2019-08-23 21:40:33 +00:00
# -Wno-overloaded-virtual: Gives a fair number of warnings under clang over in the wxwidget gui section of the code.
2020-11-14 04:42:18 +00:00
# -Wno-deprecated-declarations: The USB plugins dialogs are written in straight gtk 2, which gives a million deprecated warnings. Suppress them until we can deal with them.
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...
2020-11-14 04:42:18 +00:00
2020-11-27 15:57:28 +00:00
set ( DEFAULT_WARNINGS "-Wall -Wextra -Wno-attributes -Wno-unused-function -Wno-unused-parameter -Wno-missing-field-initializers -Wno-deprecated-declarations -Wno-format -Wno-format-security -Wno-overloaded-virtual" )
2016-07-28 08:35:21 +00:00
if ( NOT USE_ICC )
set ( DEFAULT_WARNINGS "${DEFAULT_WARNINGS} -Wno-unused-value " )
endif ( )
2020-11-27 15:57:28 +00:00
if ( USE_CLANG )
set ( DEFAULT_WARNINGS "${DEFAULT_WARNINGS} -Wno-overloaded-virtual " )
endif ( )
2020-11-21 18:29:06 +00:00
if ( USE_GCC )
set ( DEFAULT_WARNINGS "${DEFAULT_WARNINGS} -Wno-stringop-truncation -Wno-stringop-overflow " )
endif ( )
2014-12-20 12:22:54 +00:00
# -Wstrict-aliasing=n: to fix one day aliasing issue. n=1/2/3
2016-07-28 08:35:21 +00:00
if ( USE_ICC )
set ( AGGRESSIVE_WARNING "-Wstrict-aliasing " )
else ( )
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
set ( AGGRESSIVE_WARNING "-Wstrict-aliasing -Wstrict-overflow=1 " )
2016-07-28 08:35:21 +00:00
endif ( )
2014-07-14 11:58:06 +00:00
2014-07-12 14:04:57 +00:00
if ( USE_CLANG )
2014-07-14 11:58:06 +00:00
# -Wno-deprecated-register: glib issue...
2016-01-09 21:57:20 +00:00
set ( DEFAULT_WARNINGS "${DEFAULT_WARNINGS} -Wno-deprecated-register -Wno-c++14-extensions" )
2016-02-21 14:57:28 +00:00
set ( DBG "-g -fno-omit-frame-pointer" )
2016-07-28 08:35:21 +00:00
elseif ( USE_ICC )
set ( DBG "-g -fno-omit-frame-pointer" )
elseif ( USE_GCC )
2016-02-21 14:57:28 +00:00
set ( DBG "-ggdb3 -fno-omit-frame-pointer" )
2014-07-12 14:04:57 +00:00
endif ( )
2015-11-15 12:54:47 +00:00
if ( USE_LTO )
2017-01-01 00:01:14 +00:00
include ( ProcessorCount )
ProcessorCount ( ncpu )
set ( LTO_FLAGS "-fuse-linker-plugin -flto=${ncpu}" )
2015-11-15 12:54:47 +00:00
set ( DBG "" ) # not supported with LTO
2016-11-22 21:10:25 +00:00
set ( CMAKE_AR /usr/bin/gcc-ar CACHE STRING "Archiver" FORCE )
set ( CMAKE_RANLIB /usr/bin/gcc-ranlib CACHE STRING "ranlib" FORCE )
set ( CMAKE_NM /usr/bin/gcc-nm CACHE STRING "nm" FORCE )
2015-11-15 12:54:47 +00:00
else ( )
set ( LTO_FLAGS "" )
endif ( )
2016-12-10 21:51:21 +00:00
if ( USE_PGO_GENERATE OR USE_PGO_OPTIMIZE )
set ( PGO_FLAGS "-fprofile-dir=${CMAKE_SOURCE_DIR}/profile" )
endif ( )
2016-12-05 15:57:53 +00:00
if ( USE_PGO_GENERATE )
set ( PGO_FLAGS "${PGO_FLAGS} -fprofile-generate" )
endif ( )
if ( USE_PGO_OPTIMIZE )
set ( PGO_FLAGS "${PGO_FLAGS} -fprofile-use" )
endif ( )
2014-12-15 18:29:05 +00:00
if ( CMAKE_BUILD_TYPE MATCHES "Debug" )
2016-02-21 15:17:10 +00:00
set ( DEBUG_FLAG "${DBG} -DPCSX2_DEVBUILD -DPCSX2_DEBUG -D_DEBUG" )
2014-12-15 18:29:05 +00:00
elseif ( CMAKE_BUILD_TYPE MATCHES "Devel" )
2016-02-21 15:17:10 +00:00
set ( DEBUG_FLAG "${DBG} -DNDEBUG -DPCSX2_DEVBUILD -D_DEVEL" )
2014-12-15 18:29:05 +00:00
elseif ( CMAKE_BUILD_TYPE MATCHES "Release" )
set ( DEBUG_FLAG "-DNDEBUG" )
2016-02-21 15:22:31 +00:00
elseif ( CMAKE_BUILD_TYPE MATCHES "Prof" )
# Keep frame pointer and debug information for profiler tool
2016-04-01 22:10:50 +00:00
set ( DEBUG_FLAG "-g -fno-omit-frame-pointer -DNDEBUG" )
2014-04-06 09:43:40 +00:00
endif ( )
2014-07-11 21:33:09 +00:00
2014-07-12 17:57:26 +00:00
if ( USE_ASAN )
2016-02-21 14:57:28 +00:00
set ( ASAN_FLAG "-fsanitize=address ${DBG} -DASAN_WORKAROUND" )
2014-07-12 17:57:26 +00:00
else ( )
set ( ASAN_FLAG "" )
endif ( )
2015-08-08 13:25:17 +00:00
if ( NOT DEFINED OPTIMIZATION_FLAG )
2015-08-09 02:10:40 +00:00
if ( CMAKE_BUILD_TYPE STREQUAL Debug )
2016-07-28 08:35:21 +00:00
if ( USE_GCC )
2016-02-21 14:57:28 +00:00
set ( OPTIMIZATION_FLAG -Og )
2016-07-28 08:35:21 +00:00
else ( )
set ( OPTIMIZATION_FLAG -O0 )
2016-02-21 14:57:28 +00:00
endif ( )
2015-08-09 02:10:40 +00:00
else ( )
set ( OPTIMIZATION_FLAG -O2 )
endif ( )
2015-08-08 13:25:17 +00:00
endif ( )
2015-11-14 08:47:29 +00:00
if ( NOT DEFINED PGO )
set ( PGO "none" )
set ( GCOV_LIBRARIES "" )
else ( )
set ( GCOV_LIBRARIES "-lgcov" )
endif ( )
2020-05-07 15:32:34 +00:00
if ( USE_CLANG )
if ( TIMETRACE )
set ( COMMON_FLAG "${COMMON_FLAG} -ftime-trace " )
endif ( )
endif ( )
2014-12-07 21:06:39 +00:00
# Note: -DGTK_DISABLE_DEPRECATED can be used to test a build without gtk deprecated feature. It could be useful to port to a newer API
2020-11-15 12:37:58 +00:00
# Disabling the hardening flags for the moment, as they spam quite a bit. ${HARDENING_FLAG}
set ( DEFAULT_GCC_FLAG "${ARCH_FLAG} ${COMMON_FLAG} ${DEFAULT_WARNINGS} ${AGGRESSIVE_WARNING} ${DEBUG_FLAG} ${ASAN_FLAG} ${OPTIMIZATION_FLAG} ${LTO_FLAGS} ${PGO_FLAGS} ${PLUGIN_SUPPORT}" )
2014-07-05 13:08:39 +00:00
# c++ only flags
2020-09-29 14:30:03 +00:00
set ( DEFAULT_CPP_FLAG "${DEFAULT_GCC_FLAG} -Wno-invalid-offsetof" )
2011-10-29 11:39:06 +00:00
2010-07-07 11:36:54 +00:00
#-------------------------------------------------------------------------------
# Allow user to set some default flags
2010-07-13 09:16:13 +00:00
# Note: string STRIP must be used to remove trailing and leading spaces.
# See policy CMP0004
2010-07-07 11:36:54 +00:00
#-------------------------------------------------------------------------------
2014-07-05 12:54:56 +00:00
# TODO: once we completely clean all flags management, this mess could be cleaned ;)
2010-07-13 09:16:13 +00:00
### linker flags
if ( DEFINED USER_CMAKE_LD_FLAGS )
message ( STATUS "Pcsx2 is very sensible with gcc flags, so use USER_CMAKE_LD_FLAGS at your own risk !!!" )
string ( STRIP "${USER_CMAKE_LD_FLAGS}" USER_CMAKE_LD_FLAGS )
2014-07-05 13:08:39 +00:00
else ( )
2010-07-13 09:16:13 +00:00
set ( USER_CMAKE_LD_FLAGS "" )
2014-07-05 13:08:39 +00:00
endif ( )
2010-07-13 09:16:13 +00:00
# ask the linker to strip the binary
2014-07-05 12:54:56 +00:00
if ( CMAKE_BUILD_STRIP )
2010-07-13 09:16:13 +00:00
string ( STRIP "${USER_CMAKE_LD_FLAGS} -s" USER_CMAKE_LD_FLAGS )
2014-07-05 13:08:39 +00:00
endif ( )
2010-07-13 09:16:13 +00:00
### c flags
# Note CMAKE_C_FLAGS is also send to the linker.
# By default allow build on amd64 machine
2010-07-07 11:36:54 +00:00
if ( DEFINED USER_CMAKE_C_FLAGS )
message ( STATUS "Pcsx2 is very sensible with gcc flags, so use USER_CMAKE_C_FLAGS at your own risk !!!" )
2010-08-09 19:05:02 +00:00
string ( STRIP "${USER_CMAKE_C_FLAGS}" CMAKE_C_FLAGS )
2014-07-05 13:08:39 +00:00
endif ( )
2010-08-09 19:05:02 +00:00
# Use some default machine flags
2011-10-29 11:39:06 +00:00
string ( STRIP "${CMAKE_C_FLAGS} ${DEFAULT_GCC_FLAG}" CMAKE_C_FLAGS )
2010-07-07 11:36:54 +00:00
2010-07-13 09:16:13 +00:00
### C++ flags
# Note CMAKE_CXX_FLAGS is also send to the linker.
# By default allow build on amd64 machine
2010-07-07 11:36:54 +00:00
if ( DEFINED USER_CMAKE_CXX_FLAGS )
message ( STATUS "Pcsx2 is very sensible with gcc flags, so use USER_CMAKE_CXX_FLAGS at your own risk !!!" )
2010-07-13 09:16:13 +00:00
string ( STRIP "${USER_CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS )
2014-07-05 13:08:39 +00:00
endif ( )
2010-08-09 19:05:02 +00:00
# Use some default machine flags
2011-10-30 00:32:22 +00:00
string ( STRIP "${CMAKE_CXX_FLAGS} ${DEFAULT_CPP_FLAG}" CMAKE_CXX_FLAGS )
2014-12-21 09:46:33 +00:00
2020-05-24 06:19:47 +00:00
#-------------------------------------------------------------------------------
# MacOS-specific things
#-------------------------------------------------------------------------------
set ( CMAKE_OSX_DEPLOYMENT_TARGET 10.9 )
2020-10-22 01:43:25 +00:00
if ( APPLE AND ${ CMAKE_OSX_DEPLOYMENT_TARGET } VERSION_LESS 10.14 )
# Older versions of the macOS stdlib don't have operator new(size_t, align_val_t)
# Disable use of them with this flag
# Not great, but also no worse that what we were getting before we turned on C++17
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-aligned-allocation" )
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 )
set ( CMAKE_SHARED_MODULE_SUFFIX ".dylib" )
endif ( )
if ( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
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 ( )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip,-dead_strip_dylibs" )
set ( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-dead_strip,-dead_strip_dylibs" )
2020-11-27 15:57:28 +00:00
endif ( )