From 8e9f010ee0bae1989279925e8f214bb18c36ba2e Mon Sep 17 00:00:00 2001
From: memchr <118117622+memchr@users.noreply.github.com>
Date: Mon, 4 Sep 2023 17:56:02 +0000
Subject: [PATCH] build: use PCH to reduce compile time (#3095)

---
 CMakeLists.txt  |  5 +++++
 src/meson.build |  1 +
 src/pch/pch.hpp | 29 +++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+)
 create mode 100644 src/pch/pch.hpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 067062c9..a52c798a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -71,6 +71,7 @@ endif()
 
 include_directories(
   .
+  "src/"
   "subprojects/wlroots/include/"
   "subprojects/wlroots/build/include/"
   "subprojects/udis86/"
@@ -168,6 +169,10 @@ set(CPACK_PROJECT_NAME ${PROJECT_NAME})
 set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
 include(CPack)
 
+message(STATUS "Setting precompiled headers")
+
+target_precompile_headers(Hyprland PRIVATE $<$<COMPILE_LANGUAGE:CXX>:src/pch/pch.hpp>)
+
 message(STATUS "Setting link libraries")
 
 target_link_libraries(Hyprland rt PkgConfig::deps)
diff --git a/src/meson.build b/src/meson.build
index 8430f597..2065c6f5 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -4,6 +4,7 @@ src = globber.stdout().strip().split('\n')
 executable('Hyprland', src,
   cpp_args: ['-DWLR_USE_UNSTABLE'],
   link_args: '-rdynamic',
+  cpp_pch: 'pch/pch.hpp',
   dependencies: [
     server_protos,
     dependency('wayland-server'),
diff --git a/src/pch/pch.hpp b/src/pch/pch.hpp
new file mode 100644
index 00000000..9d6c3065
--- /dev/null
+++ b/src/pch/pch.hpp
@@ -0,0 +1,29 @@
+#include "Compositor.hpp"
+
+#include <algorithm>
+#include <any>
+#include <array>
+#include <chrono>
+#include <concepts>
+#include <deque>
+#include <filesystem>
+#include <fstream>
+#include <functional>
+#include <iomanip>
+#include <iostream>
+#include <iterator>
+#include <list>
+#include <map>
+#include <memory>
+#include <mutex>
+#include <optional>
+#include <random>
+#include <ranges>
+#include <regex>
+#include <set>
+#include <sstream>
+#include <string>
+#include <thread>
+#include <tuple>
+#include <unordered_map>
+#include <vector>