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(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

View file

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

View file

@ -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()

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
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()

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.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()

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
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()

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
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()

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)
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()

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
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()

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
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()

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/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()

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_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()

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
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()

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"