|
| 1 | +## -*- cmake -*- |
| 2 | +project(xmlrpc-c) |
| 3 | +include(FindPkgConfig) |
| 4 | +include(CheckIncludeFile) |
| 5 | +include(CheckFunctionExists) |
| 6 | + |
| 7 | +cmake_minimum_required(VERSION 2.4) |
| 8 | + |
| 9 | +if(COMMAND cmake_policy) |
| 10 | + cmake_policy(SET CMP0003 NEW) |
| 11 | +endif() |
| 12 | + |
| 13 | + |
| 14 | +set(XMLRPC_C_VERSION_MAJOR "1" CACHE STRING "Version (major) of xmlrpc-c") |
| 15 | +set(XMLRPC_C_VERSION_MINOR "21" CACHE STRING "Version (minor) of xmlrpc-c") |
| 16 | +set(XMLRPC_C_VERSION_POINT "00" CACHE STRING "Version (point) of xmlrpc-c") |
| 17 | + |
| 18 | +set(XMLRPC_C_VERSION |
| 19 | + "${XMLRPC_C_VERSION_MAJOR}.${XMLRPC_C_VERSION_MINOR}.${XMLRPC_C_VERSION_POINT}" |
| 20 | + CACHE STRING "Version of xmlrpc-c") |
| 21 | + |
| 22 | +set(XMLRPC_C_LIBVERSION "3.${XMLRPC_C_VERSION_MINOR}") |
| 23 | +set(XMLRPC_C_SOVERSION "3") |
| 24 | + |
| 25 | +set(XMLRPC_CXX_LIBVERSION "6.${XMLRPC_C_VERSION_MINOR}") |
| 26 | +set(XMLRPC_CXX_SOVERSION "6") |
| 27 | + |
| 28 | +string(REGEX REPLACE "^0+" "" XMLRPC_C_VERSION_MAJOR_NUM "${XMLRPC_C_VERSION_MAJOR}") |
| 29 | +string(REGEX REPLACE "^0+" "" XMLRPC_C_VERSION_MINOR_NUM "${XMLRPC_C_VERSION_MINOR}") |
| 30 | +string(REGEX REPLACE "^0+(.)" "\\1" XMLRPC_C_VERSION_POINT_NUM "${XMLRPC_C_VERSION_POINT}") |
| 31 | + |
| 32 | + |
| 33 | +macro(ensc_set_bool NAME VALUE DESC) |
| 34 | + set(${NAME} ${VALUE} CACHE BOOL ${DESC}) |
| 35 | + if(${NAME}) |
| 36 | + set(_${NAME} 1) |
| 37 | + else(${NAME}) |
| 38 | + set(_${NAME} 0) |
| 39 | + endif(${NAME}) |
| 40 | +endmacro(ensc_set_bool) |
| 41 | + |
| 42 | +macro(ensc_pkgconfig COMP) |
| 43 | + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${COMP}.pc.cmake |
| 44 | + ${CMAKE_CURRENT_BINARY_DIR}/${COMP}.pc |
| 45 | + @ONLY) |
| 46 | + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${COMP}.pc |
| 47 | + DESTINATION ${pkgconfdir}) |
| 48 | +endmacro(ensc_pkgconfig) |
| 49 | + |
| 50 | +macro(ensc_pkgconfig_lib TARGET LIBS) |
| 51 | + get_target_property(libtype ${TARGET} TYPE) |
| 52 | + if("${libtype}" STREQUAL "STATIC_LIBRARY") |
| 53 | + list(APPEND ${TARGET}_pkgconfig_libs "${LIBS}") |
| 54 | + endif("${libtype}" STREQUAL "STATIC_LIBRARY") |
| 55 | +endmacro(ensc_pkgconfig_lib) |
| 56 | + |
| 57 | +macro(ensc_set_link_exe_flags) |
| 58 | + ## HACK: libwww has broken inter-lib dependencies and '-Wl,--as-needed' fails with it |
| 59 | + if(NOT MUST_BUILD_LIBWWW_CLIENT) |
| 60 | + set_target_properties(${ARGV} |
| 61 | + PROPERTIES |
| 62 | + LINK_FLAGS ${XMLRPC_LINKER_FLAGS}) |
| 63 | + endif(NOT MUST_BUILD_LIBWWW_CLIENT) |
| 64 | +endmacro(ensc_set_link_exe_flags) |
| 65 | + |
| 66 | +########### |
| 67 | +if(WIN32) |
| 68 | + find_program(WININET_CONFIG_EXECUTABLE wininet-config) |
| 69 | + |
| 70 | + if(DEFINED MUST_BUILD_WININET_CLIENT) |
| 71 | + set(tmp ${MUST_BUILD_WININET_CLIENT}) |
| 72 | + else(DEFINED MUST_BUILD_WININET_CLIENT) |
| 73 | + if(WININET_CONFIG_EXECUTABLE) |
| 74 | + set(tmp 1) |
| 75 | + else(WININET_CONFIG_EXECUTABLE) |
| 76 | + set(tmp 0) |
| 77 | + endif(WININET_CONFIG_EXECUTABLE) |
| 78 | + endif(DEFINED MUST_BUILD_WININET_CLIENT) |
| 79 | +else(WIN32) |
| 80 | + set(tmp 0) |
| 81 | +endif(WIN32) |
| 82 | + |
| 83 | +if(tmp) |
| 84 | + set(MUST_BUILD_CLIENT 1) |
| 85 | + exec_program(${WININET_CONFIG_EXECUTABLE} ARGS --version OUTPUT_VARIABLE WININET_VERSION) |
| 86 | + exec_program(${WININET_CONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE WININET_CFLAGS) |
| 87 | + exec_program(${WININET_CONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE WININET_LDADD) |
| 88 | + message(STATUS "Using WinInet ${WININET_VERSION} transport") |
| 89 | +endif(tmp) |
| 90 | + |
| 91 | +ensc_set_bool(MUST_BUILD_WININET_CLIENT ${tmp} "Set iff WinInet client transport shall be built") |
| 92 | +set(wininet_srcdir ${xmlrpc-c_SOURCE_DIR}/lib/wininet_transport) |
| 93 | + |
| 94 | +########### |
| 95 | +if(DEFINED MUST_BUILD_CURL_CLIENT) |
| 96 | + set(tmp REQUIRED) |
| 97 | +else(DEFINED MUST_BUILD_CURL_CLIENT) |
| 98 | + set(tmp) |
| 99 | +endif(DEFINED MUST_BUILD_CURL_CLIENT) |
| 100 | + |
| 101 | +pkg_check_modules(CURL ${tmp} libcurl) |
| 102 | + |
| 103 | +ensc_set_bool(MUST_BUILD_CURL_CLIENT ${CURL_FOUND} "Set iff Curl client transport shall be built") |
| 104 | +set(curl_srcdir ${xmlrpc-c_SOURCE_DIR}/lib/curl_transport) |
| 105 | + |
| 106 | +if(MUST_BUILD_CURL_CLIENT) |
| 107 | + set(MUST_BUILD_CLIENT 1) |
| 108 | +endif(MUST_BUILD_CURL_CLIENT) |
| 109 | + |
| 110 | +########### |
| 111 | +find_program(LIBWWW_CONFIG_EXECUTABLE libwww-config) |
| 112 | +if(DEFINED MUST_BUILD_LIBWWW_CLIENT) |
| 113 | + set(tmp ${MUST_BUILD_LIBWWW_CLIENT}) |
| 114 | +else(DEFINED MUST_BUILD_LIBWWW_CLIENT) |
| 115 | + if(LIBWWW_CONFIG_EXECUTABLE) |
| 116 | + set(tmp 1) |
| 117 | + else(LIBWWW_CONFIG_EXECUTABLE) |
| 118 | + set(tmp 0) |
| 119 | + endif(LIBWWW_CONFIG_EXECUTABLE) |
| 120 | +endif(DEFINED MUST_BUILD_LIBWWW_CLIENT) |
| 121 | + |
| 122 | +if(tmp) |
| 123 | + set(MUST_BUILD_CLIENT 1) |
| 124 | + exec_program(${LIBWWW_CONFIG_EXECUTABLE} ARGS --version OUTPUT_VARIABLE LIBWWW_VERSION) |
| 125 | + exec_program(${LIBWWW_CONFIG_EXECUTABLE} ARGS --libs OUTPUT_VARIABLE LIBWWW_LIBS) |
| 126 | + exec_program(${LIBWWW_CONFIG_EXECUTABLE} ARGS --cflags OUTPUT_VARIABLE LIBWWW_CFLAGS) |
| 127 | + message(STATUS "Using libwww ${LIBWWW_VERSION} transport") |
| 128 | +endif(tmp) |
| 129 | +ensc_set_bool(MUST_BUILD_LIBWWW_CLIENT ${tmp} "Set iff LibWWW client transport shall be built") |
| 130 | +set(libwww_srcdir ${xmlrpc-c_SOURCE_DIR}/lib/libwww_transport) |
| 131 | + |
| 132 | +############ |
| 133 | + |
| 134 | +set(ENABLE_CGI_SERVER 1 CACHE BOOL "Set iff CGI server shall be enabled") |
| 135 | +set(ENABLE_CPLUSPLUS 1 CACHE BOOL "Set iff C++ part shall be enabled") |
| 136 | +set(ENABLE_ABYSS_SERVER 1 CACHE BOOL "Set iff Abyss server shall be enabled") |
| 137 | +set(ENABLE_LIBXML2_BACKEND 1 CACHE BOOL "Set iff libxml2 backend shall be used") |
| 138 | +set(ENABLE_ABYSS_SERVER 1 CACHE BOOL "Set iff abyss server shall be enabled") |
| 139 | +set(ENABLE_ABYSS_THREADS 1 CACHE BOOL "Use pthread") |
| 140 | + |
| 141 | +if(ENABLE_LIBXML2_BACKEND) |
| 142 | + pkg_check_modules(LIBXML2 libxml-2.0) |
| 143 | + |
| 144 | + if(LIBXML2_FOUND) |
| 145 | + set(libxml_pkgconfig libxml-2.0) # TODO: add more alternative modules |
| 146 | + endif(LIBXML2_FOUND) |
| 147 | +endif(ENABLE_LIBXML2_BACKEND) |
| 148 | + |
| 149 | +########### |
| 150 | + |
| 151 | +set(ENABLE_TOOLS 0 CACHE BOOL "Build the tools") |
| 152 | +pkg_check_modules(NCURSES ncurses) |
| 153 | +find_library(READLINE readline) |
| 154 | + |
| 155 | +if (ENABLE_TOOLS) |
| 156 | + message(STATUS "Building tools") |
| 157 | + if (MUST_BUILD_LIBWWW_CLIENT OR MUST_BUILD_WININET_CLIENT OR MUST_BUILD_CURL_CLIENT) |
| 158 | + if (NCURSES_FOUND AND READLINE) |
| 159 | + set(BUILD_XMLRPC_PSTREAM 1) |
| 160 | + message(STATUS "Building xmlrpc_pstream tool") |
| 161 | + endif() |
| 162 | + set(BUILD_TOOLS 1) |
| 163 | + endif() |
| 164 | +endif() |
| 165 | + |
| 166 | +#### <wchar.h> tests |
| 167 | +check_include_file(wchar.h _have_wchar_h) |
| 168 | +if(_have_wchar_h) |
| 169 | + set(HAVE_WCHAR_H 1) |
| 170 | +else(_have_wchar_h) |
| 171 | + set(HAVE_WCHAR_H 1) |
| 172 | +endif(_have_wchar_h) |
| 173 | +set(XMLRPC_HAVE_WCHAR ${HAVE_WCHAR_H}) |
| 174 | +set(HAVE_WCHAR_H_DEFINE ${HAVE_WCHAR_H}) |
| 175 | + |
| 176 | + |
| 177 | +####### |
| 178 | +set(LINKER_AS_NEEDED 1 CACHE BOOL "Use the --as-needed linker option") |
| 179 | +if(LINKER_AS_NEEDED) |
| 180 | + set(XMLRPC_LINKER_FLAGS "-Wl,--as-needed") |
| 181 | +endif(LINKER_AS_NEEDED) |
| 182 | + |
| 183 | + |
| 184 | +try_compile(HAVE_ATTR_UNUSED |
| 185 | + ${CMAKE_BINARY_DIR}/ |
| 186 | + ${xmlrpc-c_SOURCE_DIR}/cmake/try-attr.cc |
| 187 | + CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=-DCMAKE_TEST_ATTR=__unused__) |
| 188 | + |
| 189 | +try_compile(VA_LIST_IS_NOT_ARRAY |
| 190 | + ${CMAKE_BINARY_DIR}/ |
| 191 | + ${xmlrpc-c_SOURCE_DIR}/cmake/va-list-is-array.c) |
| 192 | + |
| 193 | +if(VA_LIST_IS_NOT_ARRAY) |
| 194 | + set(VA_LIST_IS_ARRAY 0) |
| 195 | + message(STATUS "va_list is not an array") |
| 196 | +else(VA_LIST_IS_NOT_ARRAY) |
| 197 | + set(VA_LIST_IS_ARRAY 1) |
| 198 | + message(STATUS "va_list is an array") |
| 199 | +endif(VA_LIST_IS_NOT_ARRAY) |
| 200 | + |
| 201 | + |
| 202 | +if(HAVE_ATTR_UNUSED) |
| 203 | + set(ATTR_UNUSED "__attribute__((__unused__))") |
| 204 | +endif(HAVE_ATTR_UNUSED) |
| 205 | + |
| 206 | +if(WIN32) |
| 207 | + set(DIRECTORY_SEPARATOR "\\") |
| 208 | +else(WIN32) |
| 209 | + set(DIRECTORY_SEPARATOR "/") |
| 210 | +endif(WIN32) |
| 211 | + |
| 212 | +check_include_file(sys/filio.h HAVE_SYS_FILIO_H) |
| 213 | +check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H) |
| 214 | +check_include_file(sys/select.h HAVE_SYS_SELECT_H) |
| 215 | +check_function_exists(setenv HAVE_SETENV) |
| 216 | +check_function_exists(strcasecmp HAVE_STRCASECMP) |
| 217 | +check_function_exists(_stricmp HAVE__STRICMP) |
| 218 | +check_function_exists(stricmp HAVE_STRICMP) |
| 219 | +check_function_exists(strtoll HAVE_STRTOLL) |
| 220 | +check_function_exists(__strtoll HAVE___STRTOLL) |
| 221 | +check_function_exists(strtoull HAVE_STRTOULL) |
| 222 | +check_function_exists(__strtoull HAVE___STRTOULL) |
| 223 | +check_function_exists(strtoq HAVE_STRTOQ) |
| 224 | +check_function_exists(strtouq HAVE_STRTOUQ) |
| 225 | +check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) |
| 226 | +check_function_exists(setgroups HAVE_SETGROUPS) |
| 227 | +check_function_exists(asprintf HAVE_ASPRINTF) |
| 228 | +check_function_exists(pselect HAVE_PSELECT) |
| 229 | +check_function_exists(wcsncmp HAVE_WCSNCMP) |
| 230 | +check_function_exists(localtime_r HAVE_LOCALTIME_R) |
| 231 | +check_function_exists(gmtime_r HAVE_GMTIME_R) |
| 232 | + |
| 233 | + |
| 234 | +configure_file(${xmlrpc-c_SOURCE_DIR}/xmlrpc_config.h.cmake |
| 235 | + ${xmlrpc-c_BINARY_DIR}/xmlrpc_config.h |
| 236 | + ESCAPE_QUOTES @ONLY) |
| 237 | + |
| 238 | +configure_file(${xmlrpc-c_SOURCE_DIR}/version.h.cmake |
| 239 | + ${xmlrpc-c_BINARY_DIR}/version.h |
| 240 | + ESCAPE_QUOTES @ONLY) |
| 241 | + |
| 242 | +configure_file(${xmlrpc-c_SOURCE_DIR}/transport_config.h.cmake |
| 243 | + ${xmlrpc-c_BINARY_DIR}/transport_config.h |
| 244 | + ESCAPE_QUOTES @ONLY) |
| 245 | + |
| 246 | +configure_file(${xmlrpc-c_SOURCE_DIR}/include/xmlrpc-c/config.h.cmake |
| 247 | + ${xmlrpc-c_BINARY_DIR}/include/xmlrpc-c/config.h |
| 248 | + ESCAPE_QUOTES @ONLY) |
| 249 | + |
| 250 | + |
| 251 | +include_directories(${xmlrpc-c_SOURCE_DIR}/include) |
| 252 | +include_directories(${xmlrpc-c_BINARY_DIR}/include) |
| 253 | +include_directories(${xmlrpc-c_SOURCE_DIR}/lib/util/include) |
| 254 | +include_directories(${xmlrpc-c_BINARY_DIR}) |
| 255 | + |
| 256 | +add_custom_target(dist |
| 257 | + rm -rf _dist && mkdir -p _dist/xmlrpc-c-${XMLRPC_C_VERSION} |
| 258 | + COMMAND cp -a ${xmlrpc-c_SOURCE_DIR}/* _dist/xmlrpc-c-${XMLRPC_C_VERSION}/ |
| 259 | + COMMAND cd _dist && tar cjf ../xmlrpc-c-${XMLRPC_C_VERSION}.tar.bz2 xmlrpc-c-${XMLRPC_C_VERSION} --exclude=.git --exclude=CVS --exclude=.svn |
| 260 | + ) |
| 261 | + |
| 262 | +set(_lib lib CACHE STRING "Basename of the library-directory; usually 'lib' or 'lib64' (on multilib archs)") |
| 263 | +set(_bin bin CACHE STRING "Basename of the bin-directory; usually 'bin'") |
| 264 | +set(prefix ${CMAKE_INSTALL_PREFIX}) |
| 265 | +set(libdir "${prefix}/${_lib}") |
| 266 | +set(bindir "${prefix}/${_bin}") |
| 267 | +set(mandir "${prefix}/share/man") |
| 268 | +set(pkgconfdir "${libdir}/pkgconfig") |
| 269 | +set(includedir "${prefix}/include") |
| 270 | + |
| 271 | +############# |
| 272 | + |
| 273 | +install(PROGRAMS xmlrpc-c-config DESTINATION ${_bin}) |
| 274 | + |
| 275 | +enable_testing() |
| 276 | + |
| 277 | +add_subdirectory(lib) |
| 278 | +add_subdirectory(Windows) |
| 279 | +add_subdirectory(doc) |
| 280 | +add_subdirectory(examples) |
| 281 | +add_subdirectory(include) |
| 282 | +add_subdirectory(src) |
| 283 | + |
| 284 | +if (BUILD_TOOLS) |
| 285 | + add_subdirectory(tools) |
| 286 | +endif() |
0 commit comments