From 30feb120cea3a3c7b92b46d1ec6b5c7fed998617 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Tue, 9 Sep 2025 21:11:36 -0300 Subject: [PATCH] [cmake] USE_CCACHE option to root and fix debug usage * ccache on cmake based off SDL2 * remove debug info (/Zi) on Release build and use only on Debug builds * change to Z7 on Debug WHEN using CCACHE Signed-off-by: Caio Oliveira --- CMakeLists.txt | 27 ++++++++++++++++++------- CMakeModules/MSVCCache.cmake | 15 -------------- CMakeModules/MinGWClangCross.cmake | 21 ++++---------------- CMakeModules/MinGWCross.cmake | 32 ++++++++++-------------------- externals/CMakeLists.txt | 21 ++++++++++++++------ src/CMakeLists.txt | 11 ---------- 6 files changed, 50 insertions(+), 77 deletions(-) delete mode 100644 CMakeModules/MSVCCache.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 673aab9e6e..da7ddf7684 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,6 +180,7 @@ CMAKE_DEPENDENT_OPTION(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF option(YUZU_TESTS "Compile tests" "${BUILD_TESTING}") option(YUZU_USE_PRECOMPILED_HEADERS "Use precompiled headers" ${EXT_DEFAULT}) +set(DYNARMIC_USE_PRECOMPILED_HEADERS YUZU_USE_PRECOMPILED_HEADERS) # TODO(crueter): CI this? option(YUZU_DOWNLOAD_ANDROID_VVL "Download validation layer binary for android" ON) @@ -253,13 +254,25 @@ if (ANDROID) set(CMAKE_POLICY_VERSION_MINIMUM 3.5) # Workaround for Oboe endif() -if (YUZU_USE_PRECOMPILED_HEADERS) - if (MSVC AND CCACHE) - # buildcache does not properly cache PCH files, leading to compilation errors. - # See https://github.com/mbitsnbites/buildcache/discussions/230 - message(WARNING "buildcache does not properly support Precompiled Headers. Disabling PCH") - set(DYNARMIC_USE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE) - set(YUZU_USE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE) +# Add option to enable CCache +option(USE_CCACHE "Use ccache for compilation" OFF) +set(CCACHE_PATH "ccache" CACHE STRING "Path to ccache binary") +if(USE_CCACHE) + find_program(CCACHE_BINARY ${CCACHE_PATH}) + if(CCACHE_BINARY) + message(STATUS "Found ccache at: ${CCACHE_BINARY}") + set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_BINARY}) + set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_BINARY}) + set(CMAKE_OBJC_COMPILER_LAUNCHER ${CCACHE_BINARY}) + if(WIN32) + message(WARNING "USE_CCACHE is unstable under Windows, errors may occur...") + # we need to downgrade debug info (/Zi -> /Z7) to use an older but more cacheable format + # See https://github.com/nanoant/CMakePCHCompiler/issues/21 + string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") + endif() + else() + message(WARNING "USE_CCACHE enabled, but no executable found at: ${CCACHE_PATH}") endif() endif() diff --git a/CMakeModules/MSVCCache.cmake b/CMakeModules/MSVCCache.cmake deleted file mode 100644 index ba0d22d9ee..0000000000 --- a/CMakeModules/MSVCCache.cmake +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-FileCopyrightText: 2022 yuzu Emulator Project -# SPDX-License-Identifier: GPL-3.0-or-later - -# buildcache wrapper -OPTION(USE_CCACHE "Use buildcache for compilation" OFF) -IF(USE_CCACHE) - FIND_PROGRAM(CCACHE buildcache) - IF (CCACHE) - MESSAGE(STATUS "Using buildcache found in PATH") - SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE}) - SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE}) - ELSE(CCACHE) - MESSAGE(WARNING "USE_CCACHE enabled, but no buildcache executable found") - ENDIF(CCACHE) -ENDIF(USE_CCACHE) diff --git a/CMakeModules/MinGWClangCross.cmake b/CMakeModules/MinGWClangCross.cmake index 286a59a7ad..bdf30bd133 100644 --- a/CMakeModules/MinGWClangCross.cmake +++ b/CMakeModules/MinGWClangCross.cmake @@ -1,13 +1,14 @@ # SPDX-FileCopyrightText: 2022 yuzu Emulator Project # SPDX-License-Identifier: GPL-3.0-or-later -set(MINGW_PREFIX /usr/x86_64-w64-mingw32/) -set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_SYSTEM_PROCESSOR x86_64) +set(MINGW_FULL_PREFIX ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32) +set(MINGW_PREFIX /usr/${MINGW_FULL_PREFIX}/) +set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_FIND_ROOT_PATH ${MINGW_PREFIX}) set(SDL2_PATH ${MINGW_PREFIX}) -set(MINGW_TOOL_PREFIX ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32-) +set(MINGW_TOOL_PREFIX ${MINGW_FULL_PREFIX}-) # Specify the cross compiler set(CMAKE_C_COMPILER ${MINGW_TOOL_PREFIX}clang) @@ -23,23 +24,9 @@ set(STRIP ${MINGW_TOOL_PREFIX}strip) set(WINDRES ${MINGW_TOOL_PREFIX}windres) set(ENV{PKG_CONFIG} ${MINGW_TOOL_PREFIX}pkg-config) -# ccache wrapper -option(USE_CCACHE "Use ccache for compilation" OFF) -if(USE_CCACHE) - find_program(CCACHE ccache) - if(CCACHE) - message(STATUS "Using ccache found in PATH") - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE}) - set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE}) - else(CCACHE) - message(WARNING "USE_CCACHE enabled, but no ccache found") - endif(CCACHE) -endif(USE_CCACHE) - # Search for programs in the build host directories set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - # Echo modified cmake vars to screen for debugging purposes if(NOT DEFINED ENV{MINGW_DEBUG_INFO}) message("") diff --git a/CMakeModules/MinGWCross.cmake b/CMakeModules/MinGWCross.cmake index 61464f7dae..ce0f5cf4f1 100644 --- a/CMakeModules/MinGWCross.cmake +++ b/CMakeModules/MinGWCross.cmake @@ -1,16 +1,20 @@ +# SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +# SPDX-License-Identifier: GPL-3.0-or-later + # SPDX-FileCopyrightText: 2018 tech4me # SPDX-License-Identifier: GPL-2.0-or-later -set(MINGW_PREFIX /usr/x86_64-w64-mingw32/) -set(CMAKE_SYSTEM_NAME Windows) -set(CMAKE_SYSTEM_PROCESSOR x86_64) # Actually a hack, w/o this will cause some strange errors -set(CMAKE_HOST_WIN32 TRUE) +set(CMAKE_HOST_WIN32 TRUE) +set(CMAKE_SYSTEM_PROCESSOR x86_64) +set(MINGW_FULL_PREFIX ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32) +set(MINGW_PREFIX /usr/${MINGW_FULL_PREFIX}/) +set(CMAKE_SYSTEM_NAME Windows) -set(CMAKE_FIND_ROOT_PATH ${MINGW_PREFIX}) -set(SDL2_PATH ${MINGW_PREFIX}) -set(MINGW_TOOL_PREFIX ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32-) +set(CMAKE_FIND_ROOT_PATH ${MINGW_PREFIX}) +set(SDL2_PATH ${MINGW_PREFIX}) +set(MINGW_TOOL_PREFIX ${MINGW_FULL_PREFIX}-) # Specify the cross compiler set(CMAKE_C_COMPILER ${MINGW_TOOL_PREFIX}gcc) @@ -22,23 +26,9 @@ set(STRIP ${MINGW_TOOL_PREFIX}strip) set(WINDRES ${MINGW_TOOL_PREFIX}windres) set(ENV{PKG_CONFIG} ${MINGW_TOOL_PREFIX}pkg-config) -# ccache wrapper -option(USE_CCACHE "Use ccache for compilation" OFF) -if(USE_CCACHE) - find_program(CCACHE ccache) - if(CCACHE) - message(STATUS "Using ccache found in PATH") - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE}) - set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE}) - else(CCACHE) - message(WARNING "USE_CCACHE enabled, but no ccache found") - endif(CCACHE) -endif(USE_CCACHE) - # Search for programs in the build host directories set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - # Echo modified cmake vars to screen for debugging purposes if(NOT DEFINED ENV{MINGW_DEBUG_INFO}) message("") diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index aba5451b6d..7f68970399 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -77,12 +77,21 @@ endif() # Sirit AddJsonPackage(sirit) -if(MSVC AND USE_CCACHE AND sirit_ADDED) - get_target_property(_opts sirit COMPILE_OPTIONS) - list(FILTER _opts EXCLUDE REGEX "/Zi") - list(APPEND _opts "/Z7") - set_target_properties(sirit PROPERTIES COMPILE_OPTIONS "${_opts}") -elseif(MSVC AND CXX_CLANG) +if(WIN32) + get_target_property(sirit_opts sirit COMPILE_OPTIONS) + # Remove Debug Info on ALL Release Builds + if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") + list(FILTER sirit_opts EXCLUDE REGEX "/Zi") + endif() + # Change to old-but-more-cacheable debug info WHEN using ccache + if(CCACHE_BINARY AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")) + list(FILTER sirit_opts EXCLUDE REGEX "/Zi") + list(APPEND sirit_opts "/Z7") + endif() + set_target_properties(sirit PROPERTIES COMPILE_OPTIONS "${sirit_opts}") +endif() + +if(MSVC AND CXX_CLANG) target_compile_options(sirit PRIVATE -Wno-error=unused-command-line-argument) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 184b049d06..720266f2b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -101,17 +101,6 @@ if (MSVC AND NOT CXX_CLANG) ) endif() - if (USE_CCACHE OR YUZU_USE_PRECOMPILED_HEADERS) - # when caching, we need to use /Z7 to downgrade debug info to use an older but more cacheable format - # Precompiled headers are deleted if not using /Z7. See https://github.com/nanoant/CMakePCHCompiler/issues/21 - add_compile_options(/Z7) - # Avoid D9025 warning - string(REPLACE "/Zi" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") - string(REPLACE "/Zi" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - else() - add_compile_options(/Zi) - endif() - if (ARCHITECTURE_x86_64) add_compile_options(/QIntel-jcc-erratum) endif()