From 7a2bd13f5bf00153fc543daa779c1037ecbe4298 Mon Sep 17 00:00:00 2001
From: Alexandre Bouvier <contact@amb.tf>
Date: Thu, 5 Jan 2023 05:00:44 +0100
Subject: [PATCH] cmake: support the standard cmake testing option

---
 CMakeLists.txt           | 9 +++++----
 externals/CMakeLists.txt | 3 +++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 658a2816b5..f91ba950aa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,12 +3,14 @@
 
 cmake_minimum_required(VERSION 3.22)
 
+project(yuzu)
+
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/externals/cmake-modules")
+
 include(DownloadExternals)
 include(CMakeDependentOption)
-
-project(yuzu)
+include(CTest)
 
 # Set bundled sdl2/qt as dependent options.
 # OFF by default, but if ENABLE_SDL2 and MSVC are true then ON
@@ -42,7 +44,7 @@ option(ENABLE_CUBEB "Enables the cubeb audio backend" ON)
 
 option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF)
 
-option(YUZU_TESTS "Compile tests" ON)
+option(YUZU_TESTS "Compile tests" "${BUILD_TESTING}")
 
 option(YUZU_USE_PRECOMPILED_HEADERS "Use precompiled headers" ON)
 
@@ -606,7 +608,6 @@ if (YUZU_USE_FASTER_LD AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
     endif()
 endif()
 
-enable_testing()
 add_subdirectory(externals)
 add_subdirectory(src)
 
diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt
index dfd40cba67..291ef96ee9 100644
--- a/externals/CMakeLists.txt
+++ b/externals/CMakeLists.txt
@@ -5,6 +5,9 @@
 # some of its variables, which is only possible in 3.13+
 set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
 
+# Disable tests in all externals supporting the standard option name
+set(BUILD_TESTING OFF)
+
 # xbyak
 if ((ARCHITECTURE_x86 OR ARCHITECTURE_x86_64) AND NOT TARGET xbyak::xbyak)
     add_subdirectory(xbyak EXCLUDE_FROM_ALL)