From b4052f81efc1204355fb38849fdde5859d21e2fb Mon Sep 17 00:00:00 2001
From: jp9000 <obs.jim@gmail.com>
Date: Mon, 15 Sep 2014 14:20:43 -0700
Subject: [PATCH] Add cmake option to disable user interface

Adds:
ENABLE_UI (on by default) which makes it so that the UI is required, and
will fail if a dependency is not found.  This is on by default because
most people are building it with the user interface, and we'll probably
get a lot of issue reports stating "why is there no executable?" if we
don't have this on by default.

DISABLE_UI which forces the UI off.

If neither are set, then the UI will only be built if the dependencies
for it are found, otherwise the UI will be be ignored.
---
 obs/CMakeLists.txt | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/obs/CMakeLists.txt b/obs/CMakeLists.txt
index a8668418f..84a14a844 100644
--- a/obs/CMakeLists.txt
+++ b/obs/CMakeLists.txt
@@ -1,11 +1,13 @@
 project(obs)
 
-include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/libobs")
-
-if(CMAKE_SIZEOF_VOID_P EQUAL 8)
-	set(_lib_suffix 64)
+option(ENABLE_UI "Enables the OBS user interfaces" ON)
+if(DISABLE_UI)
+	message(STATUS "UI disabled")
+	return()
+elseif(ENABLE_UI)
+	set(FIND_MODE REQUIRED)
 else()
-	set(_lib_suffix 32)
+	set(FIND_MODE QUIET)
 endif()
 
 if(DEFINED ENV{QTDIR${_lib_suffix}})
@@ -17,8 +19,25 @@ endif()
 set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
 set(CMAKE_AUTOMOC TRUE)
 
-find_package(Qt5Widgets REQUIRED)
-find_package(Qt5Network REQUIRED)
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+	set(_lib_suffix 64)
+else()
+	set(_lib_suffix 32)
+endif()
+
+find_package(Qt5Widgets ${FIND_MODE})
+find_package(Qt5Network ${FIND_MODE})
+
+if(NOT Qt5Widgets_FOUND OR NOT Qt5Network_FOUND)
+	if (ENABLE_UI)
+		message(FATAL_ERROR "Failed to find Qt5")
+	else()
+		message(STATUS "Qt5 not found - UI disabled")
+		return()
+	endif()
+endif()
+
+include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/libobs")
 
 if(WIN32)
 	set(obs_PLATFORM_SOURCES
-- 
GitLab