From 387f2649744e3846b37bfef21ad24165adefe81e Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <vital.had@gmail.com>
Date: Sat, 13 Jun 2026 07:07:25 +0800
Subject: [PATCH] Adjust CMakeLists

---
 CMakeLists.txt            | 66 +++++----------------------------------
 lib/tgchat/CMakeLists.txt |  9 ++----
 2 files changed, 9 insertions(+), 66 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 69835763..a0ed7d8b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,25 +35,8 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
   if (DEFINED NCURSES_ROOT_DIR AND EXISTS "${NCURSES_ROOT_DIR}")
     message(STATUS "Ncurses cmake prefix '${NCURSES_ROOT_DIR}' (user-specified)")
   else()
-    execute_process(COMMAND sh "-c"
-                    "command -v brew &> /dev/null && brew --prefix ncurses 2> /dev/null | tr -d '\n'"
-                    OUTPUT_VARIABLE NCURSES_ROOT_DIR)
-    if (EXISTS "${NCURSES_ROOT_DIR}")
-      message(STATUS "Ncurses cmake prefix '${NCURSES_ROOT_DIR}' (homebrew)")
-    else()
-      foreach(FALLBACK_DIR /opt/homebrew/opt/ncurses /usr/local/opt/ncurses)
-        if (EXISTS "${FALLBACK_DIR}")
-          set(NCURSES_ROOT_DIR "${FALLBACK_DIR}")
-          break()
-        endif()
-      endforeach()
-      if (EXISTS "${NCURSES_ROOT_DIR}")
-        message(STATUS "Ncurses cmake prefix '${NCURSES_ROOT_DIR}' (fallback)")
-      elseif (EXISTS "/opt/local")
-        set(NCURSES_ROOT_DIR "/opt/local")
-        message(STATUS "Ncurses cmake prefix '${NCURSES_ROOT_DIR}' (macports)")
-      endif()
-    endif()
+    set(NCURSES_ROOT_DIR "/opt/local")
+    message(STATUS "Ncurses cmake prefix '${NCURSES_ROOT_DIR}' (macports)")
   endif()
   if (EXISTS "${NCURSES_ROOT_DIR}")
     list(APPEND CMAKE_PREFIX_PATH ${NCURSES_ROOT_DIR})
@@ -63,25 +46,8 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
   if (DEFINED OPENSSL_ROOT_DIR AND EXISTS "${OPENSSL_ROOT_DIR}")
     message(STATUS "OpenSSL cmake prefix '${OPENSSL_ROOT_DIR}' (user-specified)")
   else()
-    execute_process(COMMAND sh "-c"
-                    "command -v brew &> /dev/null && brew --prefix openssl 2> /dev/null | tr -d '\n'"
-                    OUTPUT_VARIABLE OPENSSL_ROOT_DIR)
-    if (EXISTS "${OPENSSL_ROOT_DIR}")
-      message(STATUS "OpenSSL cmake prefix '${OPENSSL_ROOT_DIR}' (homebrew)")
-    else()
-      foreach(FALLBACK_DIR /opt/homebrew/opt/openssl /usr/local/opt/openssl)
-        if (EXISTS "${FALLBACK_DIR}")
-          set(OPENSSL_ROOT_DIR "${FALLBACK_DIR}")
-          break()
-        endif()
-      endforeach()
-      if (EXISTS "${OPENSSL_ROOT_DIR}")
-        message(STATUS "OpenSSL cmake prefix '${OPENSSL_ROOT_DIR}' (fallback)")
-      elseif (EXISTS "/opt/local")
-        set(OPENSSL_ROOT_DIR "/opt/local")
-        message(STATUS "OpenSSL cmake prefix '${OPENSSL_ROOT_DIR}' (macports)")
-      endif()
-    endif()
+    set(OPENSSL_ROOT_DIR "/opt/local")
+    message(STATUS "OpenSSL cmake prefix '${OPENSSL_ROOT_DIR}' (macports)")
   endif()
   if (EXISTS "${OPENSSL_ROOT_DIR}")
     list(APPEND CMAKE_PREFIX_PATH ${OPENSSL_ROOT_DIR})
@@ -91,25 +57,8 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
   if (DEFINED SQLITE_ROOT_DIR AND EXISTS "${SQLITE_ROOT_DIR}")
     message(STATUS "SQLite cmake prefix '${SQLITE_ROOT_DIR}' (user-specified)")
   else()
-    execute_process(COMMAND sh "-c"
-                    "command -v brew &> /dev/null && brew --prefix sqlite 2> /dev/null | tr -d '\n'"
-                    OUTPUT_VARIABLE SQLITE_ROOT_DIR)
-    if (EXISTS "${SQLITE_ROOT_DIR}")
-      message(STATUS "SQLite cmake prefix '${SQLITE_ROOT_DIR}' (homebrew)")
-    else()
-      foreach(FALLBACK_DIR /opt/homebrew/opt/sqlite /usr/local/opt/sqlite)
-        if (EXISTS "${FALLBACK_DIR}")
-          set(SQLITE_ROOT_DIR "${FALLBACK_DIR}")
-          break()
-        endif()
-      endforeach()
-      if (EXISTS "${SQLITE_ROOT_DIR}")
-        message(STATUS "SQLite cmake prefix '${SQLITE_ROOT_DIR}' (fallback)")
-      elseif (EXISTS "/opt/local")
-        set(SQLITE_ROOT_DIR "/opt/local")
-        message(STATUS "SQLite cmake prefix '${SQLITE_ROOT_DIR}' (macports)")
-      endif()
-    endif()
+    set(SQLITE_ROOT_DIR "/opt/local")
+    message(STATUS "SQLite cmake prefix '${SQLITE_ROOT_DIR}' (macports)")
   endif()
   if (EXISTS "${SQLITE_ROOT_DIR}")
     list(APPEND CMAKE_PREFIX_PATH ${SQLITE_ROOT_DIR})
@@ -192,8 +141,7 @@ test_big_endian(IS_BIG_ENDIAN)
 if(IS_BIG_ENDIAN)
   message(STATUS "Endian: Big")
   if(HAS_TELEGRAM)
-    message(WARNING "Telegram requires little endian, auto-disabling")
-	set(HAS_TELEGRAM OFF)
+    message(WARNING "Big-endian support is experimental")
   endif()
 else()
   message(STATUS "Endian: Little")
diff --git a/lib/tgchat/CMakeLists.txt b/lib/tgchat/CMakeLists.txt
index 07d1b58f..9b4ac488 100644
--- a/lib/tgchat/CMakeLists.txt
+++ b/lib/tgchat/CMakeLists.txt
@@ -9,6 +9,8 @@
   set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
 endif()
 
+find_package(Td REQUIRED)
+
 # Compiler specifics
 set(ATOMIC_TEST_SOURCE
   "
@@ -50,16 +52,9 @@
 # Dependency tdlib
 add_subdirectory(ext/td EXCLUDE_FROM_ALL)
 
-if(LIBRARY_LINKING_TYPE STREQUAL "SHARED")
-  set(TDLIBNAME "tdclientshared")
-  set(TDLIBFILENAME "libtdclientshared${CMAKE_SHARED_LIBRARY_SUFFIX}")
-  install(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TDLIBFILENAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
-else()
-  set(TDLIBNAME "tdclient")
-endif()
-
 # Linking
-target_link_libraries(tgchat PUBLIC ncutil ${TDLIBNAME})
+target_link_libraries(tgchat PUBLIC ncutil)
+target_link_libraries(tgchat PRIVATE Td::TdStatic)
 if (USE_LIBATOMIC)
   set_target_properties(tgchat PROPERTIES LINK_FLAGS "-latomic")
 endif()
--- a/lib/ncutil/CMakeLists.txt
+++ b/lib/ncutil/CMakeLists.txt
@@ -13,8 +13,7 @@
 # Dependencies
 find_library(MAGIC_LIBRARY magic)
 find_path(MAGIC_INCLUDE_DIR magic.h
-  /usr/local/include
-  /usr/include
+  @PREFIX@/include
 )
 if(HAS_STATIC_EXTLIBS)
 

