From 1aedbe7dd80be920745f05fc90beb89e53742ce0 Mon Sep 17 00:00:00 2001
From: Daniel Gibson <metalcaedes@gmail.com>
Date: Thu, 3 Jun 2021 01:38:17 +0200
Subject: [PATCH] Fix build if libbacktrace is not installed, update README

set(CMAKE_REQUIRED_LIBRARIES backtrace) tells our custom libbacktrace
availability check that it needs to link against libbacktrace.
Seems like it also tells other unrelated compiler-checks like for
-fvisibility=hidden to link against libbacktrace, so if it's not
available they fail as well.
Fixed by unsetting CMAKE_REQUIRED_LIBRARIES after the backtrace check.

While debian-based distros ship libbacktrace as part of libgcc,
apparently in Arch Linux and openSUSE (and possibly others) it's a
separate package, so I mantion it in the README as an (optional)
dependency now and made CMake print a warning if it's not found.
---
 README.md          | 4 ++++
 neo/CMakeLists.txt | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 93877df5..69009c87 100644
--- a/README.md
+++ b/README.md
@@ -71,6 +71,10 @@ Required libraries are not part of the tree. These are:
 - OpenAL (OpenAL Soft required, Creative's and Apple's versions are made of fail)
 - SDL v1.2 or 2.0 (2.0 recommended)
 - libcurl (optional, required for server downloads)
+- Optionally, on non-Windows: libbacktrace
+  - sometimes (e.g. on debian-based distros like Ubuntu) it's part of libgcc (=> always available),
+    sometimes (e.g. Arch Linux, openSUSE) it's in a separate package
+  - If this is available, dhewm3 prints more useful backtraces if it crashes
 - Also, if you're not building recent dhewm3 code from git (but 1.5.1 or older):
   - libjpeg (v8)
   - libogg, libvorbis, libvorbisfile (may be part of libvorbis)
diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt
index b928e02d..a57d47be 100644
--- a/neo/CMakeLists.txt
+++ b/neo/CMakeLists.txt
@@ -185,7 +185,7 @@ if(CURL_FOUND)
 	set(ID_ENABLE_CURL ON)
 	include_directories(${CURL_INCLUDE_DIR})
 else()
-	message(STATUS "libcurl not found, server downloads won't be available")
+	message(WARNING "libcurl not found, server downloads won't be available (apart from that dhewm3 will work)")
 	set(ID_ENABLE_CURL OFF)
 	set(CURL_LIBRARY "")
 endif()
@@ -207,11 +207,14 @@ if(NOT WIN32)
 	set(CMAKE_REQUIRED_LIBRARIES backtrace)
 	check_c_source_compiles( "#include <backtrace.h>
 	int main() { backtrace_create_state(NULL, 0, NULL, NULL); return 0; }" HAVE_LIBBACKTRACE )
+	unset(CMAKE_REQUIRED_LIBRARIES)
 
 	if(HAVE_LIBBACKTRACE)
 		set(sys_libs ${sys_libs} backtrace)
 		add_definitions(-DD3_HAVE_LIBBACKTRACE)
 		message(STATUS "Using libbacktrace")
+	else()
+		message(WARNING "libbacktrace wasn't found. It's not required but recommended, because it provides useful backtraces if dhewm3 crashes")
 	endif()
 endif() # NOT WIN32