FindXMLRPC.cmake 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindXMLRPC
  5. ----------
  6. Find xmlrpc
  7. Find the native XMLRPC headers and libraries.
  8. ::
  9. XMLRPC_INCLUDE_DIRS - where to find xmlrpc.h, etc.
  10. XMLRPC_LIBRARIES - List of libraries when using xmlrpc.
  11. XMLRPC_FOUND - True if xmlrpc found.
  12. XMLRPC modules may be specified as components for this find module.
  13. Modules may be listed by running "xmlrpc-c-config". Modules include:
  14. ::
  15. c++ C++ wrapper code
  16. libwww-client libwww-based client
  17. cgi-server CGI-based server
  18. abyss-server ABYSS-based server
  19. Typical usage:
  20. ::
  21. find_package(XMLRPC REQUIRED libwww-client)
  22. #]=======================================================================]
  23. # First find the config script from which to obtain other values.
  24. find_program(XMLRPC_C_CONFIG NAMES xmlrpc-c-config)
  25. # Check whether we found anything.
  26. if(XMLRPC_C_CONFIG)
  27. set(XMLRPC_C_FOUND 1)
  28. else()
  29. set(XMLRPC_C_FOUND 0)
  30. endif()
  31. # Lookup the include directories needed for the components requested.
  32. if(XMLRPC_C_FOUND)
  33. execute_process(
  34. COMMAND ${XMLRPC_C_CONFIG} ${XMLRPC_FIND_COMPONENTS} --cflags
  35. OUTPUT_VARIABLE XMLRPC_C_CONFIG_CFLAGS
  36. OUTPUT_STRIP_TRAILING_WHITESPACE
  37. RESULT_VARIABLE XMLRPC_C_CONFIG_RESULT
  38. )
  39. # Parse the include flags.
  40. if("${XMLRPC_C_CONFIG_RESULT}" STREQUAL "0")
  41. # Convert the compile flags to a CMake list.
  42. string(REGEX REPLACE " +" ";"
  43. XMLRPC_C_CONFIG_CFLAGS "${XMLRPC_C_CONFIG_CFLAGS}")
  44. # Look for -I options.
  45. # FIXME: Use these as hints to a find_path call to find the headers.
  46. set(XMLRPC_INCLUDE_DIRS)
  47. foreach(flag ${XMLRPC_C_CONFIG_CFLAGS})
  48. if("${flag}" MATCHES "^-I(.+)")
  49. file(TO_CMAKE_PATH "${CMAKE_MATCH_1}" DIR)
  50. list(APPEND XMLRPC_INCLUDE_DIRS "${DIR}")
  51. endif()
  52. endforeach()
  53. else()
  54. message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
  55. set(XMLRPC_C_FOUND 0)
  56. endif()
  57. endif()
  58. # Lookup the libraries needed for the components requested.
  59. if(XMLRPC_C_FOUND)
  60. execute_process(
  61. COMMAND ${XMLRPC_C_CONFIG} ${XMLRPC_FIND_COMPONENTS} --libs
  62. OUTPUT_VARIABLE XMLRPC_C_CONFIG_LIBS
  63. OUTPUT_STRIP_TRAILING_WHITESPACE
  64. RESULT_VARIABLE XMLRPC_C_CONFIG_RESULT
  65. )
  66. # Parse the library names and directories.
  67. if("${XMLRPC_C_CONFIG_RESULT}" STREQUAL "0")
  68. string(REGEX REPLACE " +" ";"
  69. XMLRPC_C_CONFIG_LIBS "${XMLRPC_C_CONFIG_LIBS}")
  70. # Look for -L flags for directories and -l flags for library names.
  71. set(XMLRPC_LIBRARY_DIRS)
  72. set(XMLRPC_LIBRARY_NAMES)
  73. foreach(flag ${XMLRPC_C_CONFIG_LIBS})
  74. if("${flag}" MATCHES "^-L(.+)")
  75. file(TO_CMAKE_PATH "${CMAKE_MATCH_1}" DIR)
  76. list(APPEND XMLRPC_LIBRARY_DIRS "${DIR}")
  77. elseif("${flag}" MATCHES "^-l(.+)")
  78. list(APPEND XMLRPC_LIBRARY_NAMES "${CMAKE_MATCH_1}")
  79. endif()
  80. endforeach()
  81. # Search for each library needed using the directories given.
  82. foreach(name ${XMLRPC_LIBRARY_NAMES})
  83. # Look for this library.
  84. find_library(XMLRPC_${name}_LIBRARY
  85. NAMES ${name}
  86. HINTS ${XMLRPC_LIBRARY_DIRS}
  87. )
  88. mark_as_advanced(XMLRPC_${name}_LIBRARY)
  89. # If any library is not found then the whole package is not found.
  90. if(NOT XMLRPC_${name}_LIBRARY)
  91. set(XMLRPC_C_FOUND 0)
  92. endif()
  93. # Build an ordered list of all the libraries needed.
  94. set(XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES} "${XMLRPC_${name}_LIBRARY}")
  95. endforeach()
  96. else()
  97. message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
  98. set(XMLRPC_C_FOUND 0)
  99. endif()
  100. endif()
  101. # Report the results.
  102. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  103. FIND_PACKAGE_HANDLE_STANDARD_ARGS(
  104. XMLRPC
  105. REQUIRED_VARS XMLRPC_C_FOUND XMLRPC_LIBRARIES
  106. FAIL_MESSAGE "XMLRPC was not found. Make sure the entries XMLRPC_* are set.")