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:
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:
24 libwww-client libwww-based client
25 cgi-server CGI-based server
26 abyss-server ABYSS-based server
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.
45 # Lookup the include directories needed for the components requested.
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
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}")
70 message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
75 # Lookup the libraries needed for the components requested.
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
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}")
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
106 HINTS ${XMLRPC_LIBRARY_DIRS}
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)
115 # Build an ordered list of all the libraries needed.
116 set(XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES} "${XMLRPC_${name}_LIBRARY}")
119 message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
120 set(XMLRPC_C_FOUND 0)
124 # Report the results.
125 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
126 FIND_PACKAGE_HANDLE_STANDARD_ARGS(
128 REQUIRED_VARS XMLRPC_C_FOUND XMLRPC_LIBRARIES
129 FAIL_MESSAGE "XMLRPC was not found. Make sure the entries XMLRPC_* are set.")