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>
This commit is contained in:
Tobias 2022-12-17 16:06:38 +01:00 committed by GitHub
parent 51e252c7ed
commit ccb50e7f2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 173 additions and 5 deletions

View File

@ -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(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(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) 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) 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) if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/hooks/pre-commit)
message(STATUS "Copying pre-commit hook") message(STATUS "Copying pre-commit hook")
file(COPY hooks/pre-commit file(COPY hooks/pre-commit

View File

@ -60,6 +60,7 @@ if (MSVC)
else() else()
add_compile_options( add_compile_options(
/MP /MP
/Zo
/permissive- /permissive-
/EHsc /EHsc
/volatile:iso /volatile:iso
@ -88,11 +89,11 @@ if (MSVC)
# Since MSVC's debugging information is not very deterministic, so we have to disable it # Since MSVC's debugging information is not very deterministic, so we have to disable it
# when using ccache or other caching tools # when using ccache or other caching tools
if (NOT CITRA_USE_CCACHE) if (CITRA_USE_CCACHE OR CITRA_USE_PRECOMPILED_HEADERS)
add_compile_options( # Precompiled headers are deleted if not using /Z7. See https://github.com/nanoant/CMakePCHCompiler/issues/21
/Zi add_compile_options(/Z7)
/Zo else()
) add_compile_options(/Zi)
endif() endif()
# /GS- - No stack buffer overflow checks # /GS- - No stack buffer overflow checks

View File

@ -23,6 +23,7 @@ add_library(audio_core STATIC
interpolate.cpp interpolate.cpp
interpolate.h interpolate.h
null_sink.h null_sink.h
precompiled_headers.h
sink.h sink.h
sink_details.cpp sink_details.cpp
sink_details.h sink_details.h
@ -89,3 +90,7 @@ if(ENABLE_CUBEB)
target_link_libraries(audio_core PRIVATE cubeb) target_link_libraries(audio_core PRIVATE cubeb)
target_compile_definitions(audio_core PUBLIC HAVE_CUBEB) target_compile_definitions(audio_core PUBLIC HAVE_CUBEB)
endif() endif()
if (CITRA_USE_PRECOMPILED_HEADERS)
target_precompile_headers(audio_core PRIVATE precompiled_headers.h)
endif()

View File

@ -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"

View File

@ -10,6 +10,7 @@ add_executable(citra
emu_window/emu_window_sdl2.h emu_window/emu_window_sdl2.h
lodepng_image_interface.cpp lodepng_image_interface.cpp
lodepng_image_interface.h lodepng_image_interface.h
precompiled_headers.h
resource.h resource.h
) )
@ -30,3 +31,7 @@ if (MSVC)
include(CopyCitraSDLDeps) include(CopyCitraSDLDeps)
copy_citra_SDL_deps(citra) copy_citra_SDL_deps(citra)
endif() endif()
if (CITRA_USE_PRECOMPILED_HEADERS)
target_precompile_headers(citra PRIVATE precompiled_headers.h)
endif()

View File

@ -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"

View File

@ -164,6 +164,7 @@ add_executable(citra-qt
multiplayer/state.cpp multiplayer/state.cpp
multiplayer/state.h multiplayer/state.h
multiplayer/validation.h multiplayer/validation.h
precompiled_headers.h
uisettings.cpp uisettings.cpp
uisettings.h uisettings.h
qt_image_interface.cpp qt_image_interface.cpp
@ -319,3 +320,7 @@ if (MSVC)
copy_citra_FFmpeg_deps(citra-qt) copy_citra_FFmpeg_deps(citra-qt)
endif() endif()
endif() endif()
if (CITRA_USE_PRECOMPILED_HEADERS)
target_precompile_headers(citra-qt PRIVATE precompiled_headers.h)
endif()

View File

@ -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"

View File

@ -68,6 +68,7 @@ add_library(common STATIC
color.h color.h
common_funcs.h common_funcs.h
common_paths.h common_paths.h
common_precompiled_headers.h
common_types.h common_types.h
construct.h construct.h
file_util.cpp file_util.cpp
@ -94,6 +95,7 @@ add_library(common STATIC
misc.cpp misc.cpp
param_package.cpp param_package.cpp
param_package.h param_package.h
precompiled_headers.h
quaternion.h quaternion.h
ring_buffer.h ring_buffer.h
scm_rev.cpp scm_rev.cpp
@ -152,3 +154,7 @@ set_target_properties(common PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LT
if (ARCHITECTURE_x86_64) if (ARCHITECTURE_x86_64)
target_link_libraries(common PRIVATE xbyak) target_link_libraries(common PRIVATE xbyak)
endif() endif()
if (CITRA_USE_PRECOMPILED_HEADERS)
target_precompile_headers(common PRIVATE precompiled_headers.h)
endif()

View File

@ -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 <algorithm>
#include <array>
#include <chrono>
#include <memory>
#include <fmt/format.h>
#include "common/assert.h"
#include "common/common_types.h"

View File

@ -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"

View File

@ -449,6 +449,7 @@ add_library(core STATIC
movie.h movie.h
perf_stats.cpp perf_stats.cpp
perf_stats.h perf_stats.h
precompiled_headers.h
rpc/packet.cpp rpc/packet.cpp
rpc/packet.h rpc/packet.h
rpc/rpc_server.cpp rpc/rpc_server.cpp
@ -504,3 +505,7 @@ endif()
if (ENABLE_FFMPEG_VIDEO_DUMPER) if (ENABLE_FFMPEG_VIDEO_DUMPER)
target_link_libraries(core PUBLIC FFmpeg::avcodec FFmpeg::avformat FFmpeg::swscale FFmpeg::swresample FFmpeg::avutil) target_link_libraries(core PUBLIC FFmpeg::avcodec FFmpeg::avformat FFmpeg::swscale FFmpeg::swresample FFmpeg::avutil)
endif() endif()
if (CITRA_USE_PRECOMPILED_HEADERS)
target_precompile_headers(core PRIVATE precompiled_headers.h)
endif()

View File

@ -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"

View File

@ -1,6 +1,7 @@
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
add_executable(citra-room add_executable(citra-room
precompiled_headers.h
citra-room.cpp citra-room.cpp
citra-room.rc citra-room.rc
) )
@ -22,3 +23,7 @@ target_link_libraries(citra-room PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads)
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
install(TARGETS citra-room RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") install(TARGETS citra-room RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif() endif()
if (CITRA_USE_PRECOMPILED_HEADERS)
target_precompile_headers(citra-room PRIVATE precompiled_headers.h)
endif()

View File

@ -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"

View File

@ -11,6 +11,7 @@ add_library(input_common STATIC
main.h main.h
motion_emu.cpp motion_emu.cpp
motion_emu.h motion_emu.h
precompiled_headers.h
touch_from_button.cpp touch_from_button.cpp
touch_from_button.h touch_from_button.h
sdl/sdl.cpp 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_include_directories(input_common PRIVATE ${LIBUSB_INCLUDE_DIR})
target_link_libraries(input_common PUBLIC ${LIBUSB_LIBRARIES}) target_link_libraries(input_common PUBLIC ${LIBUSB_LIBRARIES})
set_target_properties(input_common PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LTO}) 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()

View File

@ -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"

View File

@ -7,6 +7,7 @@ add_library(network STATIC
network_settings.h network_settings.h
packet.cpp packet.cpp
packet.h packet.h
precompiled_headers.h
room.cpp room.cpp
room.h room.h
room_member.cpp room_member.cpp
@ -27,3 +28,7 @@ endif()
target_link_libraries(network PRIVATE common enet Boost::serialization) target_link_libraries(network PRIVATE common enet Boost::serialization)
set_target_properties(network PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LTO}) set_target_properties(network PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABLE_LTO})
if (CITRA_USE_PRECOMPILED_HEADERS)
target_precompile_headers(network PRIVATE precompiled_headers.h)
endif()

View File

@ -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"

View File

@ -9,6 +9,7 @@ add_executable(tests
core/hle/kernel/hle_ipc.cpp core/hle/kernel/hle_ipc.cpp
core/memory/memory.cpp core/memory/memory.cpp
core/memory/vm_manager.cpp core/memory/vm_manager.cpp
precompiled_headers.h
audio_core/audio_fixures.h audio_core/audio_fixures.h
audio_core/decoder_tests.cpp 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) target_link_libraries(tests PRIVATE ${PLATFORM_LIBRARIES} Catch2::Catch2WithMain nihstro-headers Threads::Threads)
add_test(NAME tests COMMAND tests) add_test(NAME tests COMMAND tests)
if (CITRA_USE_PRECOMPILED_HEADERS)
target_precompile_headers(tests PRIVATE precompiled_headers.h)
endif()

View File

@ -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"

View File

@ -10,6 +10,7 @@ add_library(video_core STATIC
pica.h pica.h
pica_state.h pica_state.h
pica_types.h pica_types.h
precompiled_headers.h
primitive_assembly.cpp primitive_assembly.cpp
primitive_assembly.h primitive_assembly.h
rasterizer_interface.h rasterizer_interface.h
@ -163,3 +164,7 @@ set_target_properties(video_core PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${ENABL
if (ARCHITECTURE_x86_64) if (ARCHITECTURE_x86_64)
target_link_libraries(video_core PUBLIC xbyak) target_link_libraries(video_core PUBLIC xbyak)
endif() endif()
if (CITRA_USE_PRECOMPILED_HEADERS)
target_precompile_headers(video_core PRIVATE precompiled_headers.h)
endif()

View File

@ -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"

View File

@ -1,6 +1,7 @@
add_library(web_service STATIC add_library(web_service STATIC
announce_room_json.cpp announce_room_json.cpp
announce_room_json.h announce_room_json.h
precompiled_headers.h
telemetry_json.cpp telemetry_json.cpp
telemetry_json.h telemetry_json.h
verify_login.cpp verify_login.cpp
@ -22,3 +23,7 @@ if (ANDROID)
elseif(WIN32) elseif(WIN32)
target_link_libraries(web_service PRIVATE crypt32) target_link_libraries(web_service PRIVATE crypt32)
endif() endif()
if (CITRA_USE_PRECOMPILED_HEADERS)
target_precompile_headers(web_service PRIVATE precompiled_headers.h)
endif()

View File

@ -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"