From fff5644858658ed3e93a0366e6c92cfe20a848f3 Mon Sep 17 00:00:00 2001
From: Bill Somerville <bill@classdesign.com>
Date: Mon, 28 Sep 2020 13:51:14 +0100
Subject: [PATCH] Configure option for older version of Hamlib caching

---
 CMakeLists.txt                    | 1 +
 Transceiver/HamlibTransceiver.cpp | 8 ++++++--
 wsjtx_config.h.in                 | 1 +
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f24abbbeb..e7d65cf5b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -907,6 +907,7 @@ message (STATUS "hamlib_LIBRARY_DIRS: ${hamlib_LIBRARY_DIRS}")
 
 set (CMAKE_REQUIRED_INCLUDES "${hamlib_INCLUDE_DIRS}")
 set (CMAKE_REQUIRED_LIBRARIES "${hamlib_LIBRARIES}")
+check_symbol_exists (CACHE_ALL "hamlib/rig.h" HAVE_HAMLIB_OLD_CACHING)
 check_symbol_exists (rig_set_cache_timeout_ms "hamlib/rig.h" HAVE_HAMLIB_CACHING)
 
 
diff --git a/Transceiver/HamlibTransceiver.cpp b/Transceiver/HamlibTransceiver.cpp
index 3923f4c5d..ce7408a04 100644
--- a/Transceiver/HamlibTransceiver.cpp
+++ b/Transceiver/HamlibTransceiver.cpp
@@ -14,6 +14,10 @@
 
 #include "moc_HamlibTransceiver.cpp"
 
+#if HAVE_HAMLIB_OLD_CACHING
+#define HAMLIB_CACHE_ALL CACHE_ALL
+#endif
+
 namespace
 {
   // Unfortunately bandwidth is conflated  with mode, this is probably
@@ -606,7 +610,7 @@ int HamlibTransceiver::do_start ()
         }
     }
 
-#if HAVE_HAMLIB_CACHING
+#if HAVE_HAMLIB_CACHING || HAVE_HAMLIB_OLD_CACHING
   // we must disable Hamlib caching because it lies about frequency
   // for less than 1 Hz resolution rigs
   auto orig_cache_timeout = rig_get_cache_timeout_ms (rig_.data (), HAMLIB_CACHE_ALL);
@@ -653,7 +657,7 @@ int HamlibTransceiver::do_start ()
       resolution = -1;          // best guess
     }
 
-#if HAVE_HAMLIB_CACHING
+#if HAVE_HAMLIB_CACHING || HAVE_HAMLIB_OLD_CACHING
   // revert Hamlib cache timeout
   rig_set_cache_timeout_ms (rig_.data (), HAMLIB_CACHE_ALL, orig_cache_timeout);
 #endif
diff --git a/wsjtx_config.h.in b/wsjtx_config.h.in
index 0866cf061..7da6a4cdd 100644
--- a/wsjtx_config.h.in
+++ b/wsjtx_config.h.in
@@ -19,6 +19,7 @@ extern "C"  {
 #cmakedefine PROJECT_SAMPLES_URL "@PROJECT_SAMPLES_URL@"
 #cmakedefine PROJECT_SUMMARY_DESCRIPTION "@PROJECT_SUMMARY_DESCRIPTION@"
 
+#cmakedefine01 HAVE_HAMLIB_OLD_CACHING
 #cmakedefine01 HAVE_HAMLIB_CACHING
 
 #cmakedefine01 WSJT_SHARED_RUNTIME