Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / FindXMLRPC.cmake
1 # - Find xmlrpc
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:
8 #  c++            C++ wrapper code
9 #  libwww-client  libwww-based client
10 #  cgi-server     CGI-based server
11 #  abyss-server   ABYSS-based server
12 # Typical usage:
13 #  find_package(XMLRPC REQUIRED libwww-client)
14
15 #=============================================================================
16 # Copyright 2001-2009 Kitware, Inc.
17 #
18 # Distributed under the OSI-approved BSD License (the "License");
19 # see accompanying file Copyright.txt for details.
20 #
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.)
27
28 # First find the config script from which to obtain other values.
29 find_program(XMLRPC_C_CONFIG NAMES xmlrpc-c-config)
30
31 # Check whether we found anything.
32 if(XMLRPC_C_CONFIG)
33   set(XMLRPC_FOUND 1)
34 else()
35   set(XMLRPC_FOUND 0)
36 endif()
37
38 # Lookup the include directories needed for the components requested.
39 if(XMLRPC_FOUND)
40   # Use the newer EXECUTE_PROCESS command if it is available.
41   if(COMMAND EXECUTE_PROCESS)
42     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
47       )
48   else()
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
52       )
53   endif()
54
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}")
60
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}")
68       endif()
69     endforeach()
70   else()
71     message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
72     set(XMLRPC_FOUND 0)
73   endif()
74 endif()
75
76 # Lookup the libraries needed for the components requested.
77 if(XMLRPC_FOUND)
78   # Use the newer EXECUTE_PROCESS command if it is available.
79   if(COMMAND EXECUTE_PROCESS)
80     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
85       )
86   else()
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
90       )
91   endif()
92
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}")
97
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}")
109       endif()
110     endforeach()
111
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
116         NAMES ${name}
117         HINTS ${XMLRPC_LIBRARY_DIRS}
118         )
119       mark_as_advanced(XMLRPC_${name}_LIBRARY)
120
121       # If any library is not found then the whole package is not found.
122       if(NOT XMLRPC_${name}_LIBRARY)
123         set(XMLRPC_FOUND 0)
124       endif()
125
126       # Build an ordered list of all the libraries needed.
127       set(XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES} "${XMLRPC_${name}_LIBRARY}")
128     endforeach()
129   else()
130     message("Error running ${XMLRPC_C_CONFIG}: [${XMLRPC_C_CONFIG_RESULT}]")
131     set(XMLRPC_FOUND 0)
132   endif()
133 endif()
134
135 # Report the results.
136 if(NOT XMLRPC_FOUND)
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}")
141   else()
142     if(XMLRPC_FIND_REQUIRED)
143       message(FATAL_ERROR "${XMLRPC_DIR_MESSAGE}")
144     endif()
145   endif()
146 endif()