2021-04-17 17:29:55 -05:00
# Extra preprocessor definitions that will be added to all pcsx2 builds
set ( PCSX2_DEFS "" )
2024-07-25 10:04:28 -07:00
include ( GNUInstallDirs )
2015-01-06 23:45:43 +01:00
#-------------------------------------------------------------------------------
# Misc option
#-------------------------------------------------------------------------------
2020-08-19 03:19:28 -05:00
option ( ENABLE_TESTS "Enables building the unit tests" ON )
2026-06-20 20:27:55 -07:00
option ( ENABLE_RECOMPILER_TEST_HOOKS
"Compile harness hooks (recEeExecuteBlock, recEeIsBlockLinked, etc.) into the EE recompiler. Required by tests/ctest/core/recompilers; release builds should turn this off."
${ ENABLE_TESTS } )
2025-10-04 14:56:30 -04:00
option ( ENABLE_QT_UI "Enables building the PCSX2 Qt interface." ON )
2023-02-25 00:22:10 -06:00
option ( ENABLE_GSRUNNER "Enables building the GSRunner by default. It can still be built with `make pcsx2-gsrunner` otherwise." OFF )
2026-06-20 20:27:55 -07:00
option ( ENABLE_VURUNNER "Enables building pcsx2-vurunner (headless VU microprogram replayer for codegen iteration). Requires ENABLE_RECOMPILER_TEST_HOOKS=ON." OFF )
option ( ENABLE_EERUNNER "Enables building pcsx2-eerunner (headless EE JIT-vs-interpreter divergence localizer) by default. It can still be built with `make pcsx2-eerunner` otherwise." OFF )
option ( ENABLE_SDL_FRONTEND "Enables building the SDL3 / kmsdrm frontend (pcsx2-sdl) by default. It can still be built with `make pcsx2-sdl` otherwise." OFF )
2026-07-19 10:43:43 -07:00
option ( ENABLE_LIBRETRO "Build the libretro core (pcsx2-libretro / armsx2_libretro.so). Opt-in: when OFF the subdirectory is not added at all, so it never gets built or installed alongside the Qt/SDL frontends. Reconfigure with -DENABLE_LIBRETRO=ON to build it." OFF )
2021-09-01 22:32:14 -05: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 05:59:14 +02:00
option ( USE_VTUNE "Plug VTUNE to profile GS JIT." )
2026-06-20 20:27:55 -07:00
option ( USE_PERF_JITDUMP "Emit Linux perf jitdump (jit-<pid>.dump) for recompiled JIT blocks; use with perf record/inject." OFF )
option ( USE_PERF_MAP "Emit simple /tmp/perf-<pid>.map symbol table for recompiled JIT blocks." OFF )
2024-07-25 10:04:28 -07:00
option ( PACKAGE_MODE "Use this option to ease packaging of PCSX2 (developer/distribution option)" )
2025-11-21 01:19:28 -06:00
option ( BUNDLE_EMOJI_FONT "Bundles Noto Color Emoji for systems whose system emoji font isn't usable by freetype" ON )
2026-03-07 12:26:24 +00:00
option ( POSITION_INDEPENDENT_CODE "Generate position-independent code. It is recommended that you leave this on." ON )
2016-11-18 22:40:52 +01:00
2014-07-05 14:54:56 +02:00
#-------------------------------------------------------------------------------
# Graphical option
#-------------------------------------------------------------------------------
2024-02-18 22:55:27 +09:00
if ( NOT APPLE )
option ( USE_OPENGL "Enable OpenGL GS renderer" ON )
endif ()
2021-11-06 16:53:01 +10:00
option ( USE_VULKAN "Enable Vulkan GS renderer" ON )
2014-07-05 14:54:56 +02:00
#-------------------------------------------------------------------------------
# Path and lib option
#-------------------------------------------------------------------------------
2021-10-16 10:14:34 +10:00
if ( UNIX AND NOT APPLE )
2023-01-02 13:13:12 +10:00
option ( ENABLE_SETCAP "Enable networking capability for DEV9" OFF )
2021-10-16 10:14:34 +10:00
option ( X11_API "Enable X11 support" ON )
2023-01-02 13:13:12 +10:00
option ( WAYLAND_API "Enable Wayland support" ON )
2024-07-15 20:11:17 -04:00
option ( USE_BACKTRACE "Enable libbacktrace support" ON )
2023-06-27 00:18:56 -05:00
endif ()
if ( UNIX )
2023-06-06 18:24:58 +10:00
option ( USE_LINKED_FFMPEG "Links with ffmpeg instead of using dynamic loading" OFF )
2021-10-16 10:14:34 +10:00
endif ()
2020-05-24 01:19:47 -05:00
if ( APPLE )
2021-07-04 00:24:21 -05: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 01:19:47 -05:00
endif ()
2014-07-12 16:04:57 +02:00
#-------------------------------------------------------------------------------
# Compiler extra
#-------------------------------------------------------------------------------
2014-07-12 19:57:26 +02:00
option ( USE_ASAN "Enable address sanitizer" )
2014-07-12 16:04:57 +02:00
2016-05-17 19:31:39 +02: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 17:29:55 -05:00
if ( NOT CMAKE_BUILD_TYPE MATCHES "Debug|Devel|MinSizeRel|RelWithDebInfo|Release" )
2016-05-17 19:31:39 +02:00
set ( CMAKE_BUILD_TYPE Devel )
message ( STATUS "BuildType set to ${CMAKE_BUILD_TYPE} by default" )
endif ()
2021-04-17 17:29:55 -05:00
# Add Devel build type
set ( CMAKE_C_FLAGS_DEVEL "${CMAKE_C_FLAGS_RELWITHDEBINFO}"
CACHE STRING "Flags used by the C compiler during development builds" FORCE )
set ( CMAKE_CXX_FLAGS_DEVEL "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}"
CACHE STRING "Flags used by the C++ compiler during development builds" FORCE )
set ( CMAKE_LINKER_FLAGS_DEVEL "${CMAKE_LINKER_FLAGS_RELWITHDEBINFO}"
CACHE STRING "Flags used for linking binaries during development builds" FORCE )
set ( CMAKE_SHARED_LINKER_FLAGS_DEVEL "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}"
CACHE STRING "Flags used for linking shared libraries during development builds" FORCE )
2021-08-04 00:43:25 -05:00
set ( CMAKE_EXE_LINKER_FLAGS_DEVEL "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}"
CACHE STRING "Flags used for linking executables during development builds" FORCE )
2025-05-13 20:17:31 +01:00
# Exclude Debug from the configurations we can import from
set ( CMAKE_MAP_IMPORTED_CONFIG_DEVEL "RelWithDebInfo" "Release" "MinSizeRel" "None" "NoConfig" ""
2025-05-11 22:53:28 +01:00
CACHE STRING "Configurations used when importing packages for development builds" FORCE )
2021-04-17 17:29:55 -05:00
if ( CMAKE_CONFIGURATION_TYPES )
list ( INSERT CMAKE_CONFIGURATION_TYPES 0 Devel )
endif ()
2025-05-11 22:53:28 +01: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 CMAKE_MAP_IMPORTED_CONFIG_DEVEL )
2016-05-17 19:31:39 +02:00
2014-07-05 14:54:56 +02:00
#-------------------------------------------------------------------------------
# Select the architecture
#-------------------------------------------------------------------------------
2026-07-09 21:40:39 +02:00
# Detection keys off the *target* processor (CMAKE_SYSTEM_PROCESSOR), not the
2026-07-13 20:46:47 +02:00
# host, so both native and cross builds select the right arch. The spelling
# varies by toolchain (native MSVC reports "ARM64"/"AMD64"; other toolchains use
# lowercase "arm64"/"aarch64"), so each branch matches all the casings.
2026-07-09 21:40:39 +02:00
if ( "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64" OR
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64" )
2023-12-29 21:18:03 +10:00
# Multi-ISA only exists on x86.
option ( DISABLE_ADVANCE_SIMD "Disable advance use of SIMD (SSE2+ & AVX)" OFF )
2014-07-05 14:54:56 +02:00
2023-05-13 18:04:14 +10:00
list ( APPEND PCSX2_DEFS _M_X86=1 )
2026-03-10 23:40:32 -05:00
set ( ARCH_X86 TRUE )
2023-12-29 21:18:03 +10:00
if ( DISABLE_ADVANCE_SIMD )
message ( STATUS "Building for x86-64 (Multi-ISA)." )
else ()
message ( STATUS "Building for x86-64." )
endif ()
2023-12-22 23:03:25 +10:00
if ( MSVC )
2023-12-29 21:18:03 +10:00
# SSE4.1 is not set by MSVC, it uses _M_SSE instead.
2023-12-22 23:03:25 +10:00
list ( APPEND PCSX2_DEFS __SSE4_1__=1 )
2023-12-29 21:18:03 +10:00
if ( USE_CLANG_CL )
# clang-cl => need to explicitly enable SSE4.1.
add_compile_options ( "-msse4.1" )
endif ()
else ()
# Multi-ISA => SSE4, otherwise native.
if ( DISABLE_ADVANCE_SIMD )
add_compile_options ( "-msse" "-msse2" "-msse4.1" "-mfxsr" )
else ()
2023-12-30 16:53:39 +10:00
# Can't use march=native on Apple Silicon.
if ( NOT APPLE OR "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "x86_64" )
add_compile_options ( "-march=native" )
endif ()
2023-12-29 21:18:03 +10:00
endif ()
2023-12-22 23:03:25 +10:00
endif ()
2026-07-13 20:46:47 +02:00
elseif ( "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ARM64" OR
"${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AARCH64" OR
2024-03-21 16:19:17 +10:00
"${CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64" )
2026-07-09 21:40:39 +02:00
message ( STATUS "Building for ARM64." )
2026-03-10 23:40:32 -05:00
set ( ARCH_ARM64 TRUE )
if ( APPLE )
# Min spec is an M1
add_compile_options ( "-march=armv8.4-a" "-mcpu=apple-m1" )
2026-07-09 21:40:39 +02:00
elseif ( NOT MSVC )
2026-06-20 20:27:55 -07:00
# Require atomic rmw instructions (LSE, ARMv8.1+). This is the upstream
2026-07-19 10:24:29 -07:00
# default and targets the broad arm64 ecosystem. MSVC (and clang-cl)
# reject -march; their arm64 baseline already includes what we need.
# In-order ARMv8.0 cores without LSE (e.g. Cortex-A53 handhelds, RK3562)
# must build with -march=armv8-a (+ -moutline-atomics) in CMAKE_CXX_FLAGS
# — LSE atomics fault on them. Only apply the v8.1 default when the user
# hasn't chosen an -march: add_compile_options lands AFTER CMAKE_CXX_FLAGS
# on the compile line, so unconditionally adding it here silently
# overrides any user -march (proven by a casal SIGILL on a real A53 device).
2026-07-05 17:28:31 -07:00
if ( NOT CMAKE_CXX_FLAGS MATCHES "-march=" )
add_compile_options ( "-march=armv8.1-a" )
endif ()
2026-03-10 23:40:32 -05:00
endif ()
2024-03-21 16:19:17 +10:00
# If we're running on Linux, we need to detect the page/cache line size.
# It could be a virtual machine with 4K pages, or 16K with Asahi.
if ( LINUX )
detect_page_size ()
list ( APPEND PCSX2_DEFS OVERRIDE_HOST_PAGE_SIZE= ${ HOST_PAGE_SIZE } )
detect_cache_line_size ()
list ( APPEND PCSX2_DEFS OVERRIDE_HOST_CACHE_LINE_SIZE= ${ HOST_CACHE_LINE_SIZE } )
endif ()
2024-08-01 14:41:48 +01:00
2026-07-15 18:47:22 +02:00
# Windows page size matches x86-64 (4K).
2024-08-01 14:41:48 +01:00
if ( WIN32 )
list ( APPEND PCSX2_DEFS OVERRIDE_HOST_PAGE_SIZE=0x1000 )
2026-07-15 18:47:22 +02:00
# Ship a single unified binary that is optimal on both 64- and 128-byte
# cache line machines. Cache line size is only used for alignas() on hot
# cross-thread structures to avoid false sharing, so over-aligning is a
# strict superset: 128-aligned data is also 64-aligned, avoiding false
# sharing on 64-byte hosts too, at the cost of a few padding bytes.
# Compiling with the smaller value (64) would instead cause real false
# sharing when run on a 128-byte host (e.g. Windows-on-ARM in an Apple
# Silicon VM), so we always target the larger line size here.
list ( APPEND PCSX2_DEFS OVERRIDE_HOST_CACHE_LINE_SIZE=128 )
2024-08-01 14:41:48 +01:00
endif ()
2014-12-24 17:12:34 -05:00
else ()
2026-07-09 21:40:39 +02:00
message ( FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}" )
2014-07-05 14:54:56 +02:00
endif ()
2015-11-15 13:54:47 +01:00
2026-06-20 20:27:55 -07:00
# The Qt debugger UI depends on KDDockWidgets. Handheld/ARM64 targets don't ship
# the debugger, so default it off there to drop the dependency; on elsewhere to
# match upstream. Only meaningful when ENABLE_QT_UI is on.
if ( ARCH_ARM64 )
set ( _ENABLE_QT_DEBUGGER_DEFAULT OFF )
else ()
set ( _ENABLE_QT_DEBUGGER_DEFAULT ON )
endif ()
option ( ENABLE_QT_DEBUGGER "Build the Qt debugger UI (requires KDDockWidgets)." ${ _ENABLE_QT_DEBUGGER_DEFAULT } )
2023-07-19 23:49:18 +10:00
# Require C++20.
set ( CMAKE_CXX_STANDARD 20 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
2022-08-12 22:18:06 -05:00
if ( MSVC AND NOT USE_CLANG_CL )
2023-05-13 18:04:14 +10:00
add_compile_options (
"$<$<COMPILE_LANGUAGE:CXX>:/Zc:externConstexpr>"
"$<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>"
"$<$<COMPILE_LANGUAGE:CXX>:/permissive->"
2024-05-25 21:25:21 +01:00
"$<$<COMPILE_LANGUAGE:CXX>:/Zc:preprocessor>"
2026-07-10 11:20:54 +02:00
# C/C++ codegen flags only: the armasm64 assembler (ASM_MARMASM, used for
# the arm64 FastJmp) rejects /Zo and doesn't want /utf-8.
"$<$<COMPILE_LANGUAGE:C,CXX>:/Zo>"
"$<$<COMPILE_LANGUAGE:C,CXX>:/utf-8>"
2023-05-13 18:04:14 +10:00
)
2022-12-29 00:02:53 +10:00
endif ()
if ( MSVC )
# Disable Exceptions
string ( REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${ CMAKE_CXX_FLAGS } )
else ()
2023-06-28 23:41:30 +10:00
add_compile_options ( -pipe -fvisibility=hidden -pthread )
2022-12-29 00:02:53 +10:00
add_compile_options (
"$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>"
)
2026-06-20 20:27:55 -07:00
# GCC/Clang warn on every __fi (always_inline) function definition that lacks
# an explicit `inline` keyword. PCSX2 deliberately defines __fi without
# `inline` so that .cpp-defined __fi functions still emit a strong external
# symbol; adding `inline` to the macro globally breaks linkage for those. The
# attribute itself works correctly either way, so suppress the noise.
# Unconditional (not the GNU-only DEFAULT_WARNINGS entry below) because the
# primary toolchain here is Clang, which the GCC-gated list does not cover.
add_compile_options ( -Wno-attributes )
2021-08-04 00:43:25 -05:00
endif ()
2022-08-14 16:21:23 -05: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 00:43:25 -05:00
if ( WIN32 )
2021-09-03 21:33:11 -05:00
add_compile_definitions (
$< $<CONFIG:Debug > :_ITERATOR_DEBUG_LEVEL=2>
$< $<CONFIG:Devel > :_ITERATOR_DEBUG_LEVEL=1>
2022-08-14 16:21:23 -05:00
$< ${CONFIG_ANY_REL}:_ITERATOR_DEBUG_LEVEL=0 >
2022-12-29 00:02:53 +10:00
_HAS_EXCEPTIONS=0
2021-09-03 21:33:11 -05:00
)
2023-12-22 21:57:49 +10:00
list ( APPEND PCSX2_DEFS
_CRT_NONSTDC_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS
CRT_SECURE_NO_DEPRECATE
_SCL_SECURE_NO_WARNINGS
_UNICODE
UNICODE
)
else ()
# Assume everything else is POSIX.
list ( APPEND PCSX2_DEFS
__POSIX__
)
2021-08-04 00:43:25 -05:00
endif ()
2019-08-24 18:47:49 -07:00
2023-03-20 01:33:15 +10:00
# Enable debug information in release builds for Linux.
# Makes the backtrace actually meaningful.
2023-12-29 21:18:03 +10:00
if ( LINUX )
2023-03-21 22:42:28 +10:00
add_compile_options ( $< $<CONFIG:Release > :-g1> )
2023-03-20 01:33:15 +10:00
endif ()
2022-08-14 16:21:23 -05:00
if ( MSVC )
2026-07-10 11:20:54 +02:00
# Enable PDB generation in release builds (C/C++ only; armasm64 doesn't take /Zi)
2022-08-14 16:21:23 -05:00
add_compile_options (
2026-07-10 11:20:54 +02:00
$< $<AND:${CONFIG_REL_NO_DEB},$<COMPILE_LANGUAGE:C,CXX > >:/Zi>
2022-08-14 16:21:23 -05:00
)
add_link_options (
$< ${CONFIG_REL_NO_DEB}:/DEBUG >
$< ${CONFIG_REL_NO_DEB}:/OPT:REF >
$< ${CONFIG_REL_NO_DEB}:/OPT:ICF >
)
endif ()
2024-07-25 10:04:28 -07:00
if ( PACKAGE_MODE )
file ( RELATIVE_PATH relative_datadir ${ CMAKE_INSTALL_FULL_BINDIR } ${ CMAKE_INSTALL_FULL_DATADIR } /PCSX2 )
# Compile all source codes with those defines
list ( APPEND PCSX2_DEFS
PCSX2_APP_DATADIR= "${relative_datadir}" )
endif ()
2016-12-04 18:46:02 +01:00
if ( USE_VTUNE )
2021-04-17 17:29:55 -05:00
list ( APPEND PCSX2_DEFS ENABLE_VTUNE )
2019-08-24 18:47:49 -07:00
endif ()
2026-06-20 20:27:55 -07:00
if ( USE_PERF_JITDUMP AND USE_PERF_MAP )
message ( FATAL_ERROR "USE_PERF_JITDUMP and USE_PERF_MAP are mutually exclusive; pick one." )
endif ()
if ( USE_PERF_JITDUMP )
if ( NOT UNIX OR APPLE )
message ( FATAL_ERROR "USE_PERF_JITDUMP is Linux-only." )
endif ()
list ( APPEND PCSX2_DEFS ENABLE_PERF_JITDUMP )
endif ()
if ( USE_PERF_MAP )
if ( NOT UNIX OR APPLE )
message ( FATAL_ERROR "USE_PERF_MAP is Linux-only." )
endif ()
list ( APPEND PCSX2_DEFS ENABLE_PERF_MAP )
endif ()
2022-04-03 14:49:49 +10:00
if ( USE_OPENGL )
list ( APPEND PCSX2_DEFS ENABLE_OPENGL )
endif ()
2021-11-06 16:53:01 +10:00
if ( USE_VULKAN )
list ( APPEND PCSX2_DEFS ENABLE_VULKAN )
endif ()
2021-10-16 10:14:34 +10:00
if ( X11_API )
list ( APPEND PCSX2_DEFS X11_API )
endif ()
if ( WAYLAND_API )
list ( APPEND PCSX2_DEFS WAYLAND_API )
endif ()
2026-06-20 20:27:55 -07:00
if ( ENABLE_SDL_FRONTEND )
list ( APPEND PCSX2_DEFS ENABLE_SDL_FRONTEND )
endif ()
2014-04-18 23:39:12 +02: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.
# -Wno-unused-function: warn for function not used in release build
2020-11-13 20:42:18 -08:00
2021-08-04 00:43:25 -05:00
if ( MSVC )
set ( DEFAULT_WARNINGS )
else ()
2024-01-06 00:40:43 -05:00
set ( DEFAULT_WARNINGS -Wall -Wextra -Wno-unused-function -Wno-unused-parameter -Wno-missing-field-initializers )
2020-11-21 10:29:06 -08:00
endif ()
2026-04-16 22:02:24 -05:00
if ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
list ( APPEND DEFAULT_WARNINGS -Wno-attributes )
endif ()
2020-11-21 10:29:06 -08:00
2016-12-10 21:51:21 +00:00
if ( USE_PGO_GENERATE OR USE_PGO_OPTIMIZE )
2021-04-17 17:29:55 -05:00
add_compile_options ( "-fprofile-dir=${CMAKE_SOURCE_DIR}/profile" )
2016-12-10 21:51:21 +00:00
endif ()
2016-12-05 10:57:53 -05:00
if ( USE_PGO_GENERATE )
2021-04-17 17:29:55 -05:00
add_compile_options ( -fprofile-generate )
2016-12-05 10:57:53 -05:00
endif ()
if ( USE_PGO_OPTIMIZE )
2021-04-17 17:29:55 -05:00
add_compile_options ( -fprofile-use )
2016-12-05 10:57:53 -05:00
endif ()
2021-04-17 17:29:55 -05:00
list ( APPEND PCSX2_DEFS
"$<$<CONFIG:Debug>:PCSX2_DEVBUILD;PCSX2_DEBUG;_DEBUG>"
"$<$<CONFIG:Devel>:PCSX2_DEVBUILD;_DEVEL>" )
2014-07-11 23:33:09 +02:00
2014-07-12 19:57:26 +02:00
if ( USE_ASAN )
2021-04-17 17:29:55 -05:00
add_compile_options ( -fsanitize=address )
2022-01-06 09:44:04 -05:00
add_link_options ( -fsanitize=address )
2021-04-17 17:29:55 -05:00
list ( APPEND PCSX2_DEFS ASAN_WORKAROUND )
2014-07-12 19:57:26 +02:00
endif ()
2021-04-17 17:29:55 -05:00
if ( USE_CLANG AND TIMETRACE )
add_compile_options ( -ftime-trace )
2015-08-08 16:25:17 +03:00
endif ()
2023-04-25 12:10:44 +03:00
set ( PCSX2_WARNINGS ${ DEFAULT_WARNINGS } )
2015-11-14 09:47:29 +01:00
2026-03-07 12:26:24 +00:00
if ( POSITION_INDEPENDENT_CODE )
# Make sure position-independent code is enabled properly.
# Without this check, on some platforms (e.g. Fedora 43) the right flags
# won't be passed to the linker, resulting in a broken build when link time
# optimization is enabled (even with a cmake version >= 3.14).
if ( NOT MSVC )
include ( CheckPIESupported )
check_pie_supported ( OUTPUT_VARIABLE PIE_SUPPORTED_OUTPUT LANGUAGES C CXX )
2026-03-06 12:42:26 +00:00
2026-03-07 12:26:24 +00:00
if (( NOT CMAKE_C_LINK_PIE_SUPPORTED ) OR ( NOT CMAKE_CXX_LINK_PIE_SUPPORTED ))
message ( WARNING
"The POSITION_INDEPENDENT_CODE option is enabled but is not "
"supported at link time:\n${PIE_SUPPORTED_OUTPUT}" )
endif ()
endif ()
set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
else ()
if ( CMAKE_INTERPROCEDURAL_OPTIMIZATION )
message ( WARNING
"The CMAKE_INTERPROCEDURAL_OPTIMIZATION option is enabled but the "
2026-06-02 11:35:38 +01:00
"POSITION_INDEPENDENT_CODE option is disabled. This has been found "
"to result in broken builds on certain platforms." )
2026-03-07 12:26:24 +00:00
endif ()
set ( CMAKE_POSITION_INDEPENDENT_CODE OFF )
endif ()
2026-03-06 12:42:26 +00:00
2020-05-24 01:19:47 -05:00
#-------------------------------------------------------------------------------
# MacOS-specific things
#-------------------------------------------------------------------------------
2021-11-16 05:17:30 -06: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-10-13 21:35:41 +10:00
set ( CMAKE_OSX_DEPLOYMENT_TARGET 11.0 )
2020-10-21 20:43:25 -05:00
endif ()
2020-05-24 01:19:47 -05: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 00:24:21 -05:00
set ( CMAKE_SHARED_MODULE_SUFFIX ".dylib" )
2020-05-24 01:19:47 -05:00
endif ()
if ( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
2021-07-04 00:24:21 -05: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 ()
2020-05-24 01:19:47 -05:00
2021-04-17 17:29:55 -05:00
add_link_options ( -Wl,-dead_strip,-dead_strip_dylibs )
2020-11-27 16:57:28 +01:00
endif ()