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:
9 # libwww-client libwww-based client
10 # cgi-server CGI-based server
11 # abyss-server ABYSS-based server
13 # find_package(XMLRPC REQUIRED libwww-client)
15 #=============================================================================
16 # Copyright 2001-2009 Kitware, Inc.
18 # Distributed under the OSI-approved BSD License (the "License");
19 # see accompanying file Copyright.txt for details.
21 # This software is distributed WITHOUT ANY WARRANTY; without even the
22 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 # See the License for more information.
24 #=============================================================================
25 # (To distribute this file outside of CMake, substitute the full
26 # License text for the above reference.)
28 # First find the config script from which to obtain other values.
29 find_program(XMLRPC_C_CONFIG NAMES xmlrpc-c-config)
31 # Check whether we found anything.
38 # Lookup the include directories needed for the components requested.
40 # Use the newer EXECUTE_PROCESS command if it is available.
41 if(COMMAND EXECUTE_PROCESS)
43 COMMAND ${XMLRPC_C_CONFIG} ${XMLRPC_FIND_COMPONENTS} --cflags
44 OUTPUT_VARIABLE XMLRPC_C_CONFIG_CFLAGS
45 OUTPUT_STRIP_TRAILING_WHITESPACE
46 RESULT_VARIABLE XMLRPC_C_CONFIG_RESULT
49 exec_program(${XMLRPC_C_CONFIG} ARGS "${XMLRPC_FIND_COMPONENTS} --cflags"
50 OUTPUT_VARIABLE XMLRPC_C_CONFIG_CFLAGS
51 RETURN_VALUE XMLRPC_C_CONFIG_RESULT
55 # Parse the include flags.
56 if("${XMLRPC_C_CONFIG_RESULT}" MATCHES "^0$")
57 # Convert the compile flags to a CMake list.
58 string(REGEX REPLACE " +" ";"
59 XMLRPC_C_CONFIG_CFLAGS "${XMLRPC_C_CONFIG_CFLAGS}")
61 # Look for -I options.
62 set(XMLRPC_INCLUDE_DIRS)
63 foreach(flag ${XMLRPC_C_CONFIG_CFLAGS})
64 if("${flag}" MATCHES "^-I")
65 string(REGEX REPLACE "^-I" "" DIR "${flag}")
66 file(TO_CMAKE_PATH "${DIR}" DIR)
67 set(XMLRPC_INCLUDE_DIRS ${XMLRPC_INCLUDE_DIRS} "${DIR}")
71 message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
76 # Lookup the libraries needed for the components requested.
78 # Use the newer EXECUTE_PROCESS command if it is available.
79 if(COMMAND EXECUTE_PROCESS)
81 COMMAND ${XMLRPC_C_CONFIG} ${XMLRPC_FIND_COMPONENTS} --libs
82 OUTPUT_VARIABLE XMLRPC_C_CONFIG_LIBS
83 OUTPUT_STRIP_TRAILING_WHITESPACE
84 RESULT_VARIABLE XMLRPC_C_CONFIG_RESULT
87 exec_program(${XMLRPC_C_CONFIG} ARGS "${XMLRPC_FIND_COMPONENTS} --libs"
88 OUTPUT_VARIABLE XMLRPC_C_CONFIG_LIBS
89 RETURN_VALUE XMLRPC_C_CONFIG_RESULT
93 # Parse the library names and directories.
94 if("${XMLRPC_C_CONFIG_RESULT}" MATCHES "^0$")
95 string(REGEX REPLACE " +" ";"
96 XMLRPC_C_CONFIG_LIBS "${XMLRPC_C_CONFIG_LIBS}")
98 # Look for -L flags for directories and -l flags for library names.
99 set(XMLRPC_LIBRARY_DIRS)
100 set(XMLRPC_LIBRARY_NAMES)
101 foreach(flag ${XMLRPC_C_CONFIG_LIBS})
102 if("${flag}" MATCHES "^-L")
103 string(REGEX REPLACE "^-L" "" DIR "${flag}")
104 file(TO_CMAKE_PATH "${DIR}" DIR)
105 set(XMLRPC_LIBRARY_DIRS ${XMLRPC_LIBRARY_DIRS} "${DIR}")
106 elseif("${flag}" MATCHES "^-l")
107 string(REGEX REPLACE "^-l" "" NAME "${flag}")
108 set(XMLRPC_LIBRARY_NAMES ${XMLRPC_LIBRARY_NAMES} "${NAME}")
112 # Search for each library needed using the directories given.
113 foreach(name ${XMLRPC_LIBRARY_NAMES})
114 # Look for this library.
115 find_library(XMLRPC_${name}_LIBRARY
117 HINTS ${XMLRPC_LIBRARY_DIRS}
119 mark_as_advanced(XMLRPC_${name}_LIBRARY)
121 # If any library is not found then the whole package is not found.
122 if(NOT XMLRPC_${name}_LIBRARY)
126 # Build an ordered list of all the libraries needed.
127 set(XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES} "${XMLRPC_${name}_LIBRARY}")
130 message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
135 # Report the results.
137 set(XMLRPC_DIR_MESSAGE
138 "XMLRPC was not found. Make sure the entries XMLRPC_* are set.")
139 if(NOT XMLRPC_FIND_QUIETLY)
140 message(STATUS "${XMLRPC_DIR_MESSAGE}")
142 if(XMLRPC_FIND_REQUIRED)
143 message(FATAL_ERROR "${XMLRPC_DIR_MESSAGE}")