From e5b8adbd649f602bda9d568eb80856d809176c71 Mon Sep 17 00:00:00 2001
From: Slávek Banko <slavek.banko@axis.cz>
Date: Mon, 27 Oct 2025 14:41:30 +0100
Subject: Add linking of the clucene-shared library if needed.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This resolve FTBFS when building with the upstream state of the clucene
library, which does not list clucene-shared in the linking libraries.
See Issue #31.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
---
 ConfigureChecks.cmake | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 84147b5..86d98b1 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -63,6 +63,42 @@ if( NOT CLUCENE_FOUND )
 endif()
 if( NOT CLUCENE_VERSION VERSION_LESS "2.0" )
   set( CLUCENE_V2 1 )
+  tde_save_and_set( CMAKE_REQUIRED_INCLUDES "${CLUCENE_INCLUDE_DIRS}" )
+  tde_save_and_set( CMAKE_REQUIRED_LIBRARIES "${CLUCENE_LIBRARIES}" )
+  check_cxx_source_compiles("
+    #include <CLucene.h>
+
+    extern size_t lucene_wcstoutf8 (char *,  const wchar_t *, size_t maxslen);
+
+    int main()
+    {
+      lucene_wcstoutf8(NULL, NULL, 0);
+    }
+    "
+    BUILD_WITH_CLUCENE_CORE
+  )
+  if( NOT BUILD_WITH_CLUCENE_CORE )
+    set( CMAKE_REQUIRED_LIBRARIES "${CLUCENE_LIBRARIES};clucene-shared" )
+    check_cxx_source_compiles("
+      #include <CLucene.h>
+
+      extern size_t lucene_wcstoutf8 (char *,  const wchar_t *, size_t maxslen);
+
+      int main()
+      {
+        lucene_wcstoutf8(NULL, NULL, 0);
+      }
+      "
+      BUILD_WITH_CLUCENE_SHARED
+    )
+    if( NOT BUILD_WITH_CLUCENE_SHARED )
+      tde_message_fatal( "clucene library was found, but building with clucene is not successful" )
+    else()
+      set( CLUCENE_LIBRARIES "${CLUCENE_LIBRARIES};clucene-shared" CACHE INTERNAL "clucene libraries" FORCE )
+    endif()
+  endif()
+  tde_restore( CMAKE_REQUIRED_INCLUDES )
+  tde_restore( CMAKE_REQUIRED_LIBRARIES )
 endif()
 
 
-- 
cgit v1.2.3

