FindNETSNMP.cmake 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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(COMMAND ${NETSNMP_CONFIG_BIN} --cflags OUTPUT_VARIABLE _NETSNMP_CFLAGS)
  38. execute_process(COMMAND ${NETSNMP_CONFIG_BIN} --libs OUTPUT_VARIABLE _NETSNMP_LIBS)
  39. # Strip trailing and leading whitespaces
  40. string(STRIP "${_NETSNMP_CFLAGS}" _NETSNMP_CFLAGS)
  41. string(STRIP "${_NETSNMP_LIBS}" _NETSNMP_LIBS)
  42. set(NETSNMP_CFLAGS
  43. ${_NETSNMP_CFLAGS}
  44. CACHE STRING "CFLAGS for net-snmp lib"
  45. )
  46. set(NETSNMP_LIBS
  47. ${_NETSNMP_LIBS}
  48. CACHE STRING "linker options for net-snmp lib"
  49. )
  50. set(NETSNMP_FOUND TRUE BOOL "net-snmp is found")
  51. add_library(NETSNMP::NETSNMP INTERFACE IMPORTED)
  52. set_target_properties(
  53. NETSNMP::NETSNMP PROPERTIES COMPILE_FLAGS "${NETSNMP_CFLAGS}" INTERFACE_LINK_LIBRARIES
  54. "${NETSNMP_LIBS}"
  55. )
  56. if(NOT TARGET NETSNMP::NETSNMP)
  57. message(
  58. FATAL_ERROR "Failed to create NETSNMP::NETSNMP target, check the output of net-snmp-config"
  59. )
  60. endif()
  61. else()
  62. set(NETSNMP_FOUND FALSE /BOOL "net-snmp is not found")
  63. endif()
  64. include(FindPackageHandleStandardArgs)
  65. find_package_handle_standard_args(
  66. NETSNMP DEFAULT_MSG NETSNMP_CONFIG_BIN NETSNMP_LIBS NETSNMP_CFLAGS
  67. )
  68. mark_as_advanced(NETSNMP_LIBS NETSNMP_CFLAGS)