FindNETSNMP.cmake 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # https://fossies.org/linux/syslog-ng/cmake/Modules/FindNETSNMP.cmake
  2. #############################################################################
  3. # Copyright (c) 2019 Balabit
  4. #
  5. # This library is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 2.1 of the License, or (at your option) any later version.
  9. #
  10. # This library is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public
  16. # License along with this library; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. #
  19. # As an additional exemption you are allowed to compile & link against the
  20. # OpenSSL libraries as published by the OpenSSL project. See the file
  21. # COPYING for details.
  22. #
  23. #############################################################################
  24. # - Try to find the net-snmp library
  25. # Once done this will define
  26. #
  27. # NETSNMP_FOUND - system has the net-snmp library
  28. # NETSNMP_CFLAGS -
  29. # NETSNMP_LIBS - the libraries needed to use net-snmp
  30. #
  31. if(NETSNMP_LIBS)
  32. # Already in cache, be silent
  33. set(NETSNMP_FIND_QUIETLY TRUE)
  34. endif(NETSNMP_LIBS)
  35. find_program(NETSNMP_CONFIG_BIN net-snmp-config)
  36. if(NETSNMP_CONFIG_BIN)
  37. execute_process(
  38. COMMAND ${NETSNMP_CONFIG_BIN} --cflags OUTPUT_VARIABLE _NETSNMP_CFLAGS
  39. )
  40. execute_process(
  41. COMMAND ${NETSNMP_CONFIG_BIN} --libs OUTPUT_VARIABLE _NETSNMP_LIBS
  42. )
  43. # Strip trailing and leading whitespaces
  44. string(STRIP "${_NETSNMP_CFLAGS}" _NETSNMP_CFLAGS)
  45. string(STRIP "${_NETSNMP_LIBS}" _NETSNMP_LIBS)
  46. set(NETSNMP_CFLAGS
  47. ${_NETSNMP_CFLAGS}
  48. CACHE STRING "CFLAGS for net-snmp lib"
  49. )
  50. set(NETSNMP_LIBS
  51. ${_NETSNMP_LIBS}
  52. CACHE STRING "linker options for net-snmp lib"
  53. )
  54. set(NETSNMP_FOUND TRUE BOOL "net-snmp is found")
  55. add_library(NETSNMP::NETSNMP INTERFACE IMPORTED)
  56. set_target_properties(
  57. NETSNMP::NETSNMP PROPERTIES COMPILE_FLAGS "${NETSNMP_CFLAGS}"
  58. INTERFACE_LINK_LIBRARIES "${NETSNMP_LIBS}"
  59. )
  60. if(NOT TARGET NETSNMP::NETSNMP)
  61. message(
  62. FATAL_ERROR
  63. "Failed to create NETSNMP::NETSNMP target, check the output of net-snmp-config"
  64. )
  65. endif()
  66. else()
  67. set(NETSNMP_FOUND FALSE /BOOL "net-snmp is not found")
  68. endif()
  69. include(FindPackageHandleStandardArgs)
  70. find_package_handle_standard_args(
  71. NETSNMP DEFAULT_MSG NETSNMP_CONFIG_BIN NETSNMP_LIBS NETSNMP_CFLAGS
  72. )
  73. mark_as_advanced(NETSNMP_LIBS NETSNMP_CFLAGS)