5 CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR)
6 SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake")
7 if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
8 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${libarchive_BINARY_DIR}/bin)
12 # Version - read from 'version' file.
14 FILE(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/build/version _version)
16 "^([0-9])[0-9][0-9][0-9][0-9][0-9][0-9][a-z]?$" "\\1" _major ${_version})
18 "^[0-9]([0-9][0-9][0-9])[0-9][0-9][0-9][a-z]?$" "\\1" _minor ${_version})
20 "^[0-9][0-9][0-9][0-9]([0-9][0-9][0-9])[a-z]?$" "\\1" _revision ${_version})
22 "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9]([a-z]?)$" "\\1" _quality ${_version})
23 SET(_version_number ${_major}${_minor}${_revision})
24 STRING(REGEX REPLACE "[0]*([^0][0-9]*)$" "\\1" _minor ${_minor})
25 STRING(REGEX REPLACE "[0]*([^0][0-9]*)$" "\\1" _revision ${_revision})
27 SET(VERSION "${_major}.${_minor}.${_revision}${_quality}")
28 SET(BSDCPIO_VERSION_STRING "${VERSION}")
29 SET(BSDTAR_VERSION_STRING "${VERSION}")
30 SET(LIBARCHIVE_VERSION_NUMBER "${_version_number}")
31 SET(LIBARCHIVE_VERSION_STRING "${VERSION}")
32 # Shared library number
35 # Enable CTest/CDash support
38 # Provide ADD_TEST_28 macro to approximate CMake 2.8 ADD_TEST(NAME).
39 # TODO: Require CMake 2.8 and drop this workaround (perhaps late 2010).
42 OPTION(ENABLE_OPENSSL "Enable use of OpenSSL" ON)
43 OPTION(ENABLE_TAR "Enable tar building" ON)
44 OPTION(ENABLE_TAR_SHARED "Enable dynamic build of tar" OFF)
45 OPTION(ENABLE_CPIO "Enable cpio building" ON)
46 OPTION(ENABLE_CPIO_SHARED "Enable dynamic build of cpio" OFF)
47 OPTION(ENABLE_XATTR "Enable extended attribute support" ON)
48 OPTION(ENABLE_ACL "Enable ACL support" ON)
49 OPTION(ENABLE_TEST "Enable unit and regression tests" ON)
54 IF(WIN32 AND NOT CYGWIN)
55 # Currently, dynamic build only.
56 SET(ENABLE_TAR_SHARED ON)
57 SET(ENABLE_CPIO_SHARED ON)
58 ENDIF(WIN32 AND NOT CYGWIN)
61 SET(_WIN32_WINNT 0x0500 CACHE INTERNAL "Setting _WIN32_WINNT to 0x0500 for Windows 2000 APIs")
62 SET(WINVER 0x0500 CACHE INTERNAL "Setting WINVER to 0x0500 for Windows 2000 APIs")
66 INCLUDE(CheckCSourceRuns)
67 INCLUDE(CheckFileOffsetBits)
69 INCLUDE(CheckHeaderDirent)
70 INCLUDE(CheckIncludeFile)
71 INCLUDE(CheckIncludeFiles)
72 INCLUDE(CheckLibraryExists)
73 INCLUDE(CheckStructMember)
74 INCLUDE(CheckSymbolExists)
75 INCLUDE(CheckTypeExists)
76 INCLUDE(CheckTypeSize)
81 MACRO (GENERATE_LIST_H _listfile _cmlist __list_sources)
83 # Remove _listfile and _cmlist from _argv
84 LIST(REMOVE_AT _argv 0 1)
85 IF (NOT EXISTS "${_listfile}" OR
86 ${_cmlist} IS_NEWER_THAN "${_listfile}")
88 MESSAGE(STATUS "Generating ${_listfile}")
89 FILE(WRITE ${_listfile} "")
90 FOREACH (testfile ${_argv})
91 IF (testfile MATCHES "^test_[^/]+[.]c$")
92 FILE(STRINGS ${testfile} testvar REGEX "^DEFINE_TEST")
93 FOREACH (deftest ${testvar})
94 FILE(APPEND ${_listfile} "${deftest}\n")
96 ENDIF (testfile MATCHES "^test_[^/]+[.]c$")
99 ENDIF (NOT EXISTS "${_listfile}" OR
100 ${_cmlist} IS_NEWER_THAN "${_listfile}")
101 ENDMACRO (GENERATE_LIST_H)
103 # Generate installation rules for man pages.
105 MACRO (INSTALL_MAN __mans)
106 FOREACH (_man ${ARGV})
107 STRING(REGEX REPLACE "^.+[.]([1-9])" "\\1" _mansect ${_man})
108 INSTALL(FILES ${_man} DESTINATION "share/man/man${_mansect}")
110 ENDMACRO (INSTALL_MAN __mans)
113 # Check compress/decompress libraries
115 IF(WIN32 AND NOT CMAKE_CL_64 AND NOT CYGWIN)
116 # GnuWin32 is only for Win32, not Win64.
117 SET(__GNUWIN32PATH "C:/Program Files/GnuWin32")
118 ENDIF(WIN32 AND NOT CMAKE_CL_64 AND NOT CYGWIN)
119 IF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}")
120 # You have to add a path availabel DLL file into PATH environment variable.
121 # Maybe DLL path is "C:/Program Files/GnuWin32/bin".
122 # The zlib and the bzip2 Setup program have installed programs and DLLs into
123 # "C:/Program Files/GnuWin32" by default.
124 # This is convenience setting for Windows.
125 SET(CMAKE_PREFIX_PATH ${__GNUWIN32PATH} $(CMAKE_PREFIX_PATH))
127 # If you didn't use Setup program or installed into nonstandard path,
128 # cmake cannot find out your zlib or bzip2 libraries and include files,
129 # you should execute cmake with -DCMAKE_PREFIX_PATH option.
131 # cmake -DCMAKE_PREFIX_PATH=<your-GnuWin32-path> <path-to-source>
133 # If compiling error occured in zconf.h, You may need patch to zconf.h.
134 #--- zconf.h.orig 2005-07-21 00:40:26.000000000
135 #+++ zconf.h 2009-01-19 11:39:10.093750000
138 # #if 1 /* HAVE_UNISTD_H -- this line is updated by ./configure */
139 # # include <sys/types.h> /* for off_t */
140 #-# include <unistd.h> /* for SEEK_* and off_t */
141 #+# include <stdio.h> /* for SEEK_* and off_t */
143 # # include <unixio.h> /* for off_t */
145 ENDIF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}")
147 SET(ADDITIONAL_LIBS "")
155 INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
156 LIST(APPEND ADDITIONAL_LIBS ${ZLIB_LIBRARIES})
158 MARK_AS_ADVANCED(CLEAR ZLIB_INCLUDE_DIR)
159 MARK_AS_ADVANCED(CLEAR ZLIB_LIBRARY)
167 INCLUDE_DIRECTORIES(${BZIP2_INCLUDE_DIR})
168 LIST(APPEND ADDITIONAL_LIBS ${BZIP2_LIBRARIES})
170 MARK_AS_ADVANCED(CLEAR BZIP2_INCLUDE_DIR)
171 MARK_AS_ADVANCED(CLEAR BZIP2_LIBRARY)
179 INCLUDE_DIRECTORIES(${LZMA_INCLUDE_DIR})
180 LIST(APPEND ADDITIONAL_LIBS ${LZMA_LIBRARIES})
181 MARK_AS_ADVANCED(CLEAR LZMA_INCLUDE_DIR)
182 MARK_AS_ADVANCED(CLEAR LZMA_LIBRARY)
183 ELSEIF(LZMADEC_FOUND)
184 SET(HAVE_LIBLZMADEC 1)
185 SET(HAVE_LZMADEC_H 1)
186 INCLUDE_DIRECTORIES(${LZMADEC_INCLUDE_DIR})
187 LIST(APPEND ADDITIONAL_LIBS ${LZMADEC_LIBRARIES})
188 MARK_AS_ADVANCED(CLEAR LZMADEC_INCLUDE_DIR)
189 MARK_AS_ADVANCED(CLEAR LZMADEC_LIBRARY)
191 MARK_AS_ADVANCED(CLEAR LZMA_INCLUDE_DIR)
192 MARK_AS_ADVANCED(CLEAR LZMA_LIBRARY)
198 CHECK_HEADER_DIRENT()
201 MACRO (LA_CHECK_INCLUDE_FILE header var)
202 CHECK_INCLUDE_FILES("${INCLUDES};${header}" ${var})
204 SET(INCLUDES ${INCLUDES} ${header})
206 ENDMACRO (LA_CHECK_INCLUDE_FILE)
208 # Few headers that must precede other headers
209 # Must precede sys/extattr.h on FreeBSD
210 LA_CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
212 # Alphabetize the rest unless there's a compelling reason
213 LA_CHECK_INCLUDE_FILE("acl/libacl.h" HAVE_ACL_LIBACL_H)
214 LA_CHECK_INCLUDE_FILE("attr/xattr.h" HAVE_ATTR_XATTR_H)
215 LA_CHECK_INCLUDE_FILE("ctype.h" HAVE_CTYPE_H)
216 LA_CHECK_INCLUDE_FILE("direct.h" HAVE_DIRECT_H)
217 LA_CHECK_INCLUDE_FILE("dlfcn.h" HAVE_DLFCN_H)
218 LA_CHECK_INCLUDE_FILE("errno.h" HAVE_ERRNO_H)
219 LA_CHECK_INCLUDE_FILE("ext2fs/ext2_fs.h" HAVE_EXT2FS_EXT2_FS_H)
220 LA_CHECK_INCLUDE_FILE("fcntl.h" HAVE_FCNTL_H)
221 LA_CHECK_INCLUDE_FILE("grp.h" HAVE_GRP_H)
222 LA_CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
223 LA_CHECK_INCLUDE_FILE("io.h" HAVE_IO_H)
224 LA_CHECK_INCLUDE_FILE("langinfo.h" HAVE_LANGINFO_H)
225 LA_CHECK_INCLUDE_FILE("limits.h" HAVE_LIMITS_H)
226 LA_CHECK_INCLUDE_FILE("linux/fs.h" HAVE_LINUX_FS_H)
227 LA_CHECK_INCLUDE_FILE("locale.h" HAVE_LOCALE_H)
228 LA_CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H)
229 LA_CHECK_INCLUDE_FILE("paths.h" HAVE_PATHS_H)
230 LA_CHECK_INCLUDE_FILE("poll.h" HAVE_POLL_H)
231 LA_CHECK_INCLUDE_FILE("process.h" HAVE_PROCESS_H)
232 LA_CHECK_INCLUDE_FILE("pwd.h" HAVE_PWD_H)
233 LA_CHECK_INCLUDE_FILE("regex.h" HAVE_REGEX_H)
234 LA_CHECK_INCLUDE_FILE("signal.h" HAVE_SIGNAL_H)
235 LA_CHECK_INCLUDE_FILE("stdarg.h" HAVE_STDARG_H)
236 LA_CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)
237 LA_CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H)
238 LA_CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
239 LA_CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
240 LA_CHECK_INCLUDE_FILE("sys/acl.h" HAVE_SYS_ACL_H)
241 LA_CHECK_INCLUDE_FILE("sys/cdefs.h" HAVE_SYS_CDEFS_H)
242 LA_CHECK_INCLUDE_FILE("sys/extattr.h" HAVE_SYS_EXTATTR_H)
243 LA_CHECK_INCLUDE_FILE("sys/ioctl.h" HAVE_SYS_IOCTL_H)
244 LA_CHECK_INCLUDE_FILE("sys/mkdev.h" HAVE_SYS_MKDEV_H)
245 LA_CHECK_INCLUDE_FILE("sys/param.h" HAVE_SYS_PARAM_H)
246 LA_CHECK_INCLUDE_FILE("sys/poll.h" HAVE_SYS_POLL_H)
247 LA_CHECK_INCLUDE_FILE("sys/select.h" HAVE_SYS_SELECT_H)
248 LA_CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
249 LA_CHECK_INCLUDE_FILE("sys/time.h" HAVE_SYS_TIME_H)
250 LA_CHECK_INCLUDE_FILE("sys/utime.h" HAVE_SYS_UTIME_H)
251 LA_CHECK_INCLUDE_FILE("sys/wait.h" HAVE_SYS_WAIT_H)
252 LA_CHECK_INCLUDE_FILE("time.h" HAVE_TIME_H)
253 LA_CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
254 LA_CHECK_INCLUDE_FILE("utime.h" HAVE_UTIME_H)
255 LA_CHECK_INCLUDE_FILE("wchar.h" HAVE_WCHAR_H)
256 LA_CHECK_INCLUDE_FILE("wctype.h" HAVE_WCTYPE_H)
257 LA_CHECK_INCLUDE_FILE("windows.h" HAVE_WINDOWS_H)
261 # Some headers require extra includes when they're available.
268 FIND_PACKAGE(OpenSSL)
273 INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
274 LIST(APPEND ADDITIONAL_LIBS ${OPENSSL_LIBRARIES})
276 # Block OpenSSL checks and override cached results.
277 SET(HAVE_OPENSSL_MD5_H 0)
278 SET(HAVE_OPENSSL_RIPEMD_H 0)
279 SET(HAVE_OPENSSL_SHA_H 0)
280 SET(HAVE_OPENSSL_SHA256_INIT 0)
281 SET(HAVE_OPENSSL_SHA384_INIT 0)
282 SET(HAVE_OPENSSL_SHA512_INIT 0)
285 # Check MD5/RMD160/SHA headers
287 LA_CHECK_INCLUDE_FILE("md5.h" HAVE_MD5_H)
288 LA_CHECK_INCLUDE_FILE("openssl/md5.h" HAVE_OPENSSL_MD5_H)
289 LA_CHECK_INCLUDE_FILE("openssl/ripemd.h" HAVE_OPENSSL_RIPEMD_H)
290 LA_CHECK_INCLUDE_FILE("openssl/sha.h" HAVE_OPENSSL_SHA_H)
291 LA_CHECK_INCLUDE_FILE("ripemd.h" HAVE_RIPEMD_H)
292 LA_CHECK_INCLUDE_FILE("rmd160.h" HAVE_RMD160_H)
293 LA_CHECK_INCLUDE_FILE("sha.h" HAVE_SHA_H)
294 LA_CHECK_INCLUDE_FILE("sha1.h" HAVE_SHA1_H)
295 LA_CHECK_INCLUDE_FILE("sha2.h" HAVE_SHA2_H)
296 LA_CHECK_INCLUDE_FILE("sha256.h" HAVE_SHA256_H)
299 # Find MD5/RMD160/SHA library
301 FIND_LIBRARY(CRYPTO_LIBRARY NAMES crypto)
303 LIST(APPEND ADDITIONAL_LIBS ${CRYPTO_LIBRARY})
305 IF(NOT OPENSSL_FOUND)
306 FIND_LIBRARY(MD_LIBRARY NAMES md)
308 LIST(APPEND ADDITIONAL_LIBS ${MD_LIBRARY})
310 ENDIF(NOT OPENSSL_FOUND)
311 ENDIF(CRYPTO_LIBRARY)
313 # Check MD5/RMD160/SHA functions
315 SET(CMAKE_REQUIRED_LIBRARIES ${ADDITIONAL_LIBS})
317 CHECK_SYMBOL_EXISTS(MD5Init "md5.h" HAVE_MD5INIT)
320 CHECK_SYMBOL_EXISTS(RMD160Init "rmd160.h" HAVE_RMD160INIT)
323 CHECK_SYMBOL_EXISTS(SHA256Init "sha2.h" HAVE_SHA256INIT)
324 CHECK_SYMBOL_EXISTS(SHA384Init "sha2.h" HAVE_SHA384INIT)
325 CHECK_SYMBOL_EXISTS(SHA512Init "sha2.h" HAVE_SHA512INIT)
326 CHECK_SYMBOL_EXISTS(SHA256_Init "sha2.h" HAVE_SHA256_INIT)
327 CHECK_SYMBOL_EXISTS(SHA384_Init "sha2.h" HAVE_SHA384_INIT)
328 CHECK_SYMBOL_EXISTS(SHA512_Init "sha2.h" HAVE_SHA512_INIT)
329 ELSEIF(HAVE_OPENSSL_SHA_H)
330 CHECK_SYMBOL_EXISTS(SHA256_Init "openssl/sha.h" HAVE_OPENSSL_SHA256_INIT)
331 CHECK_SYMBOL_EXISTS(SHA384_Init "openssl/sha.h" HAVE_OPENSSL_SHA384_INIT)
332 CHECK_SYMBOL_EXISTS(SHA512_Init "openssl/sha.h" HAVE_OPENSSL_SHA512_INIT)
334 SET(CMAKE_REQUIRED_LIBRARIES "")
339 FIND_PACKAGE(LibXml2)
341 INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
342 LIST(APPEND ADDITIONAL_LIBS ${LIBXML2_LIBRARIES})
344 # libxml2's include files use iconv.h
345 # We need a directory path of iconv.h so that it won't fail to check
346 # "libxml/xmlreader.h".
347 FIND_PATH(ICONV_INCLUDE_DIR iconv.h)
348 INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR})
349 SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR})
350 CHECK_INCLUDE_FILES("libxml/xmlreader.h" HAVE_LIBXML_XMLREADER_H)
351 SET(CMAKE_REQUIRED_INCLUDES "")
358 INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR})
359 LIST(APPEND ADDITIONAL_LIBS ${EXPAT_LIBRARIES})
361 LA_CHECK_INCLUDE_FILE("expat.h" HAVE_EXPAT_H)
368 CHECK_SYMBOL_EXISTS(CreateHardLinkA "windows.h" HAVE_CREATEHARDLINKA)
369 CHECK_SYMBOL_EXISTS(CreateHardLinkW "windows.h" HAVE_CREATEHARDLINKW)
370 CHECK_SYMBOL_EXISTS(_CrtSetReportMode "crtdbg.h" HAVE__CrtSetReportMode)
371 CHECK_FUNCTION_EXISTS_GLIBC(chflags HAVE_CHFLAGS)
372 CHECK_FUNCTION_EXISTS_GLIBC(chown HAVE_CHOWN)
373 CHECK_FUNCTION_EXISTS_GLIBC(chroot HAVE_CHROOT)
374 CHECK_FUNCTION_EXISTS_GLIBC(fchdir HAVE_FCHDIR)
375 CHECK_FUNCTION_EXISTS_GLIBC(fchflags HAVE_FCHFLAGS)
376 CHECK_FUNCTION_EXISTS_GLIBC(fchmod HAVE_FCHMOD)
377 CHECK_FUNCTION_EXISTS_GLIBC(fchown HAVE_FCHOWN)
378 CHECK_FUNCTION_EXISTS_GLIBC(fcntl HAVE_FCNTL)
379 CHECK_FUNCTION_EXISTS_GLIBC(fork HAVE_FORK)
380 CHECK_FUNCTION_EXISTS_GLIBC(fstat HAVE_FSTAT)
381 CHECK_FUNCTION_EXISTS_GLIBC(ftruncate HAVE_FTRUNCATE)
382 CHECK_FUNCTION_EXISTS_GLIBC(futimens HAVE_FUTIMENS)
383 CHECK_FUNCTION_EXISTS_GLIBC(futimes HAVE_FUTIMES)
384 CHECK_FUNCTION_EXISTS_GLIBC(geteuid HAVE_GETEUID)
385 CHECK_FUNCTION_EXISTS_GLIBC(getpid HAVE_GETPID)
386 CHECK_FUNCTION_EXISTS_GLIBC(lchflags HAVE_LCHFLAGS)
387 CHECK_FUNCTION_EXISTS_GLIBC(lchmod HAVE_LCHMOD)
388 CHECK_FUNCTION_EXISTS_GLIBC(lchown HAVE_LCHOWN)
389 CHECK_FUNCTION_EXISTS_GLIBC(link HAVE_LINK)
390 CHECK_FUNCTION_EXISTS_GLIBC(lstat HAVE_LSTAT)
391 CHECK_FUNCTION_EXISTS_GLIBC(lutimes HAVE_LUTIMES)
392 CHECK_FUNCTION_EXISTS_GLIBC(memmove HAVE_MEMMOVE)
393 CHECK_FUNCTION_EXISTS_GLIBC(mkdir HAVE_MKDIR)
394 CHECK_FUNCTION_EXISTS_GLIBC(mkfifo HAVE_MKFIFO)
395 CHECK_FUNCTION_EXISTS_GLIBC(mknod HAVE_MKNOD)
396 CHECK_FUNCTION_EXISTS_GLIBC(nl_langinfo HAVE_NL_LANGINFO)
397 CHECK_FUNCTION_EXISTS_GLIBC(pipe HAVE_PIPE)
398 CHECK_FUNCTION_EXISTS_GLIBC(poll HAVE_POLL)
399 CHECK_FUNCTION_EXISTS_GLIBC(readlink HAVE_READLINK)
400 CHECK_FUNCTION_EXISTS_GLIBC(select HAVE_SELECT)
401 CHECK_FUNCTION_EXISTS_GLIBC(setenv HAVE_SETENV)
402 CHECK_FUNCTION_EXISTS_GLIBC(setlocale HAVE_SETLOCALE)
403 CHECK_FUNCTION_EXISTS_GLIBC(sigaction HAVE_SIGACTION)
404 CHECK_FUNCTION_EXISTS_GLIBC(strchr HAVE_STRCHR)
405 CHECK_FUNCTION_EXISTS_GLIBC(strdup HAVE_STRDUP)
406 CHECK_FUNCTION_EXISTS_GLIBC(strerror HAVE_STRERROR)
407 CHECK_FUNCTION_EXISTS_GLIBC(strncpy_s HAVE_STRNCPY_S)
408 CHECK_FUNCTION_EXISTS_GLIBC(strrchr HAVE_STRRCHR)
409 CHECK_FUNCTION_EXISTS_GLIBC(symlink HAVE_SYMLINK)
410 CHECK_FUNCTION_EXISTS_GLIBC(timegm HAVE_TIMEGM)
411 CHECK_FUNCTION_EXISTS_GLIBC(tzset HAVE_TZSET)
412 CHECK_FUNCTION_EXISTS_GLIBC(unsetenv HAVE_UNSETENV)
413 CHECK_FUNCTION_EXISTS_GLIBC(utime HAVE_UTIME)
414 CHECK_FUNCTION_EXISTS_GLIBC(utimes HAVE_UTIMES)
415 CHECK_FUNCTION_EXISTS_GLIBC(utimensat HAVE_UTIMENSAT)
416 CHECK_FUNCTION_EXISTS_GLIBC(vfork HAVE_VFORK)
417 CHECK_FUNCTION_EXISTS_GLIBC(wcrtomb HAVE_WCRTOMB)
418 CHECK_FUNCTION_EXISTS_GLIBC(wcscpy HAVE_WCSCPY)
419 CHECK_FUNCTION_EXISTS_GLIBC(wcslen HAVE_WCSLEN)
420 CHECK_FUNCTION_EXISTS_GLIBC(wctomb HAVE_WCTOMB)
421 CHECK_SYMBOL_EXISTS(wmemcmp "wchar.h" HAVE_WMEMCMP)
422 CHECK_SYMBOL_EXISTS(wmemcpy "wchar.h" HAVE_WMEMCPY)
424 SET(CMAKE_REQUIRED_LIBRARIES "")
425 CHECK_SYMBOL_EXISTS(fseeko "stdio.h" HAVE_FSEEKO)
426 CHECK_SYMBOL_EXISTS(strerror_r "string.h" HAVE_STRERROR_R)
427 CHECK_SYMBOL_EXISTS(strftime "time.h" HAVE_STRFTIME)
428 CHECK_SYMBOL_EXISTS(vprintf "stdio.h" HAVE_VPRINTF)
429 CHECK_SYMBOL_EXISTS(cygwin_conv_path "sys/cygwin.h" HAVE_CYGWIN_CONV_PATH)
431 CHECK_SYMBOL_EXISTS(major "sys/mkdev.h" MAJOR_IN_MKDEV)
432 CHECK_SYMBOL_EXISTS(major "sys/sysmacros.h" MAJOR_IN_SYSMACROS)
435 SET(HAVE_DECL_STRERROR_R 1)
436 ENDIF(HAVE_STRERROR_R)
441 SET(headers "limits.h")
443 LIST(APPEND headers "stdint.h")
446 LIST(APPEND headers "inttypes.h")
447 ENDIF(HAVE_INTTYPES_H)
448 CHECK_SYMBOL_EXISTS(EFTYPE "errno.h" HAVE_EFTYPE)
449 CHECK_SYMBOL_EXISTS(EILSEQ "errno.h" HAVE_EILSEQ)
450 CHECK_SYMBOL_EXISTS(D_MD_ORDER "langinfo.h" HAVE_D_MD_ORDER)
451 CHECK_SYMBOL_EXISTS(optarg "unistd.h" HAVE_DECL_OPTARG)
452 CHECK_SYMBOL_EXISTS(optind "unistd.h" HAVE_DECL_OPTIND)
453 CHECK_SYMBOL_EXISTS(INT64_MAX "${headers}" HAVE_DECL_INT64_MAX)
454 CHECK_SYMBOL_EXISTS(INT64_MIN "${headers}" HAVE_DECL_INT64_MIN)
455 CHECK_SYMBOL_EXISTS(UINT32_MAX "${headers}" HAVE_DECL_UINT32_MAX)
456 CHECK_SYMBOL_EXISTS(UINT64_MAX "${headers}" HAVE_DECL_UINT64_MAX)
457 CHECK_SYMBOL_EXISTS(SIZE_MAX "${headers}" HAVE_DECL_SIZE_MAX)
458 CHECK_SYMBOL_EXISTS(SSIZE_MAX "limits.h" HAVE_DECL_SSIZE_MAX)
461 # Check struct members
463 # Check for birthtime in struct stat
464 CHECK_STRUCT_MEMBER("struct stat" st_birthtime
465 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BIRTHTIME)
467 # Check for high-resolution timestamps in struct stat
468 CHECK_STRUCT_MEMBER("struct stat" st_birthtimespec.tv_nsec
469 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC)
470 CHECK_STRUCT_MEMBER("struct stat" st_mtimespec.tv_nsec
471 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
472 CHECK_STRUCT_MEMBER("struct stat" st_mtim.tv_nsec
473 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
474 CHECK_STRUCT_MEMBER("struct stat" st_mtime_n
475 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIME_N)
476 CHECK_STRUCT_MEMBER("struct stat" st_umtime
477 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_UMTIME)
478 CHECK_STRUCT_MEMBER("struct stat" st_mtime_usec
479 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIME_USEC)
480 # Check for block size support in struct stat
481 CHECK_STRUCT_MEMBER("struct stat" st_blksize
482 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BLKSIZE)
483 # Check for st_flags in struct stat (BSD fflags)
484 CHECK_STRUCT_MEMBER("struct stat" st_flags
485 "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_FLAGS)
488 CHECK_STRUCT_MEMBER("struct tm" tm_sec
489 "sys/types.h;sys/time.h;time.h" TIME_WITH_SYS_TIME)
492 # Check for integer types
494 # XXX There must be a way to make this simpler <sigh> XXXX
496 CHECK_TYPE_SIZE("long long int" LONG_LONG_INT)
497 CHECK_TYPE_SIZE("unsigned long long" UNSIGNED_LONG_LONG)
498 CHECK_TYPE_SIZE("unsigned long long int" UNSIGNED_LONG_LONG_INT)
501 CHECK_TYPE_SIZE(dev_t DEV_T)
504 SET(dev_t "unsigned int")
506 ENDIF(NOT HAVE_DEV_T)
508 CHECK_TYPE_SIZE(gid_t GID_T)
513 SET(gid_t "unsigned int")
515 ENDIF(NOT HAVE_GID_T)
517 CHECK_TYPE_SIZE(id_t ID_T)
522 SET(id_t "unsigned int")
526 CHECK_TYPE_SIZE(int32_t INT32_T)
529 ENDIF(NOT HAVE_INT32_T)
531 CHECK_TYPE_SIZE(int64_t INT64_T)
536 ENDIF(NOT HAVE_INT64_T)
538 CHECK_TYPE_SIZE(intmax_t INTMAX_T)
539 IF(NOT HAVE_INTMAX_T)
540 SET(intmax_t "int64_t")
541 ENDIF(NOT HAVE_INTMAX_T)
543 CHECK_TYPE_SIZE(mode_t MODE_T)
546 SET(mode_t "unsigned short")
550 ENDIF(NOT HAVE_MODE_T)
552 CHECK_TYPE_SIZE(off_t OFF_T)
555 ENDIF(NOT HAVE_OFF_T)
557 CHECK_TYPE_SIZE(size_t SIZE_T)
559 IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
560 SET(size_t "uint64_t")
561 ELSE("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
562 SET(size_t "uint32_t")
563 ENDIF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
564 ENDIF(NOT HAVE_SIZE_T)
566 CHECK_TYPE_SIZE(ssize_t SSIZE_T)
568 IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
569 SET(ssize_t "int64_t")
570 ELSE("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
572 ENDIF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
573 ENDIF(NOT HAVE_SSIZE_T)
575 CHECK_TYPE_SIZE(uid_t UID_T)
580 SET(uid_t "unsigned int")
582 ENDIF(NOT HAVE_UID_T)
584 CHECK_TYPE_SIZE(pid_t PID_T)
589 MESSAGE(FATAL_ERROR "pid_t doesn't exist on this platform?")
591 ENDIF(NOT HAVE_PID_T)
593 CHECK_TYPE_SIZE(uint16_t UINT16_T)
594 IF(NOT HAVE_UINT16_T)
595 SET(uint16_t "unsigned short")
596 ENDIF(NOT HAVE_UINT16_T)
598 CHECK_TYPE_SIZE(uint32_t UINT32_T)
599 IF(NOT HAVE_UINT32_T)
600 SET(uint32_t "unsigned int")
601 ENDIF(NOT HAVE_UINT32_T)
603 CHECK_TYPE_SIZE(uint64_t UINT64_T)
604 IF(NOT HAVE_UINT64_T)
606 SET(uint64_t "unsigned __int64")
608 ENDIF(NOT HAVE_UINT64_T)
610 CHECK_TYPE_SIZE(uintmax_t UINTMAX_T)
611 IF(NOT HAVE_UINTMAX_T)
612 SET(uintmax_t "uint64_t")
613 ENDIF(NOT HAVE_UINTMAX_T)
615 CHECK_TYPE_SIZE(intptr_t INTPTR_T)
616 IF(NOT HAVE_INTPTR_T)
617 IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
618 SET(intptr_t "int64_t")
620 SET(intptr_t "int32_t")
622 ENDIF(NOT HAVE_INTPTR_T)
624 CHECK_TYPE_SIZE(uintptr_t UINTPTR_T)
625 IF(NOT HAVE_UINTPTR_T)
626 IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
627 SET(uintptr_t "uint64_t")
629 SET(uintptr_t "uint32_t")
631 ENDIF(NOT HAVE_UINTPTR_T)
633 CHECK_TYPE_SIZE(wchar_t SIZEOF_WCHAR_T)
634 IF(HAVE_SIZEOF_WCHAR_T)
636 ENDIF(HAVE_SIZEOF_WCHAR_T)
638 # Check if _FILE_OFFSET_BITS macro needed for large files
640 CHECK_FILE_OFFSET_BITS()
645 # Check for Extended Attribute libraries, headers, and functions
648 LA_CHECK_INCLUDE_FILE(attr/xattr.h HAVE_ATTR_XATTR_H)
649 LA_CHECK_INCLUDE_FILE(sys/xattr.h HAVE_SYS_XATTR_H)
650 CHECK_LIBRARY_EXISTS(attr "setxattr" "" HAVE_ATTR_LIB)
652 SET(CMAKE_REQUIRED_LIBRARIES "attr")
654 CHECK_FUNCTION_EXISTS_GLIBC(extattr_get_file HAVE_EXTATTR_GET_FILE)
655 CHECK_FUNCTION_EXISTS_GLIBC(extattr_list_file HAVE_EXTATTR_LIST_FILE)
656 CHECK_FUNCTION_EXISTS_GLIBC(extattr_set_fd HAVE_EXTATTR_SET_FD)
657 CHECK_FUNCTION_EXISTS_GLIBC(extattr_set_file HAVE_EXTATTR_SET_FILE)
658 CHECK_FUNCTION_EXISTS_GLIBC(fsetxattr HAVE_FSETXATTR)
659 CHECK_FUNCTION_EXISTS_GLIBC(getxattr HAVE_GETXATTR)
660 CHECK_FUNCTION_EXISTS_GLIBC(lgetxattr HAVE_LGETXATTR)
661 CHECK_FUNCTION_EXISTS_GLIBC(listxattr HAVE_LISTXATTR)
662 CHECK_FUNCTION_EXISTS_GLIBC(llistxattr HAVE_LLISTXATTR)
663 CHECK_FUNCTION_EXISTS_GLIBC(lsetxattr HAVE_LSETXATTR)
667 # Check for ACL libraries, headers, and functions
669 # The ACL support in libarchive is written against the POSIX1e draft,
670 # which was never officially approved and varies quite a bit across
671 # platforms. Worse, some systems have completely non-POSIX acl functions,
672 # which makes the following checks rather more complex than I would like.
675 CHECK_LIBRARY_EXISTS(acl "acl_get_file" "" HAVE_ACL_LIB)
677 SET(CMAKE_REQUIRED_LIBRARIES "acl")
678 FIND_LIBRARY(ACL_LIBRARY NAMES acl)
679 LIST(APPEND ADDITIONAL_LIBS ${ACL_LIBRARY})
682 CHECK_FUNCTION_EXISTS_GLIBC(acl_create_entry HAVE_ACL_CREATE_ENTRY)
683 CHECK_FUNCTION_EXISTS_GLIBC(acl_init HAVE_ACL_INIT)
684 CHECK_FUNCTION_EXISTS_GLIBC(acl_set_fd HAVE_ACL_SET_FD)
685 CHECK_FUNCTION_EXISTS_GLIBC(acl_set_fd_np HAVE_ACL_SET_FD_NP)
686 CHECK_FUNCTION_EXISTS_GLIBC(acl_set_file HAVE_ACL_SET_FILE)
687 CHECK_TYPE_EXISTS(acl_permset_t "${INCLUDES}" HAVE_ACL_PERMSET_T)
689 # The "acl_get_perm()" function was omitted from the POSIX draft.
690 # (It's a pretty obvious oversight; otherwise, there's no way to
691 # test for specific permissions in a permset.) Linux uses the obvious
692 # name, FreeBSD adds _np to mark it as "non-Posix extension."
693 # Test for both as a double-check that we really have POSIX-style ACL support.
694 CHECK_SYMBOL_EXISTS(acl_get_perm "${INCLUDES}" HAVE_ACL_GET_PERM)
695 CHECK_SYMBOL_EXISTS(acl_get_perm_np "${INCLUDES}" HAVE_ACL_GET_PERM_NP)
696 CHECK_SYMBOL_EXISTS(acl_get_link "${INCLUDES}" HAVE_ACL_GET_LINK)
697 CHECK_SYMBOL_EXISTS(acl_get_link_np "${INCLUDES}" HAVE_ACL_GET_LINK_NP)
699 # MacOS has an acl.h that isn't POSIX. It can be detected by
700 # checking for ACL_USER
701 CHECK_SYMBOL_EXISTS(ACL_USER "${INCLUDES}" HAVE_ACL_USER)
704 # Generate "config.h" from "build/cmake/config.h.in"
705 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in
706 ${CMAKE_CURRENT_BINARY_DIR}/config.h)
707 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
708 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
711 # Register installation of PDF documents.
713 IF(WIN32 AND NOT CYGWIN)
715 # On Windows platform, It's better that we install PDF documents
717 # These PDF documents are available in the release package.
719 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doc/pdf)
720 INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc/pdf
721 DESTINATION share/man
722 FILES_MATCHING PATTERN "*.pdf"
724 ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doc/pdf)
725 ENDIF(WIN32 AND NOT CYGWIN)
729 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/libarchive)
732 ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
734 # Especially for early development, we want to be a little
735 # aggressive about diagnosing build problems; this can get
736 # relaxed somewhat in final shipping versions.
737 IF ("CMAKE_C_COMPILER_ID" MATCHES "^GNU$")
738 ADD_DEFINITIONS(-Wall -Werror)
739 ENDIF ("CMAKE_C_COMPILER_ID" MATCHES "^GNU$")
742 ADD_CUSTOM_TARGET(run_all_tests)
745 add_subdirectory(libarchive)
746 add_subdirectory(tar)
747 add_subdirectory(cpio)