From ccb50e7f2c5d256d88564ecbca1c4c90e7f99cfb Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 17 Dec 2022 16:06:38 +0100 Subject: [PATCH] Port yuzu-emu/yuzu#9300: "CMake: Use precompiled headers to improve compile times" (#6213) Co-authored-by: Ameer J <52414509+ameerj@users.noreply.github.com> --- CMakeLists.txt | 19 +++++++++++++++++++ src/CMakeLists.txt | 11 ++++++----- src/audio_core/CMakeLists.txt | 5 +++++ src/audio_core/precompiled_headers.h | 7 +++++++ src/citra/CMakeLists.txt | 5 +++++ src/citra/precompiled_headers.h | 7 +++++++ src/citra_qt/CMakeLists.txt | 5 +++++ src/citra_qt/precompiled_headers.h | 7 +++++++ src/common/CMakeLists.txt | 6 ++++++ src/common/common_precompiled_headers.h | 15 +++++++++++++++ src/common/precompiled_headers.h | 7 +++++++ src/core/CMakeLists.txt | 5 +++++ src/core/precompiled_headers.h | 7 +++++++ src/dedicated_room/CMakeLists.txt | 5 +++++ src/dedicated_room/precompiled_headers.h | 7 +++++++ src/input_common/CMakeLists.txt | 5 +++++ src/input_common/precompiled_headers.h | 7 +++++++ src/network/CMakeLists.txt | 5 +++++ src/network/precompiled_headers.h | 7 +++++++ src/tests/CMakeLists.txt | 5 +++++ src/tests/precompiled_headers.h | 7 +++++++ src/video_core/CMakeLists.txt | 5 +++++ src/video_core/precompiled_headers.h | 7 +++++++ src/web_service/CMakeLists.txt | 5 +++++ src/web_service/precompiled_headers.h | 7 +++++++ 25 files changed, 173 insertions(+), 5 deletions(-) create mode 100644 src/audio_core/precompiled_headers.h create mode 100644 src/citra/precompiled_headers.h create mode 100644 src/citra_qt/precompiled_headers.h create mode 100644 src/common/common_precompiled_headers.h create mode 100644 src/common/precompiled_headers.h create mode 100644 src/core/precompiled_headers.h create mode 100644 src/dedicated_room/precompiled_headers.h create mode 100644 src/input_common/precompiled_headers.h create mode 100644 src/network/precompiled_headers.h create mode 100644 src/tests/precompiled_headers.h create mode 100644 src/video_core/precompiled_headers.h create mode 100644 src/web_service/precompiled_headers.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 710f3fcfb..9d98b74fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,8 @@ CMAKE_DEPENDENT_OPTION(CITRA_USE_BUNDLED_FFMPEG "Download bundled FFmpeg binarie option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF) +option(CITRA_USE_PRECOMPILED_HEADERS "Use precompiled headers" ON) + CMAKE_DEPENDENT_OPTION(ENABLE_MF "Use Media Foundation decoder (preferred over FFmpeg)" ON "WIN32" OFF) CMAKE_DEPENDENT_OPTION(COMPILE_WITH_DWARF "Add DWARF debugging information" ON "MINGW" OFF) @@ -50,6 +52,23 @@ option(USE_SYSTEM_BOOST "Use the system Boost libs (instead of the bundled ones) CMAKE_DEPENDENT_OPTION(ENABLE_FDK "Use FDK AAC decoder" OFF "NOT ENABLE_FFMPEG_AUDIO_DECODER;NOT ENABLE_MF" OFF) +if (CITRA_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(CITRA_USE_PRECOMPILED_HEADERS OFF) + endif() + if(APPLE) + message(WARNING "Precompiled Headers currently do not work on Apple. Disabling PCH") + set(CITRA_USE_PRECOMPILED_HEADERS OFF) + endif() +endif() +if (CITRA_USE_PRECOMPILED_HEADERS) + message(STATUS "Using Precompiled Headers.") + set(CMAKE_PCH_INSTANTIATE_TEMPLATES ON) +endif() + if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/hooks/pre-commit) message(STATUS "Copying pre-commit hook") file(COPY hooks/pre-commit diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 488f92fae..f59607d66 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,6 +60,7 @@ if (MSVC) else() add_compile_options( /MP + /Zo /permissive- /EHsc /volatile:iso @@ -88,11 +89,11 @@ if (MSVC) # Since MSVC's debugging information is not very deterministic, so we have to disable it # when using ccache or other caching tools - if (NOT CITRA_USE_CCACHE) - add_compile_options( - /Zi - /Zo - ) + if (CITRA_USE_CCACHE OR CITRA_USE_PRECOMPILED_HEADERS) + # Precompiled headers are deleted if not using /Z7. See https://github.com/nanoant/CMakePCHCompiler/issues/21 + add_compile_options(/Z7) + else() + add_compile_options(/Zi) endif() # /GS- - No stack buffer overflow checks diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 54af4bf61..d8ebd37f0 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt @@ -23,6 +23,7 @@ add_library(audio_core STATIC interpolate.cpp interpolate.h null_sink.h + precompiled_headers.h sink.h sink_details.cpp sink_details.h @@ -89,3 +90,7 @@ if(ENABLE_CUBEB) target_link_libraries(audio_core PRIVATE cubeb) target_compile_definitions(audio_core PUBLIC HAVE_CUBEB) endif() + +if (CITRA_USE_PRECOMPILED_HEADERS) + target_precompile_headers(audio_core PRIVATE precompiled_headers.h) +endif() diff --git a/src/audio_core/precompiled_headers.h b/src/audio_core/precompiled_headers.h new file mode 100644 index 000000000..ffbb5e177 --- /dev/null +++ b/src/audio_core/precompiled_headers.h @@ -0,0 +1,7 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_precompiled_headers.h" diff --git a/src/citra/CMakeLists.txt b/src/citra/CMakeLists.txt index f5ef660ca..affbec3f8 100644 --- a/src/citra/CMakeLists.txt +++ b/src/citra/CMakeLists.txt @@ -10,6 +10,7 @@ add_executable(citra emu_window/emu_window_sdl2.h lodepng_image_interface.cpp lodepng_image_interface.h + precompiled_headers.h resource.h ) @@ -30,3 +31,7 @@ if (MSVC) include(CopyCitraSDLDeps) copy_citra_SDL_deps(citra) endif() + +if (CITRA_USE_PRECOMPILED_HEADERS) + target_precompile_headers(citra PRIVATE precompiled_headers.h) +endif() diff --git a/src/citra/precompiled_headers.h b/src/citra/precompiled_headers.h new file mode 100644 index 000000000..ffbb5e177 --- /dev/null +++ b/src/citra/precompiled_headers.h @@ -0,0 +1,7 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_precompiled_headers.h" diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index 29f8292d8..b95d6998a 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -164,6 +164,7 @@ add_executable(citra-qt multiplayer/state.cpp multiplayer/state.h multiplayer/validation.h + precompiled_headers.h uisettings.cpp uisettings.h qt_image_interface.cpp @@ -319,3 +320,7 @@ if (MSVC) copy_citra_FFmpeg_deps(citra-qt) endif() endif() + +if (CITRA_USE_PRECOMPILED_HEADERS) + target_precompile_headers(citra-qt PRIVATE precompiled_headers.h) +endif() diff --git a/src/citra_qt/precompiled_headers.h b/src/citra_qt/precompiled_headers.h new file mode 100644 index 000000000..ffbb5e177 --- /dev/null +++ b/src/citra_qt/precompiled_headers.h @@ -0,0 +1,7 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_precompiled_headers.h" diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 52eac11b9..0cdb362fe 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -68,6 +68,7 @@ add_library(common STATIC color.h common_funcs.h common_paths.h + common_precompiled_headers.h common_types.h construct.h file_util.cpp @@ -94,6 +95,7 @@ add_library(common STATIC misc.cpp param_package.cpp param_package.h + precompiled_headers.h quaternion.h ring_buffer.h scm_rev.cpp @@ -152,3 +154,7 @@ set_target_properties(common PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LT if (ARCHITECTURE_x86_64) target_link_libraries(common PRIVATE xbyak) endif() + +if (CITRA_USE_PRECOMPILED_HEADERS) + target_precompile_headers(common PRIVATE precompiled_headers.h) +endif() diff --git a/src/common/common_precompiled_headers.h b/src/common/common_precompiled_headers.h new file mode 100644 index 000000000..088ad512e --- /dev/null +++ b/src/common/common_precompiled_headers.h @@ -0,0 +1,15 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include + +#include + +#include "common/assert.h" +#include "common/common_types.h" diff --git a/src/common/precompiled_headers.h b/src/common/precompiled_headers.h new file mode 100644 index 000000000..ffbb5e177 --- /dev/null +++ b/src/common/precompiled_headers.h @@ -0,0 +1,7 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_precompiled_headers.h" diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 3575b048e..ddf905577 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -449,6 +449,7 @@ add_library(core STATIC movie.h perf_stats.cpp perf_stats.h + precompiled_headers.h rpc/packet.cpp rpc/packet.h rpc/rpc_server.cpp @@ -504,3 +505,7 @@ endif() if (ENABLE_FFMPEG_VIDEO_DUMPER) target_link_libraries(core PUBLIC FFmpeg::avcodec FFmpeg::avformat FFmpeg::swscale FFmpeg::swresample FFmpeg::avutil) endif() + +if (CITRA_USE_PRECOMPILED_HEADERS) + target_precompile_headers(core PRIVATE precompiled_headers.h) +endif() diff --git a/src/core/precompiled_headers.h b/src/core/precompiled_headers.h new file mode 100644 index 000000000..ffbb5e177 --- /dev/null +++ b/src/core/precompiled_headers.h @@ -0,0 +1,7 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_precompiled_headers.h" diff --git a/src/dedicated_room/CMakeLists.txt b/src/dedicated_room/CMakeLists.txt index 9dbb6784c..480c61bd9 100644 --- a/src/dedicated_room/CMakeLists.txt +++ b/src/dedicated_room/CMakeLists.txt @@ -1,6 +1,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules) add_executable(citra-room + precompiled_headers.h citra-room.cpp citra-room.rc ) @@ -22,3 +23,7 @@ target_link_libraries(citra-room PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads) if(UNIX AND NOT APPLE) install(TARGETS citra-room RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") endif() + +if (CITRA_USE_PRECOMPILED_HEADERS) + target_precompile_headers(citra-room PRIVATE precompiled_headers.h) +endif() diff --git a/src/dedicated_room/precompiled_headers.h b/src/dedicated_room/precompiled_headers.h new file mode 100644 index 000000000..ffbb5e177 --- /dev/null +++ b/src/dedicated_room/precompiled_headers.h @@ -0,0 +1,7 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_precompiled_headers.h" diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 5c4ef7512..d03284a23 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -11,6 +11,7 @@ add_library(input_common STATIC main.h motion_emu.cpp motion_emu.h + precompiled_headers.h touch_from_button.cpp touch_from_button.h sdl/sdl.cpp @@ -37,3 +38,7 @@ target_link_libraries(input_common PUBLIC core PRIVATE common ${Boost_LIBRARIES} target_include_directories(input_common PRIVATE ${LIBUSB_INCLUDE_DIR}) target_link_libraries(input_common PUBLIC ${LIBUSB_LIBRARIES}) set_target_properties(input_common PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LTO}) + +if (CITRA_USE_PRECOMPILED_HEADERS) + target_precompile_headers(input_common PRIVATE precompiled_headers.h) +endif() diff --git a/src/input_common/precompiled_headers.h b/src/input_common/precompiled_headers.h new file mode 100644 index 000000000..ffbb5e177 --- /dev/null +++ b/src/input_common/precompiled_headers.h @@ -0,0 +1,7 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_precompiled_headers.h" diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index 27bff7ce2..7ffd95368 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -7,6 +7,7 @@ add_library(network STATIC network_settings.h packet.cpp packet.h + precompiled_headers.h room.cpp room.h room_member.cpp @@ -27,3 +28,7 @@ endif() target_link_libraries(network PRIVATE common enet Boost::serialization) set_target_properties(network PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LTO}) + +if (CITRA_USE_PRECOMPILED_HEADERS) + target_precompile_headers(network PRIVATE precompiled_headers.h) +endif() diff --git a/src/network/precompiled_headers.h b/src/network/precompiled_headers.h new file mode 100644 index 000000000..ffbb5e177 --- /dev/null +++ b/src/network/precompiled_headers.h @@ -0,0 +1,7 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_precompiled_headers.h" diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 1f0968f4d..118e2c9cf 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -9,6 +9,7 @@ add_executable(tests core/hle/kernel/hle_ipc.cpp core/memory/memory.cpp core/memory/vm_manager.cpp + precompiled_headers.h audio_core/audio_fixures.h audio_core/decoder_tests.cpp ) @@ -26,3 +27,7 @@ target_link_libraries(tests PRIVATE common core video_core audio_core) target_link_libraries(tests PRIVATE ${PLATFORM_LIBRARIES} Catch2::Catch2WithMain nihstro-headers Threads::Threads) add_test(NAME tests COMMAND tests) + +if (CITRA_USE_PRECOMPILED_HEADERS) + target_precompile_headers(tests PRIVATE precompiled_headers.h) +endif() diff --git a/src/tests/precompiled_headers.h b/src/tests/precompiled_headers.h new file mode 100644 index 000000000..ffbb5e177 --- /dev/null +++ b/src/tests/precompiled_headers.h @@ -0,0 +1,7 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_precompiled_headers.h" diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 45f6e8d05..6685e26d3 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -10,6 +10,7 @@ add_library(video_core STATIC pica.h pica_state.h pica_types.h + precompiled_headers.h primitive_assembly.cpp primitive_assembly.h rasterizer_interface.h @@ -163,3 +164,7 @@ set_target_properties(video_core PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABL if (ARCHITECTURE_x86_64) target_link_libraries(video_core PUBLIC xbyak) endif() + +if (CITRA_USE_PRECOMPILED_HEADERS) + target_precompile_headers(video_core PRIVATE precompiled_headers.h) +endif() diff --git a/src/video_core/precompiled_headers.h b/src/video_core/precompiled_headers.h new file mode 100644 index 000000000..ffbb5e177 --- /dev/null +++ b/src/video_core/precompiled_headers.h @@ -0,0 +1,7 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_precompiled_headers.h" diff --git a/src/web_service/CMakeLists.txt b/src/web_service/CMakeLists.txt index 87eb06755..1fd61ffa0 100644 --- a/src/web_service/CMakeLists.txt +++ b/src/web_service/CMakeLists.txt @@ -1,6 +1,7 @@ add_library(web_service STATIC announce_room_json.cpp announce_room_json.h + precompiled_headers.h telemetry_json.cpp telemetry_json.h verify_login.cpp @@ -22,3 +23,7 @@ if (ANDROID) elseif(WIN32) target_link_libraries(web_service PRIVATE crypt32) endif() + +if (CITRA_USE_PRECOMPILED_HEADERS) + target_precompile_headers(web_service PRIVATE precompiled_headers.h) +endif() diff --git a/src/web_service/precompiled_headers.h b/src/web_service/precompiled_headers.h new file mode 100644 index 000000000..ffbb5e177 --- /dev/null +++ b/src/web_service/precompiled_headers.h @@ -0,0 +1,7 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_precompiled_headers.h"