FindXMLRPC.cmake 3.9 KB

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