File: FindXMLRPC.cmake

package info (click to toggle)
cmake 4.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 152,312 kB
  • sloc: ansic: 403,890; cpp: 303,778; sh: 4,097; python: 3,582; yacc: 3,106; lex: 1,279; f90: 534; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 235; objc: 215; perl: 213; xml: 198; makefile: 108; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (195 lines) | stat: -rw-r--r-- 6,183 bytes parent folder | download | duplicates (2)
1
2
3
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file LICENSE.rst or https://cmake.org/licensing for details.

#[=======================================================================[.rst:
FindXMLRPC
----------

Finds the native XML-RPC library for C and C++:

.. code-block:: cmake

  find_package(XMLRPC [...] [COMPONENTS <components>...] [...])

XML-RPC is a standard network protocol that enables remote procedure calls
(RPC) between systems.  It encodes requests and responses in XML and uses
HTTP as the transport mechanism.

Components
^^^^^^^^^^

The XML-RPC C/C++ library consists of various features (modules) that provide
specific functionality.  The availability of these features depends on the
installed XML-RPC library version and system configuration.  Some features also
have dependencies on others.

To list the available features on a system, the ``xmlrpc-c-config`` command-line
utility can be used.

In CMake, these features can be specified as components with the
:command:`find_package` command:

.. code-block:: cmake

  find_package(XMLRPC [COMPONENTS <components>...])

Components may be:

``c++2``
  C++ wrapper API, replacing the legacy ``c++`` feature.
``c++``
  The legacy C++ wrapper API (superseded by ``c++2``).
``client``
  XML-RPC client functions (also available as the legacy libwww-based feature
  named ``libwww-client``).
``cgi-server``
  CGI-based server functions.
``abyss-server``
  Abyss-based server functions.
``pstream-server``
  The pstream-based server functions.
``server-util``
  Basic server functions (they are automatically included with ``*-server``
  features).
``abyss``
  Abyss HTTP server (not needed with ``abyss-server``).
``openssl``
  OpenSSL convenience functions.

If no components are specified, this module searches for XML-RPC library and
its include directories without additional features.

Result Variables
^^^^^^^^^^^^^^^^

This module defines the following variables:

``XMLRPC_FOUND``
  Boolean indicating whether the XML-RPC library and all its requested
  components were found.
``XMLRPC_INCLUDE_DIRS``
  Include directories containing ``xmlrpc.h`` and other headers needed to use
  the XML-RPC library.
``XMLRPC_LIBRARIES``
  List of libraries needed for linking to XML-RPC library and its requested
  features.

Examples
^^^^^^^^

Finding XML-RPC library and its ``client`` feature, and conditionally
creating an interface :ref:`imported target <Imported Targets>` that
encapsulates its usage requirements for linking to a project target:

.. code-block:: cmake

  find_package(XMLRPC REQUIRED COMPONENTS client)

  if(XMLRPC_FOUND AND NOT TARGET XMLRPC::XMLRPC)
    add_library(XMLRPC::XMLRPC INTERFACE IMPORTED)
    set_target_properties(
      XMLRPC::XMLRPC
      PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${XMLRPC_INCLUDE_DIRS}"
        INTERFACE_LINK_LIBRARIES "${XMLRPC_LIBRARIES}"
    )
  endif()

  target_link_libraries(example PRIVATE XMLRPC::XMLRPC)
#]=======================================================================]

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

# Check whether we found anything.
if(XMLRPC_C_CONFIG)
  set(XMLRPC_C_FOUND 1)
else()
  set(XMLRPC_C_FOUND 0)
endif()

# Lookup the include directories needed for the components requested.
if(XMLRPC_C_FOUND)
  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
    )

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

    # Look for -I options.
    # FIXME: Use these as hints to a find_path call to find the headers.
    set(XMLRPC_INCLUDE_DIRS)
    foreach(flag ${XMLRPC_C_CONFIG_CFLAGS})
      if("${flag}" MATCHES "^-I(.+)")
        file(TO_CMAKE_PATH "${CMAKE_MATCH_1}" DIR)
        list(APPEND XMLRPC_INCLUDE_DIRS "${DIR}")
      endif()
    endforeach()
  else()
    message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
    set(XMLRPC_C_FOUND 0)
  endif()
endif()

# Lookup the libraries needed for the components requested.
if(XMLRPC_C_FOUND)
  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
    )

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

    # Look for -L flags for directories and -l flags for library names.
    set(XMLRPC_LIBRARY_DIRS)
    set(XMLRPC_LIBRARY_NAMES)
    foreach(flag ${XMLRPC_C_CONFIG_LIBS})
      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}")
      endif()
    endforeach()

    # Search for each library needed using the directories given.
    foreach(name ${XMLRPC_LIBRARY_NAMES})
      # Look for this library.
      find_library(XMLRPC_${name}_LIBRARY
        NAMES ${name}
        HINTS ${XMLRPC_LIBRARY_DIRS}
        )
      mark_as_advanced(XMLRPC_${name}_LIBRARY)

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

      # Build an ordered list of all the libraries needed.
      set(XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES} "${XMLRPC_${name}_LIBRARY}")
    endforeach()
  else()
    message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
    set(XMLRPC_C_FOUND 0)
  endif()
endif()

# Report the results.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
    XMLRPC
    REQUIRED_VARS XMLRPC_C_FOUND XMLRPC_LIBRARIES
    FAIL_MESSAGE "XMLRPC was not found. Make sure the entries XMLRPC_* are set.")