• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1CMAKE_MINIMUM_REQUIRED (VERSION 3.1.0)
2
3INCLUDE (CheckIncludeFiles)
4INCLUDE (CheckTypeSize)
5INCLUDE (CheckFunctionExists)
6INCLUDE (CheckSymbolExists)
7INCLUDE (CheckCSourceCompiles)
8INCLUDE (CheckStructHasMember)
9INCLUDE (CheckLibraryExists)
10
11PROJECT (c-ares LANGUAGES C VERSION "1.18.0" )
12
13# Set this version before release
14SET (CARES_VERSION "1.18.1")
15
16INCLUDE (GNUInstallDirs) # include this *AFTER* PROJECT(), otherwise paths are wrong.
17
18# This is for libtool compatibility, and specified in a form that is easily
19# translatable from libtool (even if the actual form doesn't make sense).
20# For instance, in an autotools project, in Makefile.am there is a line that
21# contains something like:
22#     -version-info 4:0:2
23# This breaks down into sections of current:revision:age
24# This then generates a version of  "(current-age).age.revision"  with an
25# interface version of "(current-age)"
26# For example, a version of 4:0:2 would generate output such as:
27#    libname.so   -> libname.so.2
28#    libname.so.2 -> libname.so.2.2.0
29SET (CARES_LIB_VERSIONINFO "7:1:5")
30
31
32OPTION (CARES_STATIC     "Build as a static library"                                             OFF)
33OPTION (CARES_SHARED     "Build as a shared library"                                             ON)
34OPTION (CARES_INSTALL    "Create installation targets (chain builders may want to disable this)" ON)
35OPTION (CARES_STATIC_PIC "Build the static library as PIC (position independent)"                OFF)
36OPTION (CARES_BUILD_TESTS "Build and run tests"                                                  OFF)
37OPTION (CARES_BUILD_CONTAINER_TESTS "Build and run container tests (implies CARES_BUILD_TESTS, Linux only)" OFF)
38OPTION (CARES_BUILD_TOOLS "Build tools"                                                          ON)
39
40# Tests require static to be enabled on Windows to be able to access otherwise hidden symbols
41IF (CARES_BUILD_TESTS AND (NOT CARES_STATIC) AND WIN32)
42	SET (CARES_STATIC ON)
43	SET (CARES_STATIC_PIC ON)
44	MESSAGE (WARNING "Static building was requested be disabled, but reenabled to support tests")
45ENDIF ()
46
47# allow linking against the static runtime library in msvc
48IF (MSVC)
49	OPTION (CARES_MSVC_STATIC_RUNTIME "Link against the static runtime library" OFF)
50	IF (CARES_MSVC_STATIC_RUNTIME)
51		# CMAKE_CONFIGURATION_TYPES is empty on non-IDE generators (Ninja, NMake)
52		# and that's why we also use CMAKE_BUILD_TYPE to cover for those generators.
53		# For IDE generators, CMAKE_BUILD_TYPE is usually empty
54		FOREACH (config_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
55			STRING (TOUPPER ${config_type} upper_config_type)
56			SET (flag_var "CMAKE_C_FLAGS_${upper_config_type}")
57			IF (${flag_var} MATCHES "/MD")
58				STRING (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
59			ENDIF ()
60		ENDFOREACH ()
61
62		# clean up
63		SET (upper_config_type)
64		SET (config_type)
65		SET (flag_var)
66	ENDIF ()
67ENDIF ()
68
69# Keep build organized.
70SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
71SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
72SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
73SET (PACKAGE_DIRECTORY ${PROJECT_BINARY_DIR}/package)
74
75# Destinations for installing different kinds of targets (pass to install command).
76SET (TARGETS_INST_DEST
77	RUNTIME DESTINATION  ${CMAKE_INSTALL_BINDIR}
78	BUNDLE DESTINATION   ${CMAKE_INSTALL_BINDIR}
79	LIBRARY DESTINATION  ${CMAKE_INSTALL_LIBDIR}
80	ARCHIVE DESTINATION  ${CMAKE_INSTALL_LIBDIR}
81)
82
83# Function in Library
84# CHECK_LIBRARY_EXISTS can't be used as it will return true if the function
85# is found in a different dependent library.
86MACRO (CARES_FUNCTION_IN_LIBRARY func lib var)
87	CHECK_FUNCTION_EXISTS ("${func}" "_CARES_FUNC_IN_LIB_GLOBAL_${func}")
88	IF ("${_CARES_FUNC_IN_LIB_GLOBAL_${func}}")
89		SET (${var} FALSE)
90	ELSE ()
91		CHECK_LIBRARY_EXISTS ("${lib}" "${func}" "" ${var})
92	ENDIF ()
93ENDMACRO ()
94
95# Look for dependent/required libraries
96CARES_FUNCTION_IN_LIBRARY (res_servicename resolv HAVE_RES_SERVICENAME_IN_LIBRESOLV)
97IF (HAVE_RES_SERVICENAME_IN_LIBRESOLV)
98	SET (HAVE_LIBRESOLV 1)
99ENDIF ()
100
101IF (APPLE)
102	CHECK_C_SOURCE_COMPILES ("
103	#include <stdio.h>
104	#include <TargetConditionals.h>
105	int main() {
106#if TARGET_OS_IPHONE == 0
107#error Not an iPhone target
108#endif
109return 0;
110	}
111	"
112	IOS)
113
114	CHECK_C_SOURCE_COMPILES ("
115#include <stdio.h>
116#include <TargetConditionals.h>
117	int main() {
118#if TARGET_OS_IPHONE == 0 || __IPHONE_OS_VERSION_MIN_REQUIRED < 100000
119#  error Not iOS v10
120#endif
121return 0;
122	}
123	"
124	IOS_V10)
125
126	CHECK_C_SOURCE_COMPILES ("
127#include <stdio.h>
128#include <AvailabilityMacros.h>
129#ifndef MAC_OS_X_VERSION_10_12
130#  define MAC_OS_X_VERSION_10_12 101200
131#endif
132	int main() {
133#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
134#  error Not MacOSX 10.12 or higher
135#endif
136return 0;
137	}
138	"
139	MACOS_V1012)
140ENDIF ()
141
142IF ((IOS OR APPLE OR ZOS) AND HAVE_LIBRESOLV)
143	SET (CARES_USE_LIBRESOLV 1)
144ENDIF()
145
146
147CARES_FUNCTION_IN_LIBRARY (gethostbyname nsl HAVE_LIBNSL)
148CARES_FUNCTION_IN_LIBRARY (gethostbyname socket HAVE_GHBN_LIBSOCKET)
149CARES_FUNCTION_IN_LIBRARY (gethostbyname network HAVE_LIBNETWORK)
150CARES_FUNCTION_IN_LIBRARY (socket socket HAVE_SOCKET_LIBSOCKET)
151IF (HAVE_GHBN_LIBSOCKET OR HAVE_SOCKET_LIBSOCKET)
152	SET(HAVE_LIBSOCKET TRUE)
153ENDIF ()
154CARES_FUNCTION_IN_LIBRARY (socket network HAVE_LIBNETWORK)
155CARES_FUNCTION_IN_LIBRARY (clock_gettime rt HAVE_LIBRT)
156
157
158# Look for necessary includes
159CHECK_INCLUDE_FILES (sys/types.h           HAVE_SYS_TYPES_H)
160CHECK_INCLUDE_FILES (sys/socket.h          HAVE_SYS_SOCKET_H)
161CHECK_INCLUDE_FILES (sys/sockio.h          HAVE_SYS_SOCKIO_H)
162CHECK_INCLUDE_FILES (arpa/inet.h           HAVE_ARPA_INET_H)
163CHECK_INCLUDE_FILES (arpa/nameser_compat.h HAVE_ARPA_NAMESER_COMPAT_H)
164CHECK_INCLUDE_FILES (arpa/nameser.h        HAVE_ARPA_NAMESER_H)
165CHECK_INCLUDE_FILES (assert.h              HAVE_ASSERT_H)
166CHECK_INCLUDE_FILES (errno.h               HAVE_ERRNO_H)
167CHECK_INCLUDE_FILES (fcntl.h               HAVE_FCNTL_H)
168CHECK_INCLUDE_FILES (inttypes.h            HAVE_INTTYPES_H)
169CHECK_INCLUDE_FILES (limits.h              HAVE_LIMITS_H)
170CHECK_INCLUDE_FILES (malloc.h              HAVE_MALLOC_H)
171CHECK_INCLUDE_FILES (memory.h              HAVE_MEMORY_H)
172CHECK_INCLUDE_FILES (netdb.h               HAVE_NETDB_H)
173CHECK_INCLUDE_FILES (netinet/in.h          HAVE_NETINET_IN_H)
174CHECK_INCLUDE_FILES (net/if.h              HAVE_NET_IF_H)
175CHECK_INCLUDE_FILES (signal.h              HAVE_SIGNAL_H)
176CHECK_INCLUDE_FILES (socket.h              HAVE_SOCKET_H)
177CHECK_INCLUDE_FILES (stdbool.h             HAVE_STDBOOL_H)
178CHECK_INCLUDE_FILES (stdint.h              HAVE_STDINT_H)
179CHECK_INCLUDE_FILES (stdlib.h              HAVE_STDLIB_H)
180CHECK_INCLUDE_FILES (strings.h             HAVE_STRINGS_H)
181CHECK_INCLUDE_FILES (string.h              HAVE_STRING_H)
182CHECK_INCLUDE_FILES (stropts.h             HAVE_STROPTS_H)
183CHECK_INCLUDE_FILES (sys/ioctl.h           HAVE_SYS_IOCTL_H)
184CHECK_INCLUDE_FILES (sys/param.h           HAVE_SYS_PARAM_H)
185CHECK_INCLUDE_FILES (sys/select.h          HAVE_SYS_SELECT_H)
186CHECK_INCLUDE_FILES (sys/stat.h            HAVE_SYS_STAT_H)
187CHECK_INCLUDE_FILES (sys/time.h            HAVE_SYS_TIME_H)
188CHECK_INCLUDE_FILES (sys/uio.h             HAVE_SYS_UIO_H)
189CHECK_INCLUDE_FILES (time.h                HAVE_TIME_H)
190CHECK_INCLUDE_FILES (dlfcn.h               HAVE_DLFCN_H)
191CHECK_INCLUDE_FILES (unistd.h              HAVE_UNISTD_H)
192
193# On OpenBSD, you must include sys/types.h before netinet/tcp.h
194IF (HAVE_SYS_TYPES_H)
195  CHECK_INCLUDE_FILES ("sys/types.h;netinet/tcp.h"         HAVE_NETINET_TCP_H)
196ELSE ()
197  CHECK_INCLUDE_FILES (netinet/tcp.h                       HAVE_NETINET_TCP_H)
198ENDIF ()
199
200# Include order matters for these windows files.
201# As cygwin environment has both socket.h and winsock2.h
202# headers check WIN32 not to include the later one here
203IF (WIN32)
204CHECK_INCLUDE_FILES ("winsock2.h;windows.h"            HAVE_WINSOCK2_H)
205CHECK_INCLUDE_FILES ("winsock2.h;ws2tcpip.h;windows.h" HAVE_WS2TCPIP_H)
206CHECK_INCLUDE_FILES ("winsock.h;windows.h"             HAVE_WINSOCK_H)
207CHECK_INCLUDE_FILES (windows.h                         HAVE_WINDOWS_H)
208ENDIF ()
209
210# Set system-specific compiler flags
211IF (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
212	LIST (APPEND SYSFLAGS -D_DARWIN_C_SOURCE)
213ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Linux")
214	LIST (APPEND SYSFLAGS -D_GNU_SOURCE -D_POSIX_C_SOURCE=199309L -D_XOPEN_SOURCE=600)
215ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
216	LIST (APPEND SYSFLAGS -D__EXTENSIONS__ -D_REENTRANT -D_XOPEN_SOURCE=600)
217ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "AIX")
218	LIST (APPEND SYSFLAGS -D_ALL_SOURCE -D_XOPEN_SOURCE=600 -D_USE_IRS)
219ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
220	# Don't define _XOPEN_SOURCE on FreeBSD, it actually reduces visibility instead of increasing it
221ELSEIF (WIN32)
222	LIST (APPEND SYSFLAGS -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_WIN32_WINNT=0x0600)
223ENDIF ()
224ADD_DEFINITIONS(${SYSFLAGS})
225
226
227
228# Tell C-Ares about libraries to depend on
229IF (HAVE_LIBRESOLV)
230	LIST (APPEND CARES_DEPENDENT_LIBS resolv)
231ENDIF ()
232IF (HAVE_LIBNSL)
233	LIST (APPEND CARES_DEPENDENT_LIBS nsl)
234ENDIF ()
235IF (HAVE_LIBSOCKET)
236	LIST (APPEND CARES_DEPENDENT_LIBS socket)
237ENDIF ()
238IF (HAVE_LIBNETWORK)
239	LIST (APPEND CARES_DEPENDENT_LIBS network)
240ENDIF ()
241IF (HAVE_LIBRT)
242	LIST (APPEND CARES_DEPENDENT_LIBS rt)
243ENDIF ()
244IF (WIN32)
245	LIST (APPEND CARES_DEPENDENT_LIBS ws2_32 advapi32 iphlpapi)
246ENDIF ()
247
248
249# When checking for symbols, we need to make sure we set the proper
250# headers, libraries, and definitions for the detection to work properly
251# CMAKE_REQUIRED_DEFINITIONS, CMAKE_REQUIRED_LIBRARIES, and
252# CMAKE_EXTRA_INCLUDE_FILES.  When we're done with the detection, we'll
253# unset them.
254
255SET (CMAKE_REQUIRED_DEFINITIONS ${SYSFLAGS})
256LIST (APPEND CMAKE_REQUIRED_LIBRARIES ${CARES_DEPENDENT_LIBS})
257
258MACRO (CARES_EXTRAINCLUDE_IFSET var include)
259	IF (${var})
260		LIST (APPEND CMAKE_EXTRA_INCLUDE_FILES ${include})
261	ENDIF ()
262ENDMACRO ()
263
264CARES_EXTRAINCLUDE_IFSET (HAVE_STDBOOL_H      stdbool.h)
265CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_TYPES_H    sys/types.h)
266CARES_EXTRAINCLUDE_IFSET (HAVE_ARPA_INET_H    arpa/inet.h)
267CARES_EXTRAINCLUDE_IFSET (HAVE_ARPA_NAMESER_H arpa/nameser.h)
268CARES_EXTRAINCLUDE_IFSET (HAVE_NETDB_H        netdb.h)
269CARES_EXTRAINCLUDE_IFSET (HAVE_NET_IF_H       net/if.h)
270CARES_EXTRAINCLUDE_IFSET (HAVE_NETINET_IN_H   netinet/in.h)
271CARES_EXTRAINCLUDE_IFSET (HAVE_NETINET_TCP_H  netinet/tcp.h)
272CARES_EXTRAINCLUDE_IFSET (HAVE_SIGNAL_H       signal.h)
273CARES_EXTRAINCLUDE_IFSET (HAVE_STDLIB_H       stdlib.h)
274CARES_EXTRAINCLUDE_IFSET (HAVE_STRING_H       string.h)
275CARES_EXTRAINCLUDE_IFSET (HAVE_STRINGS_H      strings.h)
276CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_IOCTL_H    sys/ioctl.h)
277CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_SELECT_H   sys/select.h)
278CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_SOCKET_H   sys/socket.h)
279CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_SOCKIO_H	sys/sockio.h)
280CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_TIME_H     sys/time.h)
281CARES_EXTRAINCLUDE_IFSET (HAVE_SYS_UIO_H      sys/uio.h)
282CARES_EXTRAINCLUDE_IFSET (HAVE_TIME_H         time.h)
283CARES_EXTRAINCLUDE_IFSET (HAVE_FCNTL_H        fcntl.h)
284CARES_EXTRAINCLUDE_IFSET (HAVE_UNISTD_H       unistd.h)
285CARES_EXTRAINCLUDE_IFSET (HAVE_WINSOCK2_H     winsock2.h)
286CARES_EXTRAINCLUDE_IFSET (HAVE_WS2TCPIP_H     ws2tcpip.h)
287CARES_EXTRAINCLUDE_IFSET (HAVE_WINDOWS_H      windows.h)
288
289# Check Types
290# CHECK_TYPE_SIZE can't be used to see if a type exists because on Apple when
291# building multi-arch, it will throw an error.  So we need to wrap
292# CHECK_C_SOURCE_COMPILES for our tests.
293MACRO (CARES_TYPE_EXISTS type var)
294	SET(_CARES_C_SOURCE "
295		#include <stdio.h>
296		#include <stdlib.h>
297	")
298	FOREACH(_C_HEADER ${CMAKE_EXTRA_INCLUDE_FILES})
299		SET(_CARES_C_SOURCE "${_CARES_C_SOURCE}
300		#include <${_C_HEADER}>")
301	ENDFOREACH(_C_HEADER)
302
303	SET(_CARES_C_SOURCE "${_CARES_C_SOURCE}
304		int main() {
305			${type} var_exists;
306			(void)var_exists;
307			return 0;
308		}
309	")
310	CHECK_C_SOURCE_COMPILES ("${_CARES_C_SOURCE}" ${var})
311ENDMACRO ()
312
313CARES_TYPE_EXISTS (socklen_t                 HAVE_SOCKLEN_T)
314CARES_TYPE_EXISTS (SOCKET                    HAVE_TYPE_SOCKET)
315CARES_TYPE_EXISTS (bool                      HAVE_BOOL_T)
316CARES_TYPE_EXISTS (ssize_t                   HAVE_SSIZE_T)
317CARES_TYPE_EXISTS ("long long"               HAVE_LONGLONG)
318CARES_TYPE_EXISTS (sig_atomic_t              HAVE_SIG_ATOMIC_T)
319CARES_TYPE_EXISTS ("struct addrinfo"         HAVE_STRUCT_ADDRINFO)
320CARES_TYPE_EXISTS ("struct in6_addr"         HAVE_STRUCT_IN6_ADDR)
321CARES_TYPE_EXISTS ("struct sockaddr_in6"     HAVE_STRUCT_SOCKADDR_IN6)
322CARES_TYPE_EXISTS ("struct sockaddr_storage" HAVE_STRUCT_SOCKADDR_STORAGE)
323CARES_TYPE_EXISTS ("struct timeval"          HAVE_STRUCT_TIMEVAL)
324
325
326# Check for preprocessor defines
327CHECK_SYMBOL_EXISTS (AF_INET6        "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_AF_INET6)
328CHECK_SYMBOL_EXISTS (O_NONBLOCK      "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_O_NONBLOCK)
329CHECK_SYMBOL_EXISTS (FIONBIO         "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_FIONBIO)
330CHECK_SYMBOL_EXISTS (SIOCGIFADDR     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IOCTL_SIOCGIFADDR)
331CHECK_SYMBOL_EXISTS (MSG_NOSIGNAL    "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_MSG_NOSIGNAL)
332CHECK_SYMBOL_EXISTS (PF_INET6        "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_PF_INET6)
333CHECK_SYMBOL_EXISTS (SO_NONBLOCK     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_SO_NONBLOCK)
334
335# XCode v8 bug: iOS when targeting less than v10, or MacOS when targeting less than v10.12 will
336# say clock_gettime exists, it is a weak symbol that only exists in iOS10/MacOS10.12 and will
337# cause a crash at runtime when running on older versions.  Skip finding CLOCK_MONOTONIC on older
338# OS's.
339IF ((NOT APPLE) OR IOS_V10 OR MACOS_V1012)
340	CHECK_SYMBOL_EXISTS (CLOCK_MONOTONIC "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_CLOCK_GETTIME_MONOTONIC)
341ENDIF ()
342
343CHECK_STRUCT_HAS_MEMBER("struct sockaddr_in6" sin6_scope_id "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID LANGUAGE C)
344
345# Check for "LL" numeric suffix support
346CHECK_C_SOURCE_COMPILES ("int main() { int n=1234LL; return 0; }" HAVE_LL)
347
348
349CHECK_SYMBOL_EXISTS (bitncmp         "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_BITNCMP)
350CHECK_SYMBOL_EXISTS (closesocket     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_CLOSESOCKET)
351CHECK_SYMBOL_EXISTS (CloseSocket     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_CLOSESOCKET_CAMEL)
352CHECK_SYMBOL_EXISTS (connect         "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_CONNECT)
353CHECK_SYMBOL_EXISTS (fcntl           "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_FCNTL)
354CHECK_SYMBOL_EXISTS (freeaddrinfo    "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_FREEADDRINFO)
355CHECK_SYMBOL_EXISTS (getaddrinfo     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETADDRINFO)
356CHECK_SYMBOL_EXISTS (getenv          "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETENV)
357CHECK_SYMBOL_EXISTS (gethostbyaddr   "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETHOSTBYADDR)
358CHECK_SYMBOL_EXISTS (gethostbyname   "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETHOSTBYNAME)
359CHECK_SYMBOL_EXISTS (gethostname     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETHOSTNAME)
360CHECK_SYMBOL_EXISTS (getnameinfo     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETNAMEINFO)
361CHECK_SYMBOL_EXISTS (getservbyport_r "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETSERVBYPORT_R)
362CHECK_SYMBOL_EXISTS (getservbyname_r "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETSERVBYNAME_R)
363CHECK_SYMBOL_EXISTS (gettimeofday    "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETTIMEOFDAY)
364CHECK_SYMBOL_EXISTS (if_indextoname  "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IF_INDEXTONAME)
365CHECK_SYMBOL_EXISTS (inet_net_pton   "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_INET_NET_PTON)
366IF (NOT WIN32)
367	# Disabled on Windows, because these functions are only really supported on Windows
368	# Vista or newer (_WIN32_WINNT >= 0x0600). Older versions of Windows may provide
369	# them as experimental non-working features, so we have to disable them manually.
370	CHECK_SYMBOL_EXISTS (inet_ntop       "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_INET_NTOP)
371	CHECK_SYMBOL_EXISTS (inet_pton       "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_INET_PTON)
372ENDIF ()
373CHECK_SYMBOL_EXISTS (ioctl           "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IOCTL)
374CHECK_SYMBOL_EXISTS (ioctlsocket     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IOCTLSOCKET)
375CHECK_SYMBOL_EXISTS (IoctlSocket     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IOCTLSOCKET_CAMEL)
376CHECK_SYMBOL_EXISTS (recv            "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_RECV)
377CHECK_SYMBOL_EXISTS (recvfrom        "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_RECVFROM)
378CHECK_SYMBOL_EXISTS (send            "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_SEND)
379CHECK_SYMBOL_EXISTS (setsockopt      "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_SETSOCKOPT)
380CHECK_SYMBOL_EXISTS (socket          "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_SOCKET)
381CHECK_SYMBOL_EXISTS (strcasecmp      "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRCASECMP)
382CHECK_SYMBOL_EXISTS (strcmpi         "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRCMPI)
383CHECK_SYMBOL_EXISTS (strdup          "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRDUP)
384CHECK_SYMBOL_EXISTS (stricmp         "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRICMP)
385CHECK_SYMBOL_EXISTS (strncasecmp     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRNCASECMP)
386CHECK_SYMBOL_EXISTS (strncmpi        "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRNCMPI)
387CHECK_SYMBOL_EXISTS (strnicmp        "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRNICMP)
388CHECK_SYMBOL_EXISTS (writev          "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_WRITEV)
389
390# On Android, the system headers may define __system_property_get(), but excluded
391# from libc.  We need to perform a link test instead of a header/symbol test.
392CHECK_FUNCTION_EXISTS (__system_property_get HAVE___SYSTEM_PROPERTY_GET)
393
394# Unset temporary data
395SET (CMAKE_EXTRA_INCLUDE_FILES)
396SET (CMAKE_REQUIRED_DEFINITIONS)
397SET (CMAKE_REQUIRED_LIBRARIES)
398
399
400find_file(CARES_RANDOM_FILE urandom /dev)
401mark_as_advanced(CARES_RANDOM_FILE)
402
403
404################################################################################
405# recv, recvfrom, send, getnameinfo, gethostname
406# ARGUMENTS AND RETURN VALUES
407#
408# The AutoTools build tries to be really thorough here.  So much so that it
409# takes forever.  We really don't want to do that.  Lets make some educated
410# guesses based on datatypes we have available, and for others, use some 'sane'
411# defaults.  This should be much quicker and nearly as accurate ... and even
412# if not, it probably won't matter in the least.
413
414IF (HAVE_SSIZE_T AND HAVE_SOCKLEN_T)
415	# If we have ssize_t and socklen_t, the API is usually sane and uses ssize_t and size_t for lengths
416	SET (RECVFROM_TYPE_RETV ssize_t)
417	SET (RECVFROM_TYPE_ARG3 size_t)
418ELSE ()
419	SET (RECVFROM_TYPE_RETV int)
420	SET (RECVFROM_TYPE_ARG3 int)
421ENDIF ()
422
423IF (HAVE_TYPE_SOCKET)
424	# If the SOCKET type is defined, it uses socket ... should be windows only
425	SET (RECVFROM_TYPE_ARG1 SOCKET)
426ELSE ()
427	SET (RECVFROM_TYPE_ARG1 int)
428ENDIF()
429
430IF (HAVE_SOCKLEN_T)
431	# If we have socklen_t the APIs pretty much always actually use it
432	SET (RECVFROM_TYPE_ARG6 "socklen_t *")
433	SET (GETNAMEINFO_TYPE_ARG2 socklen_t)
434	SET (GETNAMEINFO_TYPE_ARG46 socklen_t)
435ELSE ()
436	SET (RECVFROM_TYPE_ARG6 "int *")
437	SET (GETNAMEINFO_TYPE_ARG2 int)
438	SET (GETNAMEINFO_TYPE_ARG46 int)
439ENDIF ()
440
441IF (WIN32)
442	SET (RECV_TYPE_ARG2 "char *")
443ELSE ()
444	SET (RECV_TYPE_ARG2 "void *")
445ENDIF ()
446
447# Functions are typically consistent so the equivalent fields map ... equivalently
448SET (RECV_TYPE_RETV ${RECVFROM_TYPE_RETV})
449SET (SEND_TYPE_RETV ${RECVFROM_TYPE_RETV})
450SET (RECV_TYPE_ARG1 ${RECVFROM_TYPE_ARG1})
451SET (RECVFROM_TYPE_ARG2 ${RECV_TYPE_ARG2})
452SET (SEND_TYPE_ARG1 ${RECVFROM_TYPE_ARG1})
453SET (RECV_TYPE_ARG3 ${RECVFROM_TYPE_ARG3})
454SET (SEND_TYPE_ARG3 ${RECVFROM_TYPE_ARG3})
455SET (GETHOSTNAME_TYPE_ARG2 ${RECVFROM_TYPE_ARG3})
456
457# These should always be "sane" values to use always
458SET (RECVFROM_QUAL_ARG5 )
459SET (RECVFROM_TYPE_ARG4 int)
460SET (RECVFROM_TYPE_ARG5 "struct sockaddr *")
461SET (RECV_TYPE_ARG4 int)
462SET (GETNAMEINFO_TYPE_ARG1 "struct sockaddr *")
463SET (GETNAMEINFO_TYPE_ARG7 int)
464SET (SEND_TYPE_ARG2 "void *")
465SET (SEND_TYPE_ARG4 int)
466################################################################################
467
468
469# HAVE_CXX11  ??
470# HAVE_SIG_ATOMIC_T_VOLATILE  ??
471
472
473# Set a few variables by hand that C-Ares wants, logically, based on detection
474# data.
475
476IF (HAVE_SOCKLEN_T)
477	Set (CARES_TYPEOF_ARES_SOCKLEN_T "socklen_t")
478ELSE ()
479	Set (CARES_TYPEOF_ARES_SOCKLEN_T "int")
480ENDIF ()
481
482IF (HAVE_SSIZE_T)
483	Set (CARES_TYPEOF_ARES_SSIZE_T "ssize_t")
484ELSE ()
485	IF (WIN32)
486		IF ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
487			Set (CARES_TYPEOF_ARES_SSIZE_T "__int64")
488		ELSE ()
489			Set (CARES_TYPEOF_ARES_SSIZE_T "int")
490		ENDIF ()
491	ELSE ()
492		Set (CARES_TYPEOF_ARES_SSIZE_T "long")
493	ENDIF ()
494ENDIF ()
495
496IF (HAVE_FCNTL AND HAVE_O_NONBLOCK)
497	SET (HAVE_FCNTL_O_NONBLOCK 1)
498ENDIF ()
499
500IF (HAVE_IOCTL AND HAVE_FIONBIO)
501	SET (HAVE_IOCTL_FIONBIO 1)
502ENDIF ()
503
504IF (HAVE_IOCTLSOCKET AND HAVE_FIONBIO)
505	SET (HAVE_IOCTLSOCKET_FIONBIO 1)
506ENDIF ()
507
508IF (HAVE_IOCTLSOCKET_CAMEL AND HAVE_FIONBIO)
509	SET (HAVE_IOCTLSOCKET_CAMEL_FIONBIO 1)
510ENDIF ()
511
512IF (HAVE_GETADDRINFO)
513	IF (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
514		CMAKE_SYSTEM_NAME STREQUAL "HPUX" OR
515		CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR
516		CMAKE_SYSTEM_NAME STREQUAL "SunOS" OR
517		CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
518		CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
519		WIN32)
520			SET (HAVE_GETADDRINFO_THREADSAFE 1)
521	ENDIF ()
522ENDIF ()
523
524IF (HAVE_TIME_H AND HAVE_SYS_TIME_H)
525	SET (TIME_WITH_SYS_TIME 1)
526ENDIF ()
527
528IF (HAVE_GETSERVBYPORT_R)
529	# TODO : Should probably autodetect
530	IF (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
531		SET (GETSERVBYPORT_R_ARGS 5)
532	ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
533		CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
534		HAIKU)
535		SET (GETSERVBYPORT_R_ARGS 4)
536	ELSE ()
537		# Probably linux
538		SET (GETSERVBYPORT_R_ARGS 6)
539	ENDIF ()
540ENDIF ()
541
542IF (HAVE_GETSERVBYNAME_R)
543	# TODO : Should probably autodetect
544	IF (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
545		SET (GETSERVBYNAME_R_ARGS 5)
546	ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
547		CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
548		HAIKU)
549		SET (GETSERVBYNAME_R_ARGS 4)
550	ELSE ()
551		# Probably linux
552		SET (GETSERVBYNAME_R_ARGS 6)
553	ENDIF ()
554ENDIF ()
555
556# Set some aliases used for ares_build.h
557IF (HAVE_SYS_TYPES_H)
558	SET (CARES_HAVE_SYS_TYPES_H 1)
559ENDIF ()
560IF (HAVE_SYS_SOCKET_H)
561	SET (CARES_HAVE_SYS_SOCKET_H 1)
562ENDIF()
563IF (HAVE_WS2TCPIP_H)
564	SET (CARES_HAVE_WS2TCPIP_H 1)
565ENDIF()
566IF (HAVE_WINSOCK2_H)
567	SET (CARES_HAVE_WINSOCK2_H 1)
568ENDIF()
569IF (HAVE_WINDOWS_H)
570	SET (CARES_HAVE_WINDOWS_H 1)
571ENDIF()
572IF (HAVE_ARPA_NAMESER_H)
573	SET (CARES_HAVE_ARPA_NAMESER_H 1)
574ENDIF()
575IF (HAVE_ARPA_NAMESER_COMPAT_H)
576	SET (CARES_HAVE_ARPA_NAMESER_COMPAT_H 1)
577ENDIF()
578
579# Record toplevel CMakeLists.txt path
580set(CARES_TOPLEVEL_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
581
582
583# TRANSFORM_MAKEFILE_INC
584#
585# This function consumes the "Makefile.inc" autotools file, and converts it into
586#  "Makefile.inc.cmake", a cmake include file; transforming this:
587#
588# CSOURCES = ares__close_sockets.c	\
589#   ares__get_hostent.c			\
590#   ares__read_line.c			\
591#   ...
592#
593#   into this:
594#
595# SET (CSOURCES
596# 	ares__close_sockets.c
597# 	ares__get_hostent.c
598# 	ares__read_line.c
599#	...
600function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
601	file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
602	string(REPLACE "$(top_srcdir)"   "\${PROJECT_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
603	string(REPLACE "$(top_builddir)" "\${PROJECT_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
604
605	string(REGEX REPLACE "\\\\\n" "ß!ß" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
606	string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
607	string(REPLACE "ß!ß" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
608
609	string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})    # Replace $() with ${}
610	string(REGEX REPLACE "@([a-zA-Z_][a-zA-Z0-9_]*)@" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})    # Replace @@ with ${}, even if that may not be read by CMake scripts.
611	file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
612endfunction()
613
614# Directory for includes
615ADD_SUBDIRECTORY (include)
616
617# Directory for lib and tools
618ADD_SUBDIRECTORY (src)
619
620# Docs
621ADD_SUBDIRECTORY (docs)
622
623# Tests
624IF (CARES_BUILD_TESTS OR CARES_BUILD_CONTAINER_TESTS)
625	ENABLE_TESTING ()
626	ADD_SUBDIRECTORY (test)
627ENDIF ()
628
629
630# Export targets
631IF (CARES_INSTALL)
632	SET (CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
633	INCLUDE (CMakePackageConfigHelpers)
634	CONFIGURE_PACKAGE_CONFIG_FILE (${PROJECT_NAME}-config.cmake.in ${PROJECT_NAME}-config.cmake
635		INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
636		PATH_VARS CMAKE_INSTALL_INCLUDEDIR
637		NO_CHECK_REQUIRED_COMPONENTS_MACRO
638	)
639
640	WRITE_BASIC_PACKAGE_VERSION_FILE(${PROJECT_NAME}-config-version.cmake VERSION "${CARES_VERSION}" COMPATIBILITY SameMajorVersion)
641	INSTALL (EXPORT ${PROJECT_NAME}-targets COMPONENT Devel DESTINATION ${CMAKECONFIG_INSTALL_DIR} NAMESPACE ${PROJECT_NAME}::)
642	INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" COMPONENT Devel DESTINATION ${CMAKECONFIG_INSTALL_DIR})
643
644	# pkgconfig support
645	IF (NOT CARES_SHARED)
646		SET (CPPFLAG_CARES_STATICLIB "-DCARES_STATICLIB")
647		FOREACH (LIB ${CARES_DEPENDENT_LIBS})
648			SET (CARES_PRIVATE_LIBS "${CARES_PRIVATE_LIBS} -l${LIB}")
649		ENDFOREACH ()
650	ENDIF ()
651	CONFIGURE_FILE("libcares.pc.cmake" "libcares.pc" @ONLY)
652	INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcares.pc" COMPONENT Devel DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
653ENDIF ()
654
655
656# Legacy chain-building variables (provided for compatibility with old code).
657# Don't use these, external code should be updated to refer to the aliases directly (e.g., Cares::cares).
658SET (CARES_FOUND 1 CACHE INTERNAL "CARES LIBRARY FOUND")
659SET (CARES_LIBRARIES ${PROJECT_NAME}::cares CACHE INTERNAL "CARES LIBRARIES")
660
661
662IF (CARES_INSTALL)
663    # Package creation
664    set( CPACK_PACKAGE_NAME ${PROJECT_NAME} )
665    set( CPACK_PACKAGE_VENDOR "Daniel Stenberg" ) # Github project owner
666    set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "A C library for asynchronous DNS requests" )
667    set( CPACK_PACKAGE_HOMEPAGE_URL "https://c-ares.org/" )
668    set( CPACK_PACKAGE_CONTACT      "https://c-ares.org/" )
669    set( CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR} )
670    set( CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR} )
671    set( CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH} )
672    set( CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} )
673    set( CPACK_PACKAGE_INSTALL_DIRECTORY ${PROJECT_NAME} )
674    set( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md" )
675    set( CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md" )
676
677    set( CPACK_COMPONENT_Library_DISPLAY_NAME "c-ares Library" )
678    set( CPACK_COMPONENT_Library_DESCRIPTION "The c-ares binary library." )
679    set( CPACK_COMPONENT_Library_REQUIRED 1 )
680    set( CPACK_COMPONENT_Devel_DISPLAY_NAME "c-ares Development Files" )
681    set( CPACK_COMPONENT_Devel_DESCRIPTION "Development files for compiling against c-ares." )
682    set( CPACK_COMPONENT_Devel_REQUIRED 0 )
683    IF (CARES_BUILD_TOOLS)
684        set( CPACK_COMPONENT_Tools_DISPLAY_NAME "c-ares Tools" )
685        set( CPACK_COMPONENT_Tools_DESCRIPTION "Tools for using c-ares." )
686        set( CPACK_COMPONENT_Tools_REQUIRED 0 )
687    ENDIF ()
688
689    if( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
690
691        if ( "${CPACK_PACKAGE_ARCHITECTURE}" STREQUAL "" )
692            # Note: the architecture should default to the local architecture, but it
693            # in fact comes up empty.  We call `uname -m` to ask the kernel instead.
694            EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE )
695        endif()
696
697        set( CPACK_INCLUDE_TOPLEVEL_DIRECTORY 1 )
698        set( CPACK_PACKAGE_RELEASE 1 )
699
700
701        # RPM - https://cmake.org/cmake/help/latest/cpack_gen/rpm.html
702        set( CPACK_RPM_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE} )
703        set( CPACK_RPM_PACKAGE_ARCHITECTURE ${CPACK_PACKAGE_ARCHITECTURE} )
704        set( CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY} )
705        set( CPACK_RPM_PACKAGE_URL ${CPACK_PACKAGE_HOMEPAGE_URL} )
706        set( CPACK_RPM_PACKAGE_LICENSE "MIT" )
707        set( CPACK_RPM_COMPONENT_INSTALL 1 )
708        set( CPACK_RPM_COMPRESSION_TYPE "xz" )
709        set( CPACK_RPM_PACKAGE_AUTOPROV 1 )
710
711        set( CPACK_RPM_Library_PACKAGE_SUMMARY ${CPACK_COMPONENT_Library_DESCRIPTION} )
712        set( CPACK_RPM_Library_PACKAGE_ARCHITECTURE ${CPACK_RPM_PACKAGE_ARCHITECTURE} )
713        set( CPACK_RPM_Library_PACKAGE_NAME "libcares${CARES_LIB_VERSION_MAJOR}" )
714        set( CPACK_RPM_Library_FILE_NAME "RPM-DEFAULT" )
715
716        set( CPACK_RPM_Devel_PACKAGE_REQUIRES "cmake >= ${CMAKE_MINIMUM_REQUIRED_VERSION}, ${CPACK_RPM_Library_PACKAGE_NAME} >= ${CPACK_PACKAGE_VERSION}" )
717        set( CPACK_RPM_Devel_PACKAGE_SUMMARY ${CPACK_COMPONENT_Devel_DESCRIPTION} )
718        set( CPACK_RPM_Devel_PACKAGE_ARCHITECTURE ${CPACK_RPM_PACKAGE_ARCHITECTURE} )
719        set( CPACK_RPM_Devel_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-devel" )
720        set( CPACK_RPM_Devel_FILE_NAME "RPM-DEFAULT" )
721
722        IF (CARES_BUILD_TOOLS)
723            set( CPACK_RPM_Tools_PACKAGE_REQUIRES "${CPACK_RPM_Library_PACKAGE_NAME} >= ${CPACK_PACKAGE_VERSION}" )
724            set( CPACK_RPM_Tools_PACKAGE_SUMMARY ${CPACK_COMPONENT_Tools_DESCRIPTION} )
725            set( CPACK_RPM_Tools_PACKAGE_ARCHITECTURE ${CPACK_RPM_PACKAGE_ARCHITECTURE} )
726            set( CPACK_RPM_Tools_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-tools" )
727            set( CPACK_RPM_Tools_FILE_NAME "RPM-DEFAULT" )
728        ENDIF ()
729
730
731        # DEB - https://cmake.org/cmake/help/latest/cpack_gen/deb.html
732        set( CPACK_DEBIAN_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE} )
733        set( CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CPACK_PACKAGE_HOMEPAGE_URL} )
734        set( CPACK_DEB_COMPONENT_INSTALL 1 )
735        set( CPACK_DEBIAN_COMPRESSION_TYPE "xz")
736        set( CPACK_DEBIAN_PACKAGE_SHLIBDEPS 1 )
737
738        if ( ${CPACK_PACKAGE_ARCHITECTURE} STREQUAL "x86_64" )
739            set( CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64" )  # DEB doesn't always use the kernel's arch name
740        else()
741            set( CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CPACK_PACKAGE_ARCHITECTURE} )
742        endif()
743
744        set( CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT" ) # Use default naming scheme
745
746        set( CPACK_DEBIAN_LIBRARY_PACKAGE_NAME ${CPACK_RPM_Library_PACKAGE_NAME} )
747
748        set( CPACK_DEBIAN_DEVEL_PACKAGE_DEPENDS "cmake (>= ${CMAKE_MINIMUM_REQUIRED_VERSION}), ${CPACK_DEBIAN_LIBRARY_PACKAGE_NAME} (>= ${CPACK_PACKAGE_VERSION})" )
749        set( CPACK_DEBIAN_DEVEL_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-dev" )
750
751        IF (CARES_BUILD_TOOLS)
752            set( CPACK_DEBIAN_TOOLS_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-tools" )
753            set( CPACK_DEBIAN_TOOLS_PACKAGE_SHLIBDEPS OFF ) # dpkg-shlibdeps can't find the libs we built
754            set( CPACK_DEBIAN_TOOLS_PACKAGE_DEPENDS "${CPACK_DEBIAN_LIBRARY_PACKAGE_NAME} (>= ${CPACK_PACKAGE_VERSION})" )
755        ENDIF ()
756
757    elseif( ${CMAKE_HOST_WIN32} )
758        set( CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON )
759        set( CPACK_NSIS_DISPLAY_NAME ${PROJECT_NAME} )
760        set( CPACK_NSIS_PACKAGE_NAME ${PROJECT_NAME} )
761        set( CPACK_NSIS_URL_INFO_ABOUT ${CPACK_PACKAGE_HOMEPAGE_URL} )
762    endif()
763
764    # This must always be last!
765    include( CPack )
766ENDIF ()
767