FindXMLRPC.cmake 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. # - Find xmlrpc
  2. # Find the native XMLRPC headers and libraries.
  3. # XMLRPC_INCLUDE_DIRS - where to find xmlrpc.h, etc.
  4. # XMLRPC_LIBRARIES - List of libraries when using xmlrpc.
  5. # XMLRPC_FOUND - True if xmlrpc found.
  6. # XMLRPC modules may be specified as components for this find module.
  7. # Modules may be listed by running "xmlrpc-c-config". Modules include:
  8. # c++ C++ wrapper code
  9. # libwww-client libwww-based client
  10. # cgi-server CGI-based server
  11. # abyss-server ABYSS-based server
  12. # Typical usage:
  13. # FIND_PACKAGE(XMLRPC REQUIRED libwww-client)
  14. #=============================================================================
  15. # Copyright 2001-2009 Kitware, Inc.
  16. #
  17. # Distributed under the OSI-approved BSD License (the "License");
  18. # see accompanying file Copyright.txt for details.
  19. #
  20. # This software is distributed WITHOUT ANY WARRANTY; without even the
  21. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. # See the License for more information.
  23. #=============================================================================
  24. # (To distribute this file outside of CMake, substitute the full
  25. # License text for the above reference.)
  26. # First find the config script from which to obtain other values.
  27. FIND_PROGRAM(XMLRPC_C_CONFIG NAMES xmlrpc-c-config)
  28. # Check whether we found anything.
  29. IF(XMLRPC_C_CONFIG)
  30. SET(XMLRPC_FOUND 1)
  31. ELSE(XMLRPC_C_CONFIG)
  32. SET(XMLRPC_FOUND 0)
  33. ENDIF(XMLRPC_C_CONFIG)
  34. # Lookup the include directories needed for the components requested.
  35. IF(XMLRPC_FOUND)
  36. # Use the newer EXECUTE_PROCESS command if it is available.
  37. IF(COMMAND EXECUTE_PROCESS)
  38. EXECUTE_PROCESS(
  39. COMMAND ${XMLRPC_C_CONFIG} ${XMLRPC_FIND_COMPONENTS} --cflags
  40. OUTPUT_VARIABLE XMLRPC_C_CONFIG_CFLAGS
  41. OUTPUT_STRIP_TRAILING_WHITESPACE
  42. RESULT_VARIABLE XMLRPC_C_CONFIG_RESULT
  43. )
  44. ELSE(COMMAND EXECUTE_PROCESS)
  45. EXEC_PROGRAM(${XMLRPC_C_CONFIG} ARGS "${XMLRPC_FIND_COMPONENTS} --cflags"
  46. OUTPUT_VARIABLE XMLRPC_C_CONFIG_CFLAGS
  47. RETURN_VALUE XMLRPC_C_CONFIG_RESULT
  48. )
  49. ENDIF(COMMAND EXECUTE_PROCESS)
  50. # Parse the include flags.
  51. IF("${XMLRPC_C_CONFIG_RESULT}" MATCHES "^0$")
  52. # Convert the compile flags to a CMake list.
  53. STRING(REGEX REPLACE " +" ";"
  54. XMLRPC_C_CONFIG_CFLAGS "${XMLRPC_C_CONFIG_CFLAGS}")
  55. # Look for -I options.
  56. SET(XMLRPC_INCLUDE_DIRS)
  57. FOREACH(flag ${XMLRPC_C_CONFIG_CFLAGS})
  58. IF("${flag}" MATCHES "^-I")
  59. STRING(REGEX REPLACE "^-I" "" DIR "${flag}")
  60. FILE(TO_CMAKE_PATH "${DIR}" DIR)
  61. SET(XMLRPC_INCLUDE_DIRS ${XMLRPC_INCLUDE_DIRS} "${DIR}")
  62. ENDIF("${flag}" MATCHES "^-I")
  63. ENDFOREACH(flag)
  64. ELSE("${XMLRPC_C_CONFIG_RESULT}" MATCHES "^0$")
  65. MESSAGE("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
  66. SET(XMLRPC_FOUND 0)
  67. ENDIF("${XMLRPC_C_CONFIG_RESULT}" MATCHES "^0$")
  68. ENDIF(XMLRPC_FOUND)
  69. # Lookup the libraries needed for the components requested.
  70. IF(XMLRPC_FOUND)
  71. # Use the newer EXECUTE_PROCESS command if it is available.
  72. IF(COMMAND EXECUTE_PROCESS)
  73. EXECUTE_PROCESS(
  74. COMMAND ${XMLRPC_C_CONFIG} ${XMLRPC_FIND_COMPONENTS} --libs
  75. OUTPUT_VARIABLE XMLRPC_C_CONFIG_LIBS
  76. OUTPUT_STRIP_TRAILING_WHITESPACE
  77. RESULT_VARIABLE XMLRPC_C_CONFIG_RESULT
  78. )
  79. ELSE(COMMAND EXECUTE_PROCESS)
  80. EXEC_PROGRAM(${XMLRPC_C_CONFIG} ARGS "${XMLRPC_FIND_COMPONENTS} --libs"
  81. OUTPUT_VARIABLE XMLRPC_C_CONFIG_LIBS
  82. RETURN_VALUE XMLRPC_C_CONFIG_RESULT
  83. )
  84. ENDIF(COMMAND EXECUTE_PROCESS)
  85. # Parse the library names and directories.
  86. IF("${XMLRPC_C_CONFIG_RESULT}" MATCHES "^0$")
  87. STRING(REGEX REPLACE " +" ";"
  88. XMLRPC_C_CONFIG_LIBS "${XMLRPC_C_CONFIG_LIBS}")
  89. # Look for -L flags for directories and -l flags for library names.
  90. SET(XMLRPC_LIBRARY_DIRS)
  91. SET(XMLRPC_LIBRARY_NAMES)
  92. FOREACH(flag ${XMLRPC_C_CONFIG_LIBS})
  93. IF("${flag}" MATCHES "^-L")
  94. STRING(REGEX REPLACE "^-L" "" DIR "${flag}")
  95. FILE(TO_CMAKE_PATH "${DIR}" DIR)
  96. SET(XMLRPC_LIBRARY_DIRS ${XMLRPC_LIBRARY_DIRS} "${DIR}")
  97. ELSEIF("${flag}" MATCHES "^-l")
  98. STRING(REGEX REPLACE "^-l" "" NAME "${flag}")
  99. SET(XMLRPC_LIBRARY_NAMES ${XMLRPC_LIBRARY_NAMES} "${NAME}")
  100. ENDIF("${flag}" MATCHES "^-L")
  101. ENDFOREACH(flag)
  102. # Search for each library needed using the directories given.
  103. FOREACH(name ${XMLRPC_LIBRARY_NAMES})
  104. # Look for this library.
  105. FIND_LIBRARY(XMLRPC_${name}_LIBRARY
  106. NAMES ${name}
  107. HINTS ${XMLRPC_LIBRARY_DIRS}
  108. )
  109. MARK_AS_ADVANCED(XMLRPC_${name}_LIBRARY)
  110. # If any library is not found then the whole package is not found.
  111. IF(NOT XMLRPC_${name}_LIBRARY)
  112. SET(XMLRPC_FOUND 0)
  113. ENDIF(NOT XMLRPC_${name}_LIBRARY)
  114. # Build an ordered list of all the libraries needed.
  115. SET(XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES} "${XMLRPC_${name}_LIBRARY}")
  116. ENDFOREACH(name)
  117. ELSE("${XMLRPC_C_CONFIG_RESULT}" MATCHES "^0$")
  118. MESSAGE("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
  119. SET(XMLRPC_FOUND 0)
  120. ENDIF("${XMLRPC_C_CONFIG_RESULT}" MATCHES "^0$")
  121. ENDIF(XMLRPC_FOUND)
  122. # Report the results.
  123. IF(NOT XMLRPC_FOUND)
  124. SET(XMLRPC_DIR_MESSAGE
  125. "XMLRPC was not found. Make sure the entries XMLRPC_* are set.")
  126. IF(NOT XMLRPC_FIND_QUIETLY)
  127. MESSAGE(STATUS "${XMLRPC_DIR_MESSAGE}")
  128. ELSE(NOT XMLRPC_FIND_QUIETLY)
  129. IF(XMLRPC_FIND_REQUIRED)
  130. MESSAGE(FATAL_ERROR "${XMLRPC_DIR_MESSAGE}")
  131. ENDIF(XMLRPC_FIND_REQUIRED)
  132. ENDIF(NOT XMLRPC_FIND_QUIETLY)
  133. ENDIF(NOT XMLRPC_FOUND)