diff --git a/ares/n64/CMakeLists.txt b/ares/n64/CMakeLists.txt index 359698a83..97ea264c8 100644 --- a/ares/n64/CMakeLists.txt +++ b/ares/n64/CMakeLists.txt @@ -36,13 +36,6 @@ elseif(OS_LINUX OR OS_FREEBSD OR OS_OPENBSD) include(cmake/os-linux.cmake) endif() -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - message(WARNING " -Building N64 with optimizations under GCC currently results in broken graphical output, see \ -https://github.com/ares-emulator/ares/issues/1737 . Building with clang instead will work around this issue. \ -") -endif() - ares_add_sources( CORE # n64 diff --git a/cmake/common/compiler_common.cmake b/cmake/common/compiler_common.cmake index b2ca7a238..b0ec45a8c 100644 --- a/cmake/common/compiler_common.cmake +++ b/cmake/common/compiler_common.cmake @@ -100,11 +100,7 @@ set( -Wno-delete-non-abstract-non-virtual-dtor ) -set( - _ares_gcc_common_options - -fwrapv - -fno-strict-aliasing -) +set(_ares_gcc_common_options -fwrapv -fno-strict-aliasing -Wno-unused-result) if(NOT DEFINED CMAKE_COMPILE_WARNING_AS_ERROR) set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) diff --git a/cmake/linux/compilerconfig.cmake b/cmake/linux/compilerconfig.cmake index 18fed7eba..78d4d2b95 100644 --- a/cmake/linux/compilerconfig.cmake +++ b/cmake/linux/compilerconfig.cmake @@ -3,6 +3,17 @@ include_guard(GLOBAL) option(ENABLE_COMPILER_TRACE "Enable clang time-trace" OFF) mark_as_advanced(ENABLE_COMPILER_TRACE) +option( + ARES_BUILD_LOCAL + "Allows the compiler to generate code optimized for the target machine; increases performance." + ON +) +option( + ARES_ENABLE_MINIMUM_CPU + "Defines a project minimum instruction set version in order to expose advanced SSE functionality to the compiler. Currently x86-64-v2 on x86_64; not defined on arm64." + ON +) + include(ccache) include(compiler_common) @@ -14,7 +25,16 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") -fwrapv ) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - add_compile_options( - ${_ares_gcc_common_options} - ) + add_compile_options(${_ares_gcc_common_options}) +endif() + +if(ARES_BUILD_LOCAL) + add_compile_options($<$>:-march=native>) +else() + if(ARES_ENABLE_MINIMUM_CPU) + string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} LOWERCASE_CMAKE_SYSTEM_PROCESSOR) + if(LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86|x86|x64|x86_64|amd64|e2k)") + add_compile_options($<$>:-march=x86-64-v2>) + endif() + endif() endif() diff --git a/cmake/macos/compilerconfig.cmake b/cmake/macos/compilerconfig.cmake index cc0039fd9..7df108d62 100644 --- a/cmake/macos/compilerconfig.cmake +++ b/cmake/macos/compilerconfig.cmake @@ -5,12 +5,18 @@ include_guard(GLOBAL) option(ENABLE_COMPILER_TRACE "Enable clang time-trace" OFF) mark_as_advanced(ENABLE_COMPILER_TRACE) +option( + ARES_BUILD_LOCAL + "Allows the compiler to generate code optimized for the target machine; increases performance. Also disables certain entitlements and runtime options that interfere with debugging but are required for notarization and distribution." + ON +) + include(ccache) include(compiler_common) # Enable selection between arm64 and x86_64 targets if(NOT CMAKE_OSX_ARCHITECTURES) - set(CMAKE_OSX_ARCHITECTURES arm64 CACHE STRING "Build architectures for macOS" FORCE) + set(CMAKE_OSX_ARCHITECTURES ${CMAKE_SYSTEM_PROCESSOR} CACHE STRING "Build architectures for macOS" FORCE) endif() set_property(CACHE CMAKE_OSX_ARCHITECTURES PROPERTY STRINGS arm64 x86_64) @@ -38,6 +44,16 @@ string(APPEND CMAKE_CXX_FLAGS_RELEASE " -g") string(APPEND CMAKE_OBJC_FLAGS_RELEASE " -g") string(APPEND CMAKE_OBJCXX_FLAGS_RELEASE " -g") +if(ARES_BUILD_LOCAL) + add_compile_options($<$>:-march=native>) +else() + if(CMAKE_OSX_ARCHITECTURES MATCHES arm64) + # + else() + add_compile_options($<$>:-march=x86-64-v2>) + endif() +endif() + if(ENABLE_COMPILER_TRACE) add_compile_options(-ftime-trace) add_link_options(LINKER:-print_statistics) diff --git a/cmake/macos/defaults.cmake b/cmake/macos/defaults.cmake index 3efcfe190..823909534 100644 --- a/cmake/macos/defaults.cmake +++ b/cmake/macos/defaults.cmake @@ -2,6 +2,7 @@ include_guard(GLOBAL) +# Required to avoid us finding a system SDL2.framework before our provided SDL2.dylib set(CMAKE_FIND_FRAMEWORK LAST) # Set empty codesigning team if not specified as cache variable diff --git a/cmake/windows/compilerconfig.cmake b/cmake/windows/compilerconfig.cmake index 2aeaa68a0..fac2323c3 100644 --- a/cmake/windows/compilerconfig.cmake +++ b/cmake/windows/compilerconfig.cmake @@ -4,6 +4,12 @@ endif() include_guard(GLOBAL) +option( + ARES_BUILD_LOCAL + "Allows the compiler to generate code optimized for the target machine; increases performance." + ON +) + include(ccache) include(compiler_common) @@ -53,7 +59,6 @@ set( set( _ares_clang_cl_c_cxx_options - -Wno-unused-function -Wno-reorder-ctor -Wno-missing-braces -Wno-char-subscripts @@ -69,30 +74,36 @@ if(MSVC) string(REPLACE "/Ob1" "/Ob2" CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_C_FLAGS_RELWITHDEBINFO}) endif() -# add compiler flags +# add general compiler flags and optimizations if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # we are on either msys2/mingw clang, or clang-cl # add common options add_compile_options( "$<$:${_ares_clang_c_options}>" "$<$:${_ares_clang_cxx_options}>" - "$<$:${_ares_clang_cl_c_cxx_options}>" ) if(NOT MSVC) # we are on msys2 clang # statically link libc++ add_link_options(-static-libstdc++) + # msys2/mingw-specific invocations to make clang emit debug symbols set(_ares_mingw_clang_debug_compile_options -g -gcodeview) set(_ares_mingw_clang_debug_link_options -fuse-ld=lld -g -Wl,--pdb=) add_compile_options("$<$:${_ares_mingw_clang_debug_compile_options}>") add_link_options("$<$:${_ares_mingw_clang_debug_link_options}>") - # clang-cl does not understand -fwrapv, but we do want it on msys2 clang + add_compile_options(-fwrapv) else() + # we are on clang-cl # generate PDBs rather than embed debug symbols set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT ProgramDatabase) - add_compile_options("$<$:${_ares_msvc_cxx_options}>") + + add_compile_options( + "$<$:${_ares_msvc_cxx_options}>" + "$<$:${_ares_clang_cl_c_cxx_options}>" + ) + # work around https://gitlab.kitware.com/cmake/cmake/-/issues/26559 add_compile_options($<$,$>>:-flto=thin>) add_link_options( @@ -102,19 +113,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") $<$>:/OPT:REF> $<$>:/OPT:ICF> ) - # add -fwrapv - add_compile_options( - "$<$:/clang:-fwrapv>" - ) - endif() - # optimizations - if(ARES_BUILD_LOCAL) - add_compile_options(-march=native) - else() - if(${arch} STREQUAL x64) - add_compile_options("$<$:-march=x86-64-v2>") - endif() + # add -fwrapv + add_compile_options("$<$:/clang:-fwrapv>") endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_compile_options("$<$:${_ares_msvc_cxx_options}>") @@ -122,9 +123,24 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_link_options(/WX) endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - add_compile_options( - ${_ares_gcc_common_options} - ) + add_compile_options(${_ares_gcc_common_options}) +endif() + +# arch/machine-specific optimizations +if(ARES_BUILD_LOCAL) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_compile_options($<$>:-march=native>) + else() + # todo: arch optimizations on msvc + endif() +else() + if(${arch} STREQUAL x64) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_compile_options("$<$:-march=x86-64-v2>") + endif() + else() + # todo: arm64 arch baseline + endif() endif() if(NOT MINGW) diff --git a/desktop-ui/cmake/os-windows.cmake b/desktop-ui/cmake/os-windows.cmake index 7b25aea1f..c36fbe302 100644 --- a/desktop-ui/cmake/os-windows.cmake +++ b/desktop-ui/cmake/os-windows.cmake @@ -3,10 +3,7 @@ target_sources(desktop-ui PRIVATE resource/ares.rc resource/ares.Manifest) set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT desktop-ui) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_link_libraries( - desktop-ui - PRIVATE mingw32 - ) + target_link_libraries(desktop-ui PRIVATE mingw32) endif() if(ARES_ENABLE_LIBRASHADER) diff --git a/mia/CMakeLists.txt b/mia/CMakeLists.txt index 2846096da..85e0fc03a 100644 --- a/mia/CMakeLists.txt +++ b/mia/CMakeLists.txt @@ -129,10 +129,7 @@ if(ARES_BUILD_OPTIONAL_TARGETS) if(OS_WINDOWS) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_link_libraries( - mia-ui - PRIVATE nall - ) + target_link_libraries(mia-ui PRIVATE nall) endif() endif()