From fef1906d0d7050b1dfa3792f6e8d3a9b9632df68 Mon Sep 17 00:00:00 2001
From: Conrad Kostecki <conrad+github@kostecki.com>
Date: Sat, 9 Nov 2019 21:20:16 +0100
Subject: [PATCH] CMakeLists.txt: make discord-rpc and google benchmark
 optional (#10208)

For a package maintainer, it should be possible to disable the support
for discord-rpc and google benchmark, as it currently always includes them,
when the library if found.
---
 CMakeLists.txt              | 26 +++++++++++++++-----------
 src/openrct2/CMakeLists.txt | 18 ++++++++++--------
 2 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ea4bdfd8221..7dda401bbdd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,6 +42,8 @@ CMAKE_DEPENDENT_OPTION(DOWNLOAD_REPLAYS "Download replays during installation."
 option(STATIC "Create a static build.")
 option(USE_MMAP "Use mmap to try loading rct2's data segment into memory.")
 
+option(DISABLE_DISCORD_RPC "Disable Discord-RPC support." OFF)
+option(DISABLE_GOOGLE_BENCHMARK "Disable Google Benchmarks support." OFF)
 option(DISABLE_HTTP_TWITCH "Disable HTTP and Twitch support.")
 option(DISABLE_NETWORK "Disable multiplayer functionality. Mainly for testing.")
 option(DISABLE_TTF "Disable support for TTF provided by freetype2.")
@@ -125,17 +127,19 @@ if (CXX_WARN_SUGGEST_FINAL_METHODS)
    add_definitions(-D__WARN_SUGGEST_FINAL_METHODS__)
 endif ()
 
-if(EXISTS "${ROOT_DIR}/discord-rpc")
-    # Don't build discord's examples, some of which are in C and do not honour
-    # the flags we set for C++. Also we don't use the provided examples.
-    set(BUILD_EXAMPLES OFF CACHE BOOL "Build example apps")
-    add_subdirectory("${ROOT_DIR}/discord-rpc")
-    add_definitions(-D__ENABLE_DISCORD__)
-    include_directories("${ROOT_DIR}/discord-rpc/include")
-    set(HAVE_DISCORD_RPC TRUE)
-    message("Building with discord-rpc support")
-else()
-	message("No discord-rpc detected, to enable clone discord-rpc to root directory: ${ROOT_DIR}")
+if (NOT DISABLE_DISCORD_RPC)
+    if(EXISTS "${ROOT_DIR}/discord-rpc")
+        # Don't build discord's examples, some of which are in C and do not honour
+        # the flags we set for C++. Also we don't use the provided examples.
+        set(BUILD_EXAMPLES OFF CACHE BOOL "Build example apps")
+        add_subdirectory("${ROOT_DIR}/discord-rpc")
+        add_definitions(-D__ENABLE_DISCORD__)
+        include_directories("${ROOT_DIR}/discord-rpc/include")
+        set(HAVE_DISCORD_RPC TRUE)
+        message("Building with discord-rpc support")
+    else()
+        message("No discord-rpc detected, to enable clone discord-rpc to root directory: ${ROOT_DIR}")
+    endif()
 endif()
 
 # Copied from https://github.com/opencv/opencv/blob/dcdd6af5a856826fe62c95322145731e702e54c5/cmake/OpenCVDetectCXXCompiler.cmake#L63-L70
diff --git a/src/openrct2/CMakeLists.txt b/src/openrct2/CMakeLists.txt
index 61be3d13c2a..97674911c0c 100644
--- a/src/openrct2/CMakeLists.txt
+++ b/src/openrct2/CMakeLists.txt
@@ -73,14 +73,16 @@ if (NOT DISABLE_TTF)
     endif ()
 endif ()
 
-find_package(benchmark 1.4 QUIET)
-if (benchmark_FOUND)
-    message("Found Google benchmark, enabling support")
-    set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_DEFINITIONS USE_BENCHMARK)
-    target_link_libraries(${PROJECT_NAME} benchmark::benchmark)
-    target_include_directories(${PROJECT_NAME} PRIVATE ${benchmark_INCLUDE_DIRS})
-else ()
-    message("Google benchmark not found, disabling support")
+if (NOT DISABLE_GOOGLE_BENCHMARK)
+    find_package(benchmark 1.4 QUIET)
+    if (benchmark_FOUND)
+        message("Found Google benchmark, enabling support")
+        set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_DEFINITIONS USE_BENCHMARK)
+        target_link_libraries(${PROJECT_NAME} benchmark::benchmark)
+        target_include_directories(${PROJECT_NAME} PRIVATE ${benchmark_INCLUDE_DIRS})
+    else ()
+        message("Google benchmark not found, disabling support")
+    endif ()
 endif ()
 
 # Third party libraries
