From f7bf3011fb4228f1b2feab26d60cc77dd0105451 Mon Sep 17 00:00:00 2001
From: Nimish Telang <nimish@telang.net>
Date: Sun, 19 Mar 2023 16:03:04 -0400
Subject: [PATCH] Use bundled Find{CURL,ZLIB}.cmake

---
 CMakeLists.txt                 |  5 +----
 cmake/FindZLIB.cmake.unused    | 39 ----------------------------------
 cmake/FindwxWidgets.cmake      |  2 +-
 common/CMakeLists.txt          |  2 +-
 pcbnew/CMakeLists.txt          |  2 +-
 plugins/3d/oce/CMakeLists.txt  |  4 ++--
 plugins/3d/vrml/CMakeLists.txt |  4 ++--
 7 files changed, 8 insertions(+), 50 deletions(-)
 delete mode 100644 cmake/FindZLIB.cmake.unused

diff --git a/CMakeLists.txt b/CMakeLists.txt
index cb1217befa..533268b7d0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -750,14 +750,11 @@ include_directories( SYSTEM ${GLM_INCLUDE_DIR} )
 # Find zlib library, required
 #
 find_package(ZLIB REQUIRED)
-check_find_package_result( ZLIB_FOUND "ZLIB" )
-include_directories( SYSTEM ${ZLIB_INCLUDE_DIRS} )
 
 #
-# Find CURL library, required
+# Find libcurl, required
 #
 find_package( CURL REQUIRED )
-include_directories( SYSTEM ${CURL_INCLUDE_DIRS} )
 
 #
 # Find Cairo library, required
diff --git a/cmake/FindZLIB.cmake.unused b/cmake/FindZLIB.cmake.unused
deleted file mode 100644
index 0fdc315a25..0000000000
--- a/cmake/FindZLIB.cmake.unused
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# From CMake 2.6.1 + some path changes
-#
-
-# - Find zlib
-# Find the native ZLIB includes and library
-#
-#  ZLIB_INCLUDE_DIR - where to find zlib.h, etc.
-#  ZLIB_LIBRARIES   - List of libraries when using zlib.
-#  ZLIB_FOUND       - True if zlib found.
-
-IF(MSYS)
-  SET(ZLIB_DIR_SEARCH
-    c:/msys/1.0
-  )
-ENDIF(MSYS)
-
-IF (ZLIB_INCLUDE_DIR)
-  # Already in cache, be silent
-  SET(ZLIB_FIND_QUIETLY TRUE)
-ENDIF (ZLIB_INCLUDE_DIR)
-
-FIND_PATH(ZLIB_INCLUDE_DIR zlib.h PATHS ${ZLIB_DIR_SEARCH}/local/include)
-
-SET(ZLIB_NAMES z zlib zdll)
-FIND_LIBRARY(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} PATHS ${ZLIB_DIR_SEARCH}/local/lib)
-
-# handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if 
-# all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB DEFAULT_MSG ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-
-IF(ZLIB_FOUND)
-  SET( ZLIB_LIBRARIES ${ZLIB_LIBRARY} )
-ELSE(ZLIB_FOUND)
-  SET( ZLIB_LIBRARIES )
-ENDIF(ZLIB_FOUND)
-
-MARK_AS_ADVANCED( ZLIB_LIBRARY ZLIB_INCLUDE_DIR )
diff --git a/cmake/FindwxWidgets.cmake b/cmake/FindwxWidgets.cmake
index f22ba48812..02d6238163 100644
--- a/cmake/FindwxWidgets.cmake
+++ b/cmake/FindwxWidgets.cmake
@@ -231,7 +231,7 @@ endif()
 #=====================================================================
 if(wxWidgets_FIND_STYLE STREQUAL "win32")
   # Useful common wx libs needed by almost all components.
-  set(wxWidgets_COMMON_LIBRARIES png tiff jpeg zlib regex expat)
+  set(wxWidgets_COMMON_LIBRARIES png tiff jpeg ZLIB::ZLIB regex expat)
 
   # DEPRECATED: Use find_package(wxWidgets COMPONENTS mono) instead.
   if(NOT wxWidgets_FIND_COMPONENTS)
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index 2104fee339..703b39eb70 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -492,7 +492,7 @@ target_link_libraries( common
     # Database support needs these two
     nanodbc # for now; maybe hoist out of common
     Boost::locale
-    ${CURL_LIBRARIES}
+    CURL::libcurl
     ${wxWidgets_LIBRARIES}
     ${EXTRA_LIBS}
     # outline font support
diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt
index ed67d79abe..5ed604be73 100644
--- a/pcbnew/CMakeLists.txt
+++ b/pcbnew/CMakeLists.txt
@@ -632,7 +632,7 @@ target_link_libraries( pcbnew_kiface_objects
         rectpack2d
         gzip-hpp
         Boost::boost
-        ${ZLIB_LIBRARIES}
+        ZLIB::ZLIB
         ${OCC_LIBRARIES}
     )
 
diff --git a/plugins/3d/oce/CMakeLists.txt b/plugins/3d/oce/CMakeLists.txt
index 074df30a67..a6f198c4ea 100644
--- a/plugins/3d/oce/CMakeLists.txt
+++ b/plugins/3d/oce/CMakeLists.txt
@@ -17,7 +17,7 @@ add_library( s3d_plugin_oce MODULE
         loadmodel.cpp
         )
 
-target_link_libraries( s3d_plugin_oce kicad_3dsg ${OCC_LIBRARIES} ${wxWidgets_LIBRARIES} ${ZLIB_LIBRARIES} )
+target_link_libraries( s3d_plugin_oce kicad_3dsg ${OCC_LIBRARIES} ${wxWidgets_LIBRARIES} ZLIB::ZLIB )
 
 target_include_directories( s3d_plugin_oce PRIVATE
     $<TARGET_PROPERTY:gzip-hpp,INTERFACE_INCLUDE_DIRECTORIES>
@@ -39,4 +39,4 @@ install( TARGETS
 if( KICAD_WIN32_INSTALL_PDBS )
     # Get the PDBs to copy over for MSVC
     install(FILES $<TARGET_PDB_FILE:s3d_plugin_oce> DESTINATION ${KICAD_USER_PLUGIN}/3d)
-endif()
\ No newline at end of file
+endif()
diff --git a/plugins/3d/vrml/CMakeLists.txt b/plugins/3d/vrml/CMakeLists.txt
index b651598842..ecf01ed31c 100644
--- a/plugins/3d/vrml/CMakeLists.txt
+++ b/plugins/3d/vrml/CMakeLists.txt
@@ -65,7 +65,7 @@ add_library( s3d_plugin_vrml MODULE
         x3d/x3d_transform.cpp
         )
 
-target_link_libraries( s3d_plugin_vrml kicad_3dsg ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} ${ZLIB_LIBRARIES} )
+target_link_libraries( s3d_plugin_vrml kicad_3dsg ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} ZLIB::ZLIB )
 
 target_include_directories( s3d_plugin_vrml PRIVATE
     $<TARGET_PROPERTY:gzip-hpp,INTERFACE_INCLUDE_DIRECTORIES>
@@ -87,4 +87,4 @@ install( TARGETS
 if( KICAD_WIN32_INSTALL_PDBS )
     # Get the PDBs to copy over for MSVC
     install(FILES $<TARGET_PDB_FILE:s3d_plugin_vrml> DESTINATION ${KICAD_USER_PLUGIN}/3d)
-endif()
\ No newline at end of file
+endif()