Imported Upstream version 2.8.3
[platform/upstream/libarchive.git] / CMakeLists.txt
1 #
2 #
3 PROJECT(libarchive C)
4 #
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)
9 endif()
10
11 #
12 # Version - read from 'version' file.
13 #
14 FILE(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/build/version _version)
15 STRING(REGEX REPLACE
16  "^([0-9])[0-9][0-9][0-9][0-9][0-9][0-9][a-z]?$" "\\1" _major ${_version})
17 STRING(REGEX REPLACE
18  "^[0-9]([0-9][0-9][0-9])[0-9][0-9][0-9][a-z]?$" "\\1" _minor ${_version})
19 STRING(REGEX REPLACE
20  "^[0-9][0-9][0-9][0-9]([0-9][0-9][0-9])[a-z]?$" "\\1" _revision ${_version})
21 STRING(REGEX REPLACE
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})
26 #
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
33 SET(SOVERSION                   8)
34
35 # Enable CTest/CDash support
36 include(CTest)
37
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).
40 INCLUDE(AddTest28)
41
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)
50
51 IF(ENABLE_TEST)
52         ENABLE_TESTING()
53 ENDIF(ENABLE_TEST)
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)
59
60 IF(WIN32)
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")
63 ENDIF(WIN32)
64
65 #
66 INCLUDE(CheckCSourceRuns)
67 INCLUDE(CheckFileOffsetBits)
68 INCLUDE(CheckFuncs)
69 INCLUDE(CheckHeaderDirent)
70 INCLUDE(CheckIncludeFile)
71 INCLUDE(CheckIncludeFiles)
72 INCLUDE(CheckLibraryExists)
73 INCLUDE(CheckStructMember)
74 INCLUDE(CheckSymbolExists)
75 INCLUDE(CheckTypeExists)
76 INCLUDE(CheckTypeSize)
77
78 #
79 # Generate list.h
80 #
81 MACRO (GENERATE_LIST_H _listfile _cmlist __list_sources)
82   SET(_argv ${ARGV})
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}")
87
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")
95         ENDFOREACH (deftest)
96       ENDIF (testfile MATCHES "^test_[^/]+[.]c$")
97     ENDFOREACH (testfile)
98
99   ENDIF (NOT EXISTS "${_listfile}" OR
100      ${_cmlist} IS_NEWER_THAN "${_listfile}")
101 ENDMACRO (GENERATE_LIST_H)
102 #
103 # Generate installation rules for man pages.
104 #
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}")
109   ENDFOREACH (_man)
110 ENDMACRO (INSTALL_MAN __mans)
111
112 #
113 # Check compress/decompress libraries
114 #
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))
126   #
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.
130   #   e.g.
131   #     cmake -DCMAKE_PREFIX_PATH=<your-GnuWin32-path> <path-to-source>
132   #
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
136   #@@ -286,7 +286,7 @@
137   # 
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 */
142   # #  ifdef VMS
143   # #    include <unixio.h>   /* for off_t */
144   # #  endif
145 ENDIF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}")
146
147 SET(ADDITIONAL_LIBS "")
148 #
149 # Find ZLIB
150 #
151 FIND_PACKAGE(ZLIB)
152 IF(ZLIB_FOUND)
153   SET(HAVE_LIBZ 1)
154   SET(HAVE_ZLIB_H 1)
155   INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
156   LIST(APPEND ADDITIONAL_LIBS ${ZLIB_LIBRARIES})
157 ENDIF(ZLIB_FOUND)
158 MARK_AS_ADVANCED(CLEAR ZLIB_INCLUDE_DIR)
159 MARK_AS_ADVANCED(CLEAR ZLIB_LIBRARY)
160 #
161 # Find BZip2
162 #
163 FIND_PACKAGE(BZip2)
164 IF(BZIP2_FOUND)
165   SET(HAVE_LIBBZ2 1)
166   SET(HAVE_BZLIB_H 1)
167   INCLUDE_DIRECTORIES(${BZIP2_INCLUDE_DIR})
168   LIST(APPEND ADDITIONAL_LIBS ${BZIP2_LIBRARIES})
169 ENDIF(BZIP2_FOUND)
170 MARK_AS_ADVANCED(CLEAR BZIP2_INCLUDE_DIR)
171 MARK_AS_ADVANCED(CLEAR BZIP2_LIBRARY)
172 #
173 # Find LZMA
174 #
175 FIND_PACKAGE(LZMA)
176 IF(LZMA_FOUND)
177   SET(HAVE_LIBLZMA 1)
178   SET(HAVE_LZMA_H 1)
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)
190 ELSE(LZMA_FOUND)
191   MARK_AS_ADVANCED(CLEAR LZMA_INCLUDE_DIR)
192   MARK_AS_ADVANCED(CLEAR LZMA_LIBRARY)
193 ENDIF(LZMA_FOUND)
194
195 #
196 # Check headers
197 #
198 CHECK_HEADER_DIRENT()
199
200 SET(INCLUDES "")
201 MACRO (LA_CHECK_INCLUDE_FILE header var)
202       CHECK_INCLUDE_FILES("${INCLUDES};${header}" ${var})
203       IF (${var})
204          SET(INCLUDES ${INCLUDES} ${header})
205       ENDIF (${var})
206 ENDMACRO (LA_CHECK_INCLUDE_FILE)
207
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)
211
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)
258
259
260 #
261 # Some headers require extra includes when they're available.
262 #
263
264 #
265 # Find OpenSSL
266 #
267 IF(ENABLE_OPENSSL)
268   FIND_PACKAGE(OpenSSL)
269 ELSE()
270   SET(OPENSSL_FOUND 0)
271 ENDIF()
272 IF(OPENSSL_FOUND)
273   INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
274   LIST(APPEND ADDITIONAL_LIBS ${OPENSSL_LIBRARIES})
275 ELSE()
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)
283 ENDIF()
284 #
285 # Check MD5/RMD160/SHA headers
286 #
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)
297
298 #
299 # Find MD5/RMD160/SHA library
300 #
301 FIND_LIBRARY(CRYPTO_LIBRARY NAMES crypto)
302 IF(CRYPTO_LIBRARY)
303   LIST(APPEND ADDITIONAL_LIBS ${CRYPTO_LIBRARY})
304 ELSE(CRYPTO_LIBRARY)
305   IF(NOT OPENSSL_FOUND)
306     FIND_LIBRARY(MD_LIBRARY NAMES md)
307     IF(MD_LIBRARY)
308       LIST(APPEND ADDITIONAL_LIBS ${MD_LIBRARY})
309     ENDIF(MD_LIBRARY)
310   ENDIF(NOT OPENSSL_FOUND)
311 ENDIF(CRYPTO_LIBRARY)
312 #
313 # Check MD5/RMD160/SHA functions
314 #
315 SET(CMAKE_REQUIRED_LIBRARIES ${ADDITIONAL_LIBS})
316 IF(HAVE_MD5_H)
317   CHECK_SYMBOL_EXISTS(MD5Init                   "md5.h"         HAVE_MD5INIT)
318 ENDIF(HAVE_MD5_H)
319 IF(HAVE_RMD160_H)
320   CHECK_SYMBOL_EXISTS(RMD160Init                "rmd160.h"      HAVE_RMD160INIT)
321 ENDIF(HAVE_RMD160_H)
322 IF(HAVE_SHA2_H)
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)
333 ENDIF()
334 SET(CMAKE_REQUIRED_LIBRARIES "")
335
336 #
337 # Find Libxml2
338 #
339 FIND_PACKAGE(LibXml2)
340 IF(LIBXML2_FOUND)
341   INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
342   LIST(APPEND ADDITIONAL_LIBS ${LIBXML2_LIBRARIES})
343   SET(HAVE_LIBXML2 1)
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 "")
352 ELSE(LIBXML2_FOUND)
353   #
354   # Find Expat
355   #
356   FIND_PACKAGE(EXPAT)
357   IF(EXPAT_FOUND)
358     INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR})
359     LIST(APPEND ADDITIONAL_LIBS ${EXPAT_LIBRARIES})
360     SET(HAVE_LIBEXPAT 1)
361     LA_CHECK_INCLUDE_FILE("expat.h" HAVE_EXPAT_H)
362   ENDIF(EXPAT_FOUND)
363 ENDIF(LIBXML2_FOUND)
364
365 #
366 # Check functions
367 #
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)
423
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)
430
431 CHECK_SYMBOL_EXISTS(major            "sys/mkdev.h"     MAJOR_IN_MKDEV)
432 CHECK_SYMBOL_EXISTS(major            "sys/sysmacros.h" MAJOR_IN_SYSMACROS)
433
434 IF(HAVE_STRERROR_R)
435   SET(HAVE_DECL_STRERROR_R 1)
436 ENDIF(HAVE_STRERROR_R)
437
438 #
439 # Check defines
440 #
441 SET(headers "limits.h")
442 IF(HAVE_STDINT_H)
443   LIST(APPEND headers "stdint.h")
444 ENDIF(HAVE_STDINT_H)
445 IF(HAVE_INTTYPES_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)
459
460 #
461 # Check struct members
462 #
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)
466
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)
486 #
487 #
488 CHECK_STRUCT_MEMBER("struct tm" tm_sec
489     "sys/types.h;sys/time.h;time.h" TIME_WITH_SYS_TIME)
490
491 #
492 # Check for integer types
493 #
494 # XXX There must be a way to make this simpler <sigh> XXXX
495 #
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)
499
500 #
501 CHECK_TYPE_SIZE(dev_t       DEV_T)
502 IF(NOT HAVE_DEV_T)
503   IF(MSVC)
504     SET(dev_t "unsigned int")
505   ENDIF(MSVC)
506 ENDIF(NOT HAVE_DEV_T)
507 #
508 CHECK_TYPE_SIZE(gid_t       GID_T)
509 IF(NOT HAVE_GID_T)
510   IF(WIN32)
511     SET(gid_t "short")
512   ELSE(WIN32)
513     SET(gid_t "unsigned int")
514   ENDIF(WIN32)
515 ENDIF(NOT HAVE_GID_T)
516 #
517 CHECK_TYPE_SIZE(id_t        ID_T)
518 IF(NOT HAVE_ID_T)
519   IF(WIN32)
520     SET(id_t "short")
521   ELSE(WIN32)
522     SET(id_t "unsigned int")
523   ENDIF(WIN32)
524 ENDIF(NOT HAVE_ID_T)
525 #
526 CHECK_TYPE_SIZE(int32_t    INT32_T)
527 IF(NOT HAVE_INT32_T)
528   SET(int32_t "int")
529 ENDIF(NOT HAVE_INT32_T)
530 #
531 CHECK_TYPE_SIZE(int64_t     INT64_T)
532 IF(NOT HAVE_INT64_T)
533   IF(WIN32)
534     SET(int64_t __int64)
535   ENDIF(WIN32)
536 ENDIF(NOT HAVE_INT64_T)
537 #
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)
542 #
543 CHECK_TYPE_SIZE(mode_t      MODE_T)
544 IF(NOT HAVE_MODE_T)
545   IF(WIN32)
546     SET(mode_t "unsigned short")
547   ELSE(WIN32)
548     SET(mode_t "int")
549   ENDIF(WIN32)
550 ENDIF(NOT HAVE_MODE_T)
551 #
552 CHECK_TYPE_SIZE(off_t       OFF_T)
553 IF(NOT HAVE_OFF_T)
554   SET(off_t "__int64")
555 ENDIF(NOT HAVE_OFF_T)
556 #
557 CHECK_TYPE_SIZE(size_t      SIZE_T)
558 IF(NOT HAVE_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)
565 #
566 CHECK_TYPE_SIZE(ssize_t     SSIZE_T)
567 IF(NOT HAVE_SSIZE_T)
568   IF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
569     SET(ssize_t "int64_t")
570   ELSE("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
571     SET(ssize_t "long")
572   ENDIF("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
573 ENDIF(NOT HAVE_SSIZE_T)
574 #
575 CHECK_TYPE_SIZE(uid_t       UID_T)
576 IF(NOT HAVE_UID_T)
577   IF(WIN32)
578     SET(uid_t "short")
579   ELSE(WIN32)
580     SET(uid_t "unsigned int")
581   ENDIF(WIN32)
582 ENDIF(NOT HAVE_UID_T)
583 #
584 CHECK_TYPE_SIZE(pid_t       PID_T)
585 IF(NOT HAVE_PID_T)
586   IF(WIN32)
587     SET(pid_t "int")
588   ELSE(WIN32)
589     MESSAGE(FATAL_ERROR "pid_t doesn't exist on this platform?")
590   ENDIF(WIN32)
591 ENDIF(NOT HAVE_PID_T)
592 #
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)
597 #
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)
602 #
603 CHECK_TYPE_SIZE(uint64_t    UINT64_T)
604 IF(NOT HAVE_UINT64_T)
605   IF(WIN32)
606     SET(uint64_t "unsigned __int64")
607   ENDIF(WIN32)
608 ENDIF(NOT HAVE_UINT64_T)
609 #
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)
614 #
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")
619   ELSE()
620     SET(intptr_t "int32_t")
621   ENDIF()
622 ENDIF(NOT HAVE_INTPTR_T)
623 #
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")
628   ELSE()
629     SET(uintptr_t "uint32_t")
630   ENDIF()
631 ENDIF(NOT HAVE_UINTPTR_T)
632 #
633 CHECK_TYPE_SIZE(wchar_t     SIZEOF_WCHAR_T)
634 IF(HAVE_SIZEOF_WCHAR_T)
635   SET(HAVE_WCHAR_T 1)
636 ENDIF(HAVE_SIZEOF_WCHAR_T)
637 #
638 # Check if _FILE_OFFSET_BITS macro needed for large files
639 #
640 CHECK_FILE_OFFSET_BITS()
641
642
643
644 #
645 # Check for Extended Attribute libraries, headers, and functions
646 #
647 IF(ENABLE_XATTR)
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)
651   IF(HAVE_ATTR_LIB)
652     SET(CMAKE_REQUIRED_LIBRARIES "attr")
653   ENDIF(HAVE_ATTR_LIB)
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)
664 ENDIF(ENABLE_XATTR)
665
666 #
667 # Check for ACL libraries, headers, and functions
668 #
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.
673 #
674 IF(ENABLE_ACL)
675   CHECK_LIBRARY_EXISTS(acl "acl_get_file" "" HAVE_ACL_LIB)
676   IF(HAVE_ACL_LIB)
677     SET(CMAKE_REQUIRED_LIBRARIES "acl")
678     FIND_LIBRARY(ACL_LIBRARY NAMES acl)
679     LIST(APPEND ADDITIONAL_LIBS ${ACL_LIBRARY})
680   ENDIF(HAVE_ACL_LIB)
681   #
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)
688
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)
698
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)
702 ENDIF(ENABLE_ACL)
703
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)
709
710 #
711 # Register installation of PDF documents.
712 #
713 IF(WIN32 AND NOT CYGWIN)
714   #
715   # On Windows platform, It's better that we install PDF documents
716   # on one's computer.
717   # These PDF documents are available in the release package.
718   #
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"
723     )
724   ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doc/pdf)
725 ENDIF(WIN32 AND NOT CYGWIN)
726 #
727 #
728 #
729 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/libarchive)
730 #
731 IF(MSVC)
732   ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
733 ENDIF(MSVC)
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$")
740
741 IF(ENABLE_TEST)
742 ADD_CUSTOM_TARGET(run_all_tests)
743 ENDIF(ENABLE_TEST)
744
745 add_subdirectory(libarchive)
746 add_subdirectory(tar)
747 add_subdirectory(cpio)