2016-07-10 08:15:56 +00:00
# Check and configure compiler options for RPCS3
2019-06-23 05:54:42 +00:00
if ( MSVC )
2023-07-11 18:40:30 +00:00
add_compile_options ( /Zc:throwingNew- /constexpr:steps16777216 )
add_compile_definitions (
_ C R T _ S E C U R E _ N O _ D E P R E C A T E = 1 _ C R T _ N O N _ C O N F O R M I N G _ S W P R I N T F S = 1 _ S C L _ S E C U R E _ N O _ W A R N I N G S = 1
N O M I N M A X _ E N A B L E _ E X T E N D E D _ A L I G N E D _ S T O R A G E = 1 _ H A S _ E X C E P T I O N S = 0 )
add_link_options ( /DYNAMICBASE:NO /BASE:0x10000 /FIXED )
2016-07-10 08:15:56 +00:00
2019-06-28 09:01:32 +00:00
#TODO: Some of these could be cleaned up
add_compile_options ( /wd4805 ) # Comparing boolean and int
add_compile_options ( /wd4804 ) # Using integer operators with booleans
2019-10-25 10:32:21 +00:00
add_compile_options ( /wd4200 ) # Zero-sized array in struct/union
add_link_options ( /ignore:4281 ) # Undesirable base address 0x10000
2019-06-28 09:01:32 +00:00
# MSVC 2017 uses iterator as base class internally, causing a lot of warning spam
2023-07-11 18:40:30 +00:00
add_compile_definitions ( _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING=1 )
2019-06-28 09:01:32 +00:00
2019-06-23 05:54:42 +00:00
# Increase stack limit to 8 MB
2023-07-11 18:40:30 +00:00
add_link_options ( /STACK:8388608,1048576 )
2019-06-23 05:54:42 +00:00
else ( )
# Some distros have the compilers set to use PIE by default, but RPCS3 doesn't work with PIE, so we need to disable it.
2023-07-11 18:40:30 +00:00
check_cxx_compiler_flag ( "-no-pie" HAS_NO_PIE )
check_cxx_compiler_flag ( "-march=native" COMPILER_SUPPORTS_MARCH_NATIVE )
check_cxx_compiler_flag ( "-msse -msse2 -mcx16" COMPILER_X86 )
2022-04-04 19:36:13 +00:00
if ( APPLE )
2023-07-11 18:40:30 +00:00
check_cxx_compiler_flag ( "-march=armv8.4-a" COMPILER_ARM )
2022-04-04 19:36:13 +00:00
else ( )
2023-07-11 18:40:30 +00:00
check_cxx_compiler_flag ( "-march=armv8.1-a" COMPILER_ARM )
2022-04-04 19:36:13 +00:00
endif ( )
2016-07-10 08:15:56 +00:00
2019-05-10 17:24:14 +00:00
add_compile_options ( -Wall )
2020-03-09 16:18:39 +00:00
add_compile_options ( -fno-exceptions )
2021-02-08 15:47:03 +00:00
add_compile_options ( -fstack-protector )
2021-12-30 16:39:18 +00:00
2024-05-06 12:34:27 +00:00
if ( USE_NATIVE_INSTRUCTIONS AND COMPILER_SUPPORTS_MARCH_NATIVE )
add_compile_options ( -march=native )
elseif ( COMPILER_ARM )
2024-02-10 23:15:06 +00:00
# This section needs a review. Apple claims armv8.5-a on M-series but doesn't support SVE.
# Note that compared to the rest of the 8.x family, 8.1 is very restrictive and we'll have to bump the requirement in future to get anything meaningful.
2022-04-04 19:36:13 +00:00
if ( APPLE )
add_compile_options ( -march=armv8.4-a )
else ( )
add_compile_options ( -march=armv8.1-a )
endif ( )
2024-02-10 23:15:06 +00:00
elseif ( COMPILER_X86 )
# Some compilers will set both X86 and ARM, so check explicitly for ARM first
2024-02-10 14:43:36 +00:00
add_compile_options ( -msse -msse2 -mcx16 )
2021-12-30 16:39:18 +00:00
endif ( )
2017-10-06 18:52:08 +00:00
2019-12-04 20:56:19 +00:00
add_compile_options ( -Werror=old-style-cast )
2020-02-19 17:03:59 +00:00
add_compile_options ( -Werror=sign-compare )
2020-02-21 12:20:10 +00:00
add_compile_options ( -Werror=reorder )
2021-01-06 20:33:09 +00:00
add_compile_options ( -Werror=return-type )
2021-02-15 12:34:10 +00:00
add_compile_options ( -Werror=overloaded-virtual )
2021-04-07 21:52:18 +00:00
add_compile_options ( -Werror=missing-noreturn )
2024-01-07 11:56:08 +00:00
add_compile_options ( -Werror=implicit-fallthrough )
2021-03-05 19:05:37 +00:00
add_compile_options ( -Wunused-parameter )
2021-03-07 15:49:42 +00:00
add_compile_options ( -Wignored-qualifiers )
2021-03-21 15:02:21 +00:00
add_compile_options ( -Wredundant-move )
add_compile_options ( -Wcast-qual )
2021-03-29 13:20:10 +00:00
add_compile_options ( -Wdeprecated-copy )
2021-03-13 20:01:37 +00:00
add_compile_options ( -Wtautological-compare )
2021-03-08 20:41:23 +00:00
#add_compile_options(-Wshadow)
#add_compile_options(-Wconversion)
#add_compile_options(-Wpadded)
2021-03-07 16:47:29 +00:00
add_compile_options ( -Wempty-body )
2021-03-23 19:32:50 +00:00
add_compile_options ( -Wredundant-decls )
2021-04-19 08:11:24 +00:00
#add_compile_options(-Weffc++)
2020-12-29 01:07:41 +00:00
2021-03-08 20:41:23 +00:00
add_compile_options ( -Wstrict-aliasing=1 )
2021-03-01 12:03:00 +00:00
#add_compile_options(-Wnull-dereference)
2021-03-08 20:41:23 +00:00
2023-07-11 18:40:30 +00:00
if ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
2021-02-15 15:45:54 +00:00
add_compile_options ( -Werror=inconsistent-missing-override )
2024-03-10 23:31:54 +00:00
add_compile_options ( -Werror=delete-non-virtual-dtor )
2023-07-11 18:40:30 +00:00
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
2021-02-15 15:45:54 +00:00
add_compile_options ( -Werror=suggest-override )
2021-03-07 16:47:29 +00:00
add_compile_options ( -Wclobbered )
2023-07-11 18:40:30 +00:00
# add_compile_options(-Wcast-function-type)
2021-03-13 15:03:08 +00:00
add_compile_options ( -Wduplicated-branches )
2021-03-13 15:46:59 +00:00
add_compile_options ( -Wduplicated-cond )
2021-02-15 15:45:54 +00:00
endif ( )
2019-06-23 05:54:42 +00:00
#TODO Clean the code so these are removed
2023-07-11 18:40:30 +00:00
if ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
2020-03-24 10:09:52 +00:00
add_compile_options ( -fconstexpr-steps=16777216 )
2019-06-23 05:54:42 +00:00
add_compile_options ( -Wno-unused-lambda-capture )
add_compile_options ( -Wno-unused-private-field )
add_compile_options ( -Wno-unused-command-line-argument )
2024-09-22 18:39:43 +00:00
add_compile_options ( -Wno-elaborated-enum-base )
2023-07-11 18:40:30 +00:00
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
2019-06-23 05:54:42 +00:00
add_compile_options ( -Wno-class-memaccess )
2016-07-10 08:15:56 +00:00
endif ( )
2018-09-18 10:07:33 +00:00
2019-06-23 05:54:42 +00:00
if ( NOT APPLE AND NOT WIN32 )
# This hides our LLVM from mesa's LLVM, otherwise we get some unresolvable conflicts.
2023-07-11 18:40:30 +00:00
add_link_options ( -Wl,--exclude-libs,ALL )
2018-09-18 10:07:33 +00:00
2019-06-23 05:54:42 +00:00
if ( HAS_NO_PIE )
2023-07-11 18:40:30 +00:00
add_link_options ( -no-pie )
2019-06-23 05:54:42 +00:00
endif ( )
elseif ( APPLE )
2022-04-04 19:36:13 +00:00
if ( CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" )
2023-07-11 18:40:30 +00:00
add_link_options ( -Wl,-image_base,0x10000 -Wl,-pagezero_size,0x10000 )
add_link_options ( -Wl,-no_pie )
2022-04-04 19:36:13 +00:00
endif ( )
2019-06-23 05:54:42 +00:00
elseif ( WIN32 )
2023-07-11 18:40:30 +00:00
add_compile_definitions ( __STDC_FORMAT_MACROS=1 )
2019-06-23 05:54:42 +00:00
2018-09-18 10:07:33 +00:00
# Workaround for mingw64 (MSYS2)
2023-07-11 18:40:30 +00:00
add_link_options ( -Wl,--allow-multiple-definition )
2018-09-18 10:07:33 +00:00
2019-04-14 12:11:07 +00:00
# Increase stack limit to 8 MB
2023-07-11 18:40:30 +00:00
add_link_options ( -Wl,--stack -Wl,8388608 )
2024-09-08 00:45:39 +00:00
# For arm64 windows, the image base cannot be below 4GB or the OS rejects the binary without much explanation.
if ( COMPILER_X86 )
add_link_options ( -Wl,--image-base,0x10000 )
endif ( )
2018-09-18 10:07:33 +00:00
endif ( )
2024-09-07 15:17:12 +00:00
2024-09-08 11:50:36 +00:00
# Specify C++ library to use as standard C++ when using clang (not required on linux due to GNU)
if ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND ( APPLE OR WIN32 ) )
2024-09-07 15:17:12 +00:00
add_compile_options ( -stdlib=libc++ )
endif ( )
2018-09-18 10:07:33 +00:00
endif ( )