From 286479198f19a94c6a57b5799f470cb855c4670e Mon Sep 17 00:00:00 2001 From: Chris Miles Date: Sun, 17 Dec 2023 19:04:21 -0600 Subject: [PATCH] [Compilation] Use pre-compiled headers for Windows (speed) (#3778) * Experiment with PCH * Another run * GCC test * Different test * Another one * Another one * Lua headers * PCH main zone primitives * Tweaks * Tweaks * Tweaks * Add EQEMU_BUILD_PCH option default to ON --- CMakeLists.txt | 1 + common/CMakeLists.txt | 3 +++ common/pch/pch.h | 34 ++++++++++++++++++++++++++++++++++ world/CMakeLists.txt | 4 ++++ zone/CMakeLists.txt | 6 ++++++ 5 files changed, 48 insertions(+) create mode 100644 common/pch/pch.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c771ae206..ea68bedcc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ SET(CMAKE_CXX_STANDARD_REQUIRED ON) SET(CMAKE_CXX_EXTENSIONS OFF) OPTION(EQEMU_BUILD_STATIC "Build with static linking" OFF) +OPTION(EQEMU_BUILD_PCH "Build with precompiled headers (Windows)" ON) IF (EQEMU_BUILD_STATIC) SET(BUILD_SHARED_LIBS OFF) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 517d0081e..d21fa0c79 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -792,5 +792,8 @@ IF (UNIX) SET_SOURCE_FILES_PROPERTIES("patches/sod.cpp" "patches/sof.cpp" "patches/rof.cpp" "patches/rof2.cpp" "patches/uf.cpp" PROPERTIES COMPILE_FLAGS -O0) ENDIF (UNIX) +IF (WIN32 AND EQEMU_BUILD_PCH) + TARGET_PRECOMPILE_HEADERS(common PRIVATE pch/pch.h) +ENDIF() SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) diff --git a/common/pch/pch.h b/common/pch/pch.h new file mode 100644 index 000000000..06b1d1a8f --- /dev/null +++ b/common/pch/pch.h @@ -0,0 +1,34 @@ +// types +#include +#include +#include +#include + +// containers +#include +#include +#include +#include +#include +#include +#include + +// utilities +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// fmt +#include + +// lua +#include "lua.hpp" +#include +#include diff --git a/world/CMakeLists.txt b/world/CMakeLists.txt index c46b68d84..2d4c6ebaa 100644 --- a/world/CMakeLists.txt +++ b/world/CMakeLists.txt @@ -78,6 +78,10 @@ ADD_EXECUTABLE(world ${world_sources} ${world_headers}) INSTALL(TARGETS world RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) +IF (WIN32 AND EQEMU_BUILD_PCH) + TARGET_PRECOMPILE_HEADERS(world PRIVATE ../common/pch/pch.h) +ENDIF () + ADD_DEFINITIONS(-DWORLD) TARGET_LINK_LIBRARIES(world ${SERVER_LIBS}) diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index fd3c28dc5..faa976ab9 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -284,6 +284,12 @@ ADD_EXECUTABLE(zone ${zone_sources} ${zone_headers}) INSTALL(TARGETS zone RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) +IF (WIN32 AND EQEMU_BUILD_PCH) + TARGET_PRECOMPILE_HEADERS(zone PRIVATE ../common/pch/pch.h) + TARGET_PRECOMPILE_HEADERS(zone PRIVATE ../common/types.h ../common/eqemu_logsys.h ../common/eqemu_logsys_log_aliases.h ../common/features.h ../common/global_define.h) + TARGET_PRECOMPILE_HEADERS(zone PRIVATE mob.h npc.h corpse.h doors.h bot.h entity.h client.h zone.h) +ENDIF() + ADD_DEFINITIONS(-DZONE) TARGET_LINK_LIBRARIES(zone ${ZONE_LIBS})