CMakeLists.txt 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. CMAKE_MINIMUM_REQUIRED(VERSION 2.0)
  2. PROJECT(LIBTAR C)
  3. INCLUDE_REGULAR_EXPRESSION("^.*$")
  4. # We need ansi c-flags, especially on HP
  5. SET(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
  6. SET(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})
  7. # If we are on AIX, do the _ALL_SOURCE magic
  8. IF(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  9. SET(_ALL_SOURCE 1)
  10. ENDIF(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  11. # Include all the necessary files for macros
  12. #SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
  13. # Include all the necessary files for macros
  14. INCLUDE (CheckIncludeFiles)
  15. INCLUDE (CheckFunctionExists)
  16. INCLUDE (CheckTypeSize)
  17. INCLUDE (CheckSymbolExists)
  18. INCLUDE (TestBigEndian)
  19. MACRO(MANGLE_VARIABLE_NAME str var prefix)
  20. STRING(TOUPPER "${str}" mangle_variable_name_var)
  21. STRING(REGEX REPLACE "[/. ]" "_" mangle_variable_name_var "${mangle_variable_name_var}")
  22. SET(${var} "${prefix}${mangle_variable_name_var}")
  23. ENDMACRO(MANGLE_VARIABLE_NAME str var)
  24. # Check if header file exists and add it to the list.
  25. MACRO(CHECK_INCLUDE_FILE_CONCAT FILE)
  26. MANGLE_VARIABLE_NAME("${FILE}" "CHECK_INCLUDE_FILE_CONCAT_VAR" "HAVE_")
  27. CHECK_INCLUDE_FILES("${HEADER_INCLUDES};${FILE}" ${CHECK_INCLUDE_FILE_CONCAT_VAR})
  28. IF(${CHECK_INCLUDE_FILE_CONCAT_VAR})
  29. SET(HEADER_INCLUDES ${HEADER_INCLUDES} ${FILE})
  30. ENDIF(${CHECK_INCLUDE_FILE_CONCAT_VAR})
  31. ENDMACRO(CHECK_INCLUDE_FILE_CONCAT)
  32. MACRO(CHECK_FUNCTION_EXISTS_EX FUNC)
  33. MANGLE_VARIABLE_NAME("${FUNC}" "CHECK_FUNCTION_EXISTS_EX_VAR" "HAVE_")
  34. CHECK_FUNCTION_EXISTS("${FUNC}" "${CHECK_FUNCTION_EXISTS_EX_VAR}")
  35. ENDMACRO(CHECK_FUNCTION_EXISTS_EX)
  36. MACRO(CHECK_SYMBOL_EXISTS_EX SYM)
  37. MANGLE_VARIABLE_NAME("${SYM}" "CHECK_SYMBOL_EXISTS_EX_VAR" "HAVE_")
  38. CHECK_SYMBOL_EXISTS("${SYM}" "${HEADER_INCLUDES}" "${CHECK_SYMBOL_EXISTS_EX_VAR}")
  39. ENDMACRO(CHECK_SYMBOL_EXISTS_EX)
  40. #MACRO(CHECK_TYPE_SIZE_EX type defualt_size)
  41. # MANGLE_VARIABLE_NAME("${type}" "check_type_size_var" "")
  42. # CHECK_TYPE_SIZE("${type}" "SIZEOF_${check_type_size_var}")
  43. # IF(HAVE_${check_type_size_var})
  44. # SET("HAVE_${check_type_size_var}" 1)
  45. # ELSE(HAVE_${check_type_size_var})
  46. # ENDIF(HAVE_${check_type_size_var})
  47. #ENDMACRO(CHECK_TYPE_SIZE_EX)
  48. INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}")
  49. INCLUDE_DIRECTORIES(${CURL_SPECIAL_LIBZ_INCLUDES})
  50. #check for stdc headers
  51. CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
  52. #check for other headers used by the program
  53. FOREACH(file
  54. "ctype.h"
  55. "fnmatch.h"
  56. "inttypes.h"
  57. "libgen.h"
  58. "memory.h"
  59. "sys/mkdev.h"
  60. "stdint.h"
  61. "stdlib.h"
  62. "stdio.h"
  63. "string.h"
  64. "strings.h"
  65. "sys/param.h"
  66. "sys/types.h"
  67. "sys/stat.h"
  68. "unistd.h"
  69. "glob.h"
  70. "dirent.h"
  71. "sys/sysmacros.h"
  72. )
  73. CHECK_INCLUDE_FILE_CONCAT("${file}")
  74. ENDFOREACH(file)
  75. #check for the functions used by the program
  76. FOREACH(func
  77. basename
  78. dirname
  79. fnmatch
  80. lchown
  81. snprintf
  82. strlcpy
  83. strmode
  84. strsep
  85. strdup
  86. strftime
  87. vsnprintf
  88. glob
  89. major
  90. minor
  91. )
  92. CHECK_SYMBOL_EXISTS_EX("${func}")
  93. ENDFOREACH(func)
  94. CHECK_TYPE_SIZE("dev_t" SIZEOF_DEV_T)
  95. IF(HAVE_SIZEOF_DEV_T)
  96. SET (HAVE_DEV_T 1)
  97. ELSE(HAVE_SIZEOF_DEV_T)
  98. SET (HAVE_DEV_T 0)
  99. SET (dev_t "unsigned long")
  100. ENDIF(HAVE_SIZEOF_DEV_T)
  101. CHECK_TYPE_SIZE("major_t" SIZEOF_MAJOR_T)
  102. IF(HAVE_SIZEOF_MAJOR_T)
  103. SET (HAVE_MAJOR_T 1)
  104. ELSE(HAVE_SIZEOF_MAJOR_T)
  105. SET (HAVE_MAJOR_T 0)
  106. SET (major_t "unsigned int")
  107. ENDIF(HAVE_SIZEOF_MAJOR_T)
  108. CHECK_TYPE_SIZE("minor_t" SIZEOF_MINOR_T)
  109. IF(HAVE_SIZEOF_MINOR_T)
  110. SET (HAVE_MINOR_T 1)
  111. ELSE(HAVE_SIZEOF_MINOR_T)
  112. SET (HAVE_MINOR_T 0)
  113. SET (minor_t "unsigned int")
  114. ENDIF(HAVE_SIZEOF_MINOR_T)
  115. CHECK_TYPE_SIZE("nlink_t" SIZEOF_NLINK_T)
  116. IF(HAVE_SIZEOF_NLINK_T)
  117. SET (HAVE_NLINK_T 1)
  118. ELSE(HAVE_SIZEOF_NLINK_T)
  119. SET (HAVE_NLINK_T 0)
  120. SET (nlink_t "unsigned short")
  121. ENDIF(HAVE_SIZEOF_NLINK_T)
  122. CHECK_TYPE_SIZE("uint64_t" SIZEOF_UINT64_T)
  123. IF(HAVE_SIZEOF_UINT64_T)
  124. SET (HAVE_UINT64_T 1)
  125. ELSE(HAVE_SIZEOF_UINT64_T)
  126. SET (HAVE_UINT64_T 0)
  127. SET (uint64_t "long long")
  128. ENDIF(HAVE_SIZEOF_UINT64_T)
  129. CHECK_TYPE_SIZE("gid_t" SIZEOF_GID_T)
  130. IF(HAVE_SIZEOF_GID_T)
  131. SET (HAVE_GID_T 1)
  132. ELSE(HAVE_SIZEOF_GID_T)
  133. SET (HAVE_GID_T 0)
  134. SET (gid_t "int")
  135. ENDIF(HAVE_SIZEOF_GID_T)
  136. CHECK_TYPE_SIZE("mode_t" SIZEOF_MODE_T)
  137. IF(HAVE_SIZEOF_MODE_T)
  138. SET (HAVE_MODE_T 1)
  139. ELSE(HAVE_SIZEOF_MODE_T)
  140. SET (HAVE_MODE_T 0)
  141. SET (mode_t "int")
  142. ENDIF(HAVE_SIZEOF_MODE_T)
  143. CHECK_TYPE_SIZE("off_t" SIZEOF_OFF_T)
  144. IF(HAVE_SIZEOF_OFF_T)
  145. SET (HAVE_OFF_T 1)
  146. ELSE(HAVE_SIZEOF_OFF_T)
  147. SET (HAVE_OFF_T 0)
  148. SET (off_t "long")
  149. ENDIF(HAVE_SIZEOF_OFF_T)
  150. CHECK_TYPE_SIZE("size_t" SIZEOF_SIZE_T)
  151. IF(HAVE_SIZEOF_SIZE_T)
  152. SET (HAVE_SIZE_T 1)
  153. ELSE(HAVE_SIZEOF_SIZE_T)
  154. SET (HAVE_SIZE_T 0)
  155. SET (size_t "unsigned")
  156. ENDIF(HAVE_SIZEOF_SIZE_T)
  157. CHECK_TYPE_SIZE("ssize_t" SIZEOF_SSIZE_T)
  158. IF(HAVE_SIZEOF_SSIZE_T)
  159. SET (HAVE_SSIZE_T 1)
  160. ELSE(HAVE_SIZEOF_SSIZE_T)
  161. SET (HAVE_SSIZE_T 0)
  162. SET (ssize_t "int")
  163. ENDIF(HAVE_SIZEOF_SSIZE_T)
  164. CHECK_TYPE_SIZE("uid_t" SIZEOF_UID_T)
  165. IF(HAVE_SIZEOF_UID_T)
  166. SET (HAVE_UID_T 1)
  167. ELSE(HAVE_SIZEOF_UID_T)
  168. SET (HAVE_UID_T 0)
  169. SET (uid_t "int")
  170. ENDIF(HAVE_SIZEOF_UID_T)
  171. #SET (HAVE_BASENAME 0)
  172. #SET (HAVE_CTYPE_H 0)
  173. #SET (HAVE_DEV_T 1)
  174. #SET (HAVE_DIRNAME 0)
  175. #SET (HAVE_FNMATCH 1)
  176. #SET (HAVE_FNMATCH_H 1)
  177. #SET (HAVE_INTTYPES_H 1)
  178. #SET (HAVE_LCHOWN 1)
  179. #SET (HAVE_LIBGEN_H 1)
  180. SET (HAVE_LIBZ 1)
  181. #SET (HAVE_MAJOR_T 0)
  182. #SET (HAVE_MEMORY_H 1)
  183. #SET (HAVE_MINOR_T 0)
  184. #SET (HAVE_NLINK_T 1)
  185. #SET (HAVE_SNPRINTF 1)
  186. #SET (HAVE_STDINT_H 1)
  187. #SET (HAVE_STDLIB_H 1)
  188. #SET (HAVE_STRDUP 1)
  189. #SET (HAVE_STRFTIME 1)
  190. #SET (HAVE_STRINGS_H 1)
  191. #SET (HAVE_STRING_H 1)
  192. #SET (HAVE_STRLCPY 0)
  193. #SET (HAVE_STRMODE 0)
  194. #SET (HAVE_STRSEP 1)
  195. #SET (HAVE_SYS_STAT_H 1)
  196. #SET (HAVE_SYS_TYPES_H 1)
  197. #SET (HAVE_UINT64_T 1)
  198. #SET (HAVE_UNISTD_H 1)
  199. SET (MAJOR_IN_MKDEV 0)
  200. SET (MAJOR_IN_SYSMACROS 0)
  201. SET (MAKEDEV_THREE_ARGS 0)
  202. #SET (NEED_BASENAME 0)
  203. #SET (NEED_DIRNAME 0)
  204. #SET (NEED_FNMATCH 1)
  205. IF(UNIX)
  206. SET (NEED_MAKEDEV 1)
  207. ENDIF(UNIX)
  208. #SET (NEED_SNPRINTF 0)
  209. #SET (NEED_STRDUP 0)
  210. #SET (NEED_STRLCPY 0)
  211. #SET (NEED_STRMODE 1)
  212. #SET (NEED_STRSEP 0)
  213. SET (PACKAGE_BUGREPORT "")
  214. SET (PACKAGE_NAME "\"libtar\"")
  215. SET (PACKAGE_STRING "\"libtar 1.2.11\"")
  216. SET (PACKAGE_TARNAME "\"libtar\"")
  217. SET (PACKAGE_VERSION "\"1.2.11\"")
  218. #SET (STDC_HEADERS 1)
  219. SET (const 0)
  220. #SET (dev_t 0)
  221. #SET (gid_t 0)
  222. #SET (major_t "unsigned int")
  223. #SET (minor_t "unsigned int")
  224. #SET (mode_t 0)
  225. #SET (nlink_t 0)
  226. #SET (off_t 0)
  227. #SET (size_t 0)
  228. #SET (uid_t 0)
  229. #SET (uint64_t 0)
  230. SET (LISTHASH_PREFIX "libtar")
  231. CONFIGURE_FILE(${LIBTAR_SOURCE_DIR}/listhash/listhash.h.in
  232. ${LIBTAR_BINARY_DIR}/libtar/libtar_listhash.h @ONLY IMMEDIATE)
  233. CONFIGURE_FILE(${LIBTAR_SOURCE_DIR}/listhash/list.c.in
  234. ${LIBTAR_BINARY_DIR}/listhash/libtar_list.c @ONLY IMMEDIATE)
  235. CONFIGURE_FILE(${LIBTAR_SOURCE_DIR}/listhash/hash.c.in
  236. ${LIBTAR_BINARY_DIR}/listhash/libtar_hash.c @ONLY IMMEDIATE)
  237. FOREACH(hfile libtar.h tar.h compat/compat.h)
  238. GET_FILENAME_COMPONENT(outname "${hfile}" NAME)
  239. CONFIGURE_FILE(${LIBTAR_SOURCE_DIR}/${hfile}
  240. ${LIBTAR_BINARY_DIR}/libtar/${outname} @ONLY IMMEDIATE)
  241. ENDFOREACH(hfile)
  242. FOREACH(hfile internal.h filesystem.h)
  243. GET_FILENAME_COMPONENT(outname "${hfile}" NAME)
  244. CONFIGURE_FILE(${LIBTAR_SOURCE_DIR}/${hfile}
  245. ${LIBTAR_BINARY_DIR}/libtarint/${outname} @ONLY IMMEDIATE)
  246. ENDFOREACH(hfile)
  247. SET(libtar_SRC
  248. append.c
  249. block.c
  250. decode.c
  251. encode.c
  252. extract.c
  253. handle.c
  254. ${LIBTAR_BINARY_DIR}/listhash/libtar_hash.c
  255. ${LIBTAR_BINARY_DIR}/listhash/libtar_list.c
  256. output.c
  257. util.c
  258. wrapper.c
  259. internal.h
  260. ${LIBTAR_BINARY_DIR}/libtar/config.h
  261. config.h.in
  262. tar.h
  263. libtar.h
  264. compat/compat.h
  265. # compat/strlcpy.c
  266. # compat/basename.c
  267. # compat/dirname.c
  268. # compat/strmode.c
  269. # compat/strsep.c
  270. )
  271. IF(NOT HAVE_DIRENT_H)
  272. SET(libtar_SRC
  273. ${libtar_SRC}
  274. filesystem.c filesystem.h)
  275. ENDIF(NOT HAVE_DIRENT_H)
  276. IF(NOT HAVE_STRLCPY)
  277. SET(libtar_SRC ${libtar_SRC} compat/strlcpy.c)
  278. SET(NEED_STRLCPY 1)
  279. ENDIF(NOT HAVE_STRLCPY)
  280. IF(NOT HAVE_STRMODE)
  281. SET(libtar_SRC ${libtar_SRC} compat/strmode.c)
  282. SET(NEED_STRMODE 1)
  283. ENDIF(NOT HAVE_STRMODE)
  284. IF(WIN32)
  285. IF(NOT HAVE_SNPRINTF OR NOT HAVE_VSNPRINTF)
  286. SET(libtar_SRC ${libtar_SRC} compat/snprintf.c)
  287. SET(NEED_SNPRINTF 1)
  288. ENDIF(NOT HAVE_SNPRINTF OR NOT HAVE_VSNPRINTF)
  289. ENDIF(WIN32)
  290. IF(NOT HAVE_DIRNAME)
  291. SET(libtar_SRC ${libtar_SRC} compat/dirname.c)
  292. SET(NEED_DIRNAME 1)
  293. ENDIF(NOT HAVE_DIRNAME)
  294. IF(NOT HAVE_STRSEP)
  295. SET(libtar_SRC ${libtar_SRC} compat/strsep.c)
  296. SET(NEED_STRSEP 1)
  297. ENDIF(NOT HAVE_STRSEP)
  298. IF(NOT HAVE_BASENAME)
  299. SET(libtar_SRC ${libtar_SRC} compat/basename.c)
  300. SET(NEED_BASENAME 1)
  301. ENDIF(NOT HAVE_BASENAME)
  302. IF(NOT HAVE_FNMATCH)
  303. SET(libtar_SRC ${libtar_SRC} compat/fnmatch.c)
  304. SET(NEED_FNMATCH 1)
  305. ENDIF(NOT HAVE_FNMATCH)
  306. #IF(NOT HAVE_GLOB)
  307. #SET(libtar_SRC ${libtar_SRC} compat/glob.c)
  308. #SET(NEED_GLOB 1)
  309. #ENDIF(NOT HAVE_GLOB)
  310. CONFIGURE_FILE(${LIBTAR_SOURCE_DIR}/config.h.in
  311. ${LIBTAR_BINARY_DIR}/libtar/config.h)
  312. ADD_LIBRARY(cmtar STATIC ${libtar_SRC})
  313. ADD_EXECUTABLE(tartest libtar.c)
  314. TARGET_LINK_LIBRARIES(tartest cmtar ${CMAKE_ZLIB_LIBRARIES})