FindXMLRPC.cmake 3.98 KB
Newer Older
1 2 3
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#[=======================================================================[.rst:
FindXMLRPC
----------

Find xmlrpc

Find the native XMLRPC headers and libraries.

::

  XMLRPC_INCLUDE_DIRS      - where to find xmlrpc.h, etc.
  XMLRPC_LIBRARIES         - List of libraries when using xmlrpc.
  XMLRPC_FOUND             - True if xmlrpc found.

XMLRPC modules may be specified as components for this find module.
Modules may be listed by running "xmlrpc-c-config".  Modules include:

::

  c++            C++ wrapper code
  libwww-client  libwww-based client
  cgi-server     CGI-based server
  abyss-server   ABYSS-based server

Typical usage:

::

  find_package(XMLRPC REQUIRED libwww-client)
#]=======================================================================]
34 35

# First find the config script from which to obtain other values.
36
find_program(XMLRPC_C_CONFIG NAMES xmlrpc-c-config)
37 38

# Check whether we found anything.
39
if(XMLRPC_C_CONFIG)
40
  set(XMLRPC_C_FOUND 1)
41
else()
42
  set(XMLRPC_C_FOUND 0)
43
endif()
44 45

# Lookup the include directories needed for the components requested.
46
if(XMLRPC_C_FOUND)
47 48 49 50 51 52
  execute_process(
    COMMAND ${XMLRPC_C_CONFIG} ${XMLRPC_FIND_COMPONENTS} --cflags
    OUTPUT_VARIABLE XMLRPC_C_CONFIG_CFLAGS
    OUTPUT_STRIP_TRAILING_WHITESPACE
    RESULT_VARIABLE XMLRPC_C_CONFIG_RESULT
    )
53 54

  # Parse the include flags.
55
  if("${XMLRPC_C_CONFIG_RESULT}" STREQUAL "0")
56
    # Convert the compile flags to a CMake list.
57
    string(REGEX REPLACE " +" ";"
58 59 60
      XMLRPC_C_CONFIG_CFLAGS "${XMLRPC_C_CONFIG_CFLAGS}")

    # Look for -I options.
61
    # FIXME: Use these as hints to a find_path call to find the headers.
62 63
    set(XMLRPC_INCLUDE_DIRS)
    foreach(flag ${XMLRPC_C_CONFIG_CFLAGS})
64 65 66
      if("${flag}" MATCHES "^-I(.+)")
        file(TO_CMAKE_PATH "${CMAKE_MATCH_1}" DIR)
        list(APPEND XMLRPC_INCLUDE_DIRS "${DIR}")
67 68 69
      endif()
    endforeach()
  else()
70
    message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
71
    set(XMLRPC_C_FOUND 0)
72 73
  endif()
endif()
74 75

# Lookup the libraries needed for the components requested.
76
if(XMLRPC_C_FOUND)
77 78 79 80 81 82
  execute_process(
    COMMAND ${XMLRPC_C_CONFIG} ${XMLRPC_FIND_COMPONENTS} --libs
    OUTPUT_VARIABLE XMLRPC_C_CONFIG_LIBS
    OUTPUT_STRIP_TRAILING_WHITESPACE
    RESULT_VARIABLE XMLRPC_C_CONFIG_RESULT
    )
83 84

  # Parse the library names and directories.
85
  if("${XMLRPC_C_CONFIG_RESULT}" STREQUAL "0")
86
    string(REGEX REPLACE " +" ";"
87 88 89
      XMLRPC_C_CONFIG_LIBS "${XMLRPC_C_CONFIG_LIBS}")

    # Look for -L flags for directories and -l flags for library names.
90 91 92
    set(XMLRPC_LIBRARY_DIRS)
    set(XMLRPC_LIBRARY_NAMES)
    foreach(flag ${XMLRPC_C_CONFIG_LIBS})
93 94 95 96 97
      if("${flag}" MATCHES "^-L(.+)")
        file(TO_CMAKE_PATH "${CMAKE_MATCH_1}" DIR)
        list(APPEND XMLRPC_LIBRARY_DIRS "${DIR}")
      elseif("${flag}" MATCHES "^-l(.+)")
        list(APPEND XMLRPC_LIBRARY_NAMES "${CMAKE_MATCH_1}")
98 99
      endif()
    endforeach()
100 101

    # Search for each library needed using the directories given.
102
    foreach(name ${XMLRPC_LIBRARY_NAMES})
103
      # Look for this library.
104
      find_library(XMLRPC_${name}_LIBRARY
105
        NAMES ${name}
106
        HINTS ${XMLRPC_LIBRARY_DIRS}
107
        )
108
      mark_as_advanced(XMLRPC_${name}_LIBRARY)
109 110

      # If any library is not found then the whole package is not found.
111
      if(NOT XMLRPC_${name}_LIBRARY)
112
        set(XMLRPC_C_FOUND 0)
113
      endif()
114 115

      # Build an ordered list of all the libraries needed.
116
      set(XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES} "${XMLRPC_${name}_LIBRARY}")
117 118
    endforeach()
  else()
119
    message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
120
    set(XMLRPC_C_FOUND 0)
121 122
  endif()
endif()
123 124

# Report the results.
125 126 127
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
    XMLRPC
128
    REQUIRED_VARS XMLRPC_C_FOUND XMLRPC_LIBRARIES
129
    FAIL_MESSAGE "XMLRPC was not found. Make sure the entries XMLRPC_* are set.")