Selaa lähdekoodia

CMake: Auto find ZLIB from package config if nedded

Konstantin Podsvirov 9 vuotta sitten
vanhempi
commit
eefd1fdd48
2 muutettua tiedostoa jossa 5 lisäystä ja 0 poistoa
  1. 2 0
      cmake/CMakeLists.txt
  2. 3 0
      cmake/protobuf-config.cmake.in

+ 2 - 0
cmake/CMakeLists.txt

@@ -86,6 +86,7 @@ if (CMAKE_USE_PTHREADS_INIT)
   add_definitions(-DHAVE_PTHREAD)
   add_definitions(-DHAVE_PTHREAD)
 endif (CMAKE_USE_PTHREADS_INIT)
 endif (CMAKE_USE_PTHREADS_INIT)
 
 
+set(_protobuf_FIND_ZLIB)
 if (protobuf_WITH_ZLIB)
 if (protobuf_WITH_ZLIB)
   find_package(ZLIB)
   find_package(ZLIB)
   if (ZLIB_FOUND)
   if (ZLIB_FOUND)
@@ -96,6 +97,7 @@ if (protobuf_WITH_ZLIB)
     # Using imported target if exists
     # Using imported target if exists
     if (TARGET ZLIB::ZLIB)
     if (TARGET ZLIB::ZLIB)
       set(ZLIB_LIBRARIES ZLIB::ZLIB)
       set(ZLIB_LIBRARIES ZLIB::ZLIB)
+      set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND)\n  find_package(ZLIB)\nendif()")
     endif (TARGET ZLIB::ZLIB)
     endif (TARGET ZLIB::ZLIB)
   else (ZLIB_FOUND)
   else (ZLIB_FOUND)
     set(HAVE_ZLIB 0)
     set(HAVE_ZLIB 0)

+ 3 - 0
cmake/protobuf-config.cmake.in

@@ -1,6 +1,9 @@
 # User options
 # User options
 include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake")
 include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake")
 
 
+# Depend packages
+@_protobuf_FIND_ZLIB@
+
 # Imported targets
 # Imported targets
 include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake")
 include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake")