Merge topic 'cxx-checks-tolerate-unused-arguments'
[kiteware-cmake.git] / Modules / FindXMLRPC.cmake
blob69e6df22bf8b3aa66eafb8fdc7e9b7eb69a86582
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
5 FindXMLRPC
6 ----------
8 Find xmlrpc
10 Find the native XMLRPC headers and libraries.
14   XMLRPC_INCLUDE_DIRS      - where to find xmlrpc.h, etc.
15   XMLRPC_LIBRARIES         - List of libraries when using xmlrpc.
16   XMLRPC_FOUND             - True if xmlrpc found.
18 XMLRPC modules may be specified as components for this find module.
19 Modules may be listed by running "xmlrpc-c-config".  Modules include:
23   c++            C++ wrapper code
24   libwww-client  libwww-based client
25   cgi-server     CGI-based server
26   abyss-server   ABYSS-based server
28 Typical usage:
32   find_package(XMLRPC REQUIRED libwww-client)
33 #]=======================================================================]
35 # First find the config script from which to obtain other values.
36 find_program(XMLRPC_C_CONFIG NAMES xmlrpc-c-config)
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()
45 # Lookup the include directories needed for the components requested.
46 if(XMLRPC_C_FOUND)
47   execute_process(
48     COMMAND ${XMLRPC_C_CONFIG} ${XMLRPC_FIND_COMPONENTS} --cflags
49     OUTPUT_VARIABLE XMLRPC_C_CONFIG_CFLAGS
50     OUTPUT_STRIP_TRAILING_WHITESPACE
51     RESULT_VARIABLE XMLRPC_C_CONFIG_RESULT
52     )
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       XMLRPC_C_CONFIG_CFLAGS "${XMLRPC_C_CONFIG_CFLAGS}")
60     # Look for -I options.
61     # FIXME: Use these as hints to a find_path call to find the headers.
62     set(XMLRPC_INCLUDE_DIRS)
63     foreach(flag ${XMLRPC_C_CONFIG_CFLAGS})
64       if("${flag}" MATCHES "^-I(.+)")
65         file(TO_CMAKE_PATH "${CMAKE_MATCH_1}" DIR)
66         list(APPEND XMLRPC_INCLUDE_DIRS "${DIR}")
67       endif()
68     endforeach()
69   else()
70     message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
71     set(XMLRPC_C_FOUND 0)
72   endif()
73 endif()
75 # Lookup the libraries needed for the components requested.
76 if(XMLRPC_C_FOUND)
77   execute_process(
78     COMMAND ${XMLRPC_C_CONFIG} ${XMLRPC_FIND_COMPONENTS} --libs
79     OUTPUT_VARIABLE XMLRPC_C_CONFIG_LIBS
80     OUTPUT_STRIP_TRAILING_WHITESPACE
81     RESULT_VARIABLE XMLRPC_C_CONFIG_RESULT
82     )
84   # Parse the library names and directories.
85   if("${XMLRPC_C_CONFIG_RESULT}" STREQUAL "0")
86     string(REGEX REPLACE " +" ";"
87       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         file(TO_CMAKE_PATH "${CMAKE_MATCH_1}" DIR)
95         list(APPEND XMLRPC_LIBRARY_DIRS "${DIR}")
96       elseif("${flag}" MATCHES "^-l(.+)")
97         list(APPEND XMLRPC_LIBRARY_NAMES "${CMAKE_MATCH_1}")
98       endif()
99     endforeach()
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)
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()
115       # Build an ordered list of all the libraries needed.
116       set(XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES} "${XMLRPC_${name}_LIBRARY}")
117     endforeach()
118   else()
119     message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
120     set(XMLRPC_C_FOUND 0)
121   endif()
122 endif()
124 # Report the results.
125 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
126 FIND_PACKAGE_HANDLE_STANDARD_ARGS(
127     XMLRPC
128     REQUIRED_VARS XMLRPC_C_FOUND XMLRPC_LIBRARIES
129     FAIL_MESSAGE "XMLRPC was not found. Make sure the entries XMLRPC_* are set.")