From 6d3c48d1b01943a467928235c3affbab463c25ab Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Thu, 7 Jul 2022 12:32:47 -0700
Subject: [PATCH] cmake: Use alternate way to detect libm

The standard package provided with MathLib cmake module does not work
when libm is folded into libc starting glibc 2.35+

Upstream-Status: Pending
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 CMakeLists.txt                   | 7 ++++++-
 contrib/fonttools/CMakeLists.txt | 2 +-
 fontforge/CMakeLists.txt         | 2 +-
 fontforgeexe/CMakeLists.txt      | 4 ++--
 4 files changed, 10 insertions(+), 5 deletions(-)

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -111,9 +111,14 @@ find_package_with_target(Intl REQUIRED)
 find_package(GLIB 2.6 REQUIRED COMPONENTS gio gobject)
 find_package(Iconv REQUIRED)
 find_package(LibXml2 REQUIRED)
-find_package(MathLib REQUIRED)
 find_package(ZLIB REQUIRED)
 
+include(CheckLibraryExists)
+CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIB_M)
+if (HAVE_LIB_M)
+    set(EXTRA_LIBS ${EXTRA_LIBS} m)
+endif (HAVE_LIB_M)
+
 check_include_file(pthread.h HAVE_PTHREAD_H)
 if(HAVE_PTHREAD_H)
   find_package(Threads)
--- a/contrib/fonttools/CMakeLists.txt
+++ b/contrib/fonttools/CMakeLists.txt
@@ -15,6 +15,6 @@ add_executable(woff woff.c)
 
 target_link_libraries(acorn2sfd PRIVATE fontforge)
 target_link_libraries(dewoff PRIVATE ZLIB::ZLIB)
-target_link_libraries(pcl2ttf PRIVATE MathLib::MathLib)
+target_link_libraries(pcl2ttf PRIVATE ${EXTRA_LIBS})
 target_link_libraries(ttf2eps PRIVATE fontforge)
 target_link_libraries(woff PRIVATE ZLIB::ZLIB)
--- a/fontforge/CMakeLists.txt
+++ b/fontforge/CMakeLists.txt
@@ -237,7 +237,7 @@ target_link_libraries(fontforge
     GLIB::GLIB
     Intl::Intl
   PRIVATE
-    MathLib::MathLib
+    ${EXTRA_LIBS}
     Iconv::Iconv
     ZLIB::ZLIB
 )
--- a/fontforgeexe/CMakeLists.txt
+++ b/fontforgeexe/CMakeLists.txt
@@ -110,7 +110,7 @@ if(ENABLE_PYTHON_SCRIPTING_RESULT)
   target_link_libraries(fontforgeexe PRIVATE Python3::Python)
 endif()
 
-target_link_libraries(fontforgeexe PRIVATE fontforge Iconv::Iconv MathLib::MathLib)
+target_link_libraries(fontforgeexe PRIVATE fontforge Iconv::Iconv ${EXTRA_LIBS})
 install(TARGETS fontforgeexe RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 
 if(UNIX)
