From 3d55270de69a768b1eb32079438d6c9f9a56de78 Mon Sep 17 00:00:00 2001
From: Castor215 <132155746+Castor215@users.noreply.github.com>
Date: Fri, 13 Oct 2023 23:03:50 +0100
Subject: [PATCH] externals: allow users to use system xbyak (#7068)

---
 CMakeLists.txt           | 1 +
 externals/CMakeLists.txt | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0136af311..8ac15f170 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -99,6 +99,7 @@ option(USE_SYSTEM_CPP_HTTPLIB "Use the system cpp-httplib (instead of the bundle
 option(USE_SYSTEM_JSON "Use the system JSON (nlohmann-json3) package (instead of the bundled one)" OFF)
 option(USE_SYSTEM_DYNARMIC "Use the system dynarmic (instead of the bundled one)" OFF)
 option(USE_SYSTEM_FMT "Use the system fmt (instead of the bundled one)" OFF)
+option(USE_SYSTEM_XBYAK "Use the system xbyak (instead of the bundled one)" OFF)
 
 if (CITRA_USE_PRECOMPILED_HEADERS)
     message(STATUS "Using Precompiled Headers.")
diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt
index 1d8468d46..7f3f44476 100644
--- a/externals/CMakeLists.txt
+++ b/externals/CMakeLists.txt
@@ -80,7 +80,13 @@ endif()
 
 # Xbyak
 if ("x86_64" IN_LIST ARCHITECTURE)
-    add_subdirectory(xbyak EXCLUDE_FROM_ALL)
+    if(USE_SYSTEM_XBYAK)
+        find_package(xbyak REQUIRED)
+        add_library(xbyak INTERFACE)
+        target_link_libraries(xbyak INTERFACE xbyak::xbyak)
+    else()
+        add_subdirectory(xbyak EXCLUDE_FROM_ALL)
+    endif()
 endif()
 
 # Dynarmic