CMakeLists.txt 8.63 KB
Newer Older
Andy Cedilnik's avatar
Andy Cedilnik committed
1
2
CMAKE_MINIMUM_REQUIRED(VERSION 2.0)
PROJECT(LIBTAR C)
3
INCLUDE_REGULAR_EXPRESSION("^.*$")
Andy Cedilnik's avatar
Andy Cedilnik committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

# We need ansi c-flags, especially on HP
SET(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
SET(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_CFLAGS})

# If we are on AIX, do the _ALL_SOURCE magic
IF(${CMAKE_SYSTEM_NAME} MATCHES AIX)
  SET(_ALL_SOURCE 1)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES AIX)

# Include all the necessary files for macros
#SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
# Include all the necessary files for macros
INCLUDE (CheckIncludeFiles)
INCLUDE (CheckFunctionExists)
INCLUDE (CheckTypeSize)
INCLUDE (CheckSymbolExists)
INCLUDE (TestBigEndian)

MACRO(MANGLE_VARIABLE_NAME str var prefix)
  STRING(TOUPPER "${str}" mangle_variable_name_var)
  STRING(REGEX REPLACE "[/. ]" "_" mangle_variable_name_var "${mangle_variable_name_var}")
  SET(${var} "${prefix}${mangle_variable_name_var}")
ENDMACRO(MANGLE_VARIABLE_NAME str var)

# Check if header file exists and add it to the list.
MACRO(CHECK_INCLUDE_FILE_CONCAT FILE)
  MANGLE_VARIABLE_NAME("${FILE}" "CHECK_INCLUDE_FILE_CONCAT_VAR" "HAVE_")
  CHECK_INCLUDE_FILES("${HEADER_INCLUDES};${FILE}" ${CHECK_INCLUDE_FILE_CONCAT_VAR})
  IF(${CHECK_INCLUDE_FILE_CONCAT_VAR})
    SET(HEADER_INCLUDES ${HEADER_INCLUDES} ${FILE})
  ENDIF(${CHECK_INCLUDE_FILE_CONCAT_VAR})
ENDMACRO(CHECK_INCLUDE_FILE_CONCAT)

MACRO(CHECK_FUNCTION_EXISTS_EX FUNC)
  MANGLE_VARIABLE_NAME("${FUNC}" "CHECK_FUNCTION_EXISTS_EX_VAR" "HAVE_")
  CHECK_FUNCTION_EXISTS("${FUNC}" "${CHECK_FUNCTION_EXISTS_EX_VAR}")
ENDMACRO(CHECK_FUNCTION_EXISTS_EX)

MACRO(CHECK_SYMBOL_EXISTS_EX SYM)
  MANGLE_VARIABLE_NAME("${SYM}" "CHECK_SYMBOL_EXISTS_EX_VAR" "HAVE_")
  CHECK_SYMBOL_EXISTS("${SYM}" "${HEADER_INCLUDES}" "${CHECK_SYMBOL_EXISTS_EX_VAR}")
ENDMACRO(CHECK_SYMBOL_EXISTS_EX)

#MACRO(CHECK_TYPE_SIZE_EX type defualt_size)
#  MANGLE_VARIABLE_NAME("${type}" "check_type_size_var" "")
#  CHECK_TYPE_SIZE("${type}" "SIZEOF_${check_type_size_var}")
#  IF(HAVE_${check_type_size_var})
#    SET("HAVE_${check_type_size_var}" 1)
#  ELSE(HAVE_${check_type_size_var})
#  ENDIF(HAVE_${check_type_size_var})
#ENDMACRO(CHECK_TYPE_SIZE_EX)



INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}")
INCLUDE_DIRECTORIES(${CURL_SPECIAL_LIBZ_INCLUDES})

#check for stdc headers
CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)

#check for other headers used by the program
FOREACH(file
  "ctype.h"
  "fnmatch.h"
  "inttypes.h"
  "libgen.h"
  "memory.h"
72
  "sys/mkdev.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
73
74
75
76
77
  "stdint.h"
  "stdlib.h"
  "stdio.h"
  "string.h"
  "strings.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
78
  "sys/param.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
79
80
81
82
  "sys/types.h"
  "sys/stat.h"
  "unistd.h"
  "glob.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
83
  "dirent.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  )
  CHECK_INCLUDE_FILE_CONCAT("${file}")
ENDFOREACH(file)

#check for the functions used by the program
FOREACH(func
    basename
    dirname
    fnmatch
    lchown
    snprintf
    strlcpy
    strmode
    strsep
    strdup
    strftime
    glob
    )
  CHECK_SYMBOL_EXISTS_EX("${func}")
ENDFOREACH(func)

CHECK_TYPE_SIZE("dev_t" SIZEOF_DEV_T)
IF(HAVE_SIZEOF_DEV_T)
  SET (HAVE_DEV_T 1)
ELSE(HAVE_SIZEOF_DEV_T)
  SET (HAVE_DEV_T 0)
  SET (dev_t "unsigned long")
ENDIF(HAVE_SIZEOF_DEV_T)

CHECK_TYPE_SIZE("major_t" SIZEOF_MAJOR_T)
IF(HAVE_SIZEOF_MAJOR_T)
  SET (HAVE_MAJOR_T 1)
ELSE(HAVE_SIZEOF_MAJOR_T)
  SET (HAVE_MAJOR_T 0)
  SET (major_t "unsigned int")
ENDIF(HAVE_SIZEOF_MAJOR_T)

CHECK_TYPE_SIZE("minor_t" SIZEOF_MINOR_T)
IF(HAVE_SIZEOF_MINOR_T)
  SET (HAVE_MINOR_T 1)
ELSE(HAVE_SIZEOF_MINOR_T)
  SET (HAVE_MINOR_T 0)
  SET (minor_t "unsigned int")
ENDIF(HAVE_SIZEOF_MINOR_T)

CHECK_TYPE_SIZE("nlink_t" SIZEOF_NLINK_T)
IF(HAVE_SIZEOF_NLINK_T)
  SET (HAVE_NLINK_T 1)
ELSE(HAVE_SIZEOF_NLINK_T)
  SET (HAVE_NLINK_T 0)
  SET (nlink_t "unsigned short")
ENDIF(HAVE_SIZEOF_NLINK_T)

CHECK_TYPE_SIZE("uint64_t" SIZEOF_UINT64_T)
IF(HAVE_SIZEOF_UINT64_T)
  SET (HAVE_UINT64_T 1)
ELSE(HAVE_SIZEOF_UINT64_T)
  SET (HAVE_UINT64_T 0)
  SET (uint64_t "long long")
ENDIF(HAVE_SIZEOF_UINT64_T)

CHECK_TYPE_SIZE("gid_t" SIZEOF_GID_T)
IF(HAVE_SIZEOF_GID_T)
  SET (HAVE_GID_T 1)
ELSE(HAVE_SIZEOF_GID_T)
  SET (HAVE_GID_T 0)
  SET (gid_t "int")
ENDIF(HAVE_SIZEOF_GID_T)

CHECK_TYPE_SIZE("mode_t" SIZEOF_MODE_T)
IF(HAVE_SIZEOF_MODE_T)
  SET (HAVE_MODE_T 1)
ELSE(HAVE_SIZEOF_MODE_T)
  SET (HAVE_MODE_T 0)
  SET (mode_t "int")
ENDIF(HAVE_SIZEOF_MODE_T)

CHECK_TYPE_SIZE("off_t" SIZEOF_OFF_T)
IF(HAVE_SIZEOF_OFF_T)
  SET (HAVE_OFF_T 1)
ELSE(HAVE_SIZEOF_OFF_T)
  SET (HAVE_OFF_T 0)
  SET (off_t "long")
ENDIF(HAVE_SIZEOF_OFF_T)

CHECK_TYPE_SIZE("size_t" SIZEOF_SIZE_T)
IF(HAVE_SIZEOF_SIZE_T)
  SET (HAVE_SIZE_T 1)
ELSE(HAVE_SIZEOF_SIZE_T)
  SET (HAVE_SIZE_T 0)
  SET (size_t "unsigned")
ENDIF(HAVE_SIZEOF_SIZE_T)

CHECK_TYPE_SIZE("ssize_t" SIZEOF_SSIZE_T)
IF(HAVE_SIZEOF_SSIZE_T)
  SET (HAVE_SSIZE_T 1)
ELSE(HAVE_SIZEOF_SSIZE_T)
  SET (HAVE_SSIZE_T 0)
  SET (ssize_t "int")
ENDIF(HAVE_SIZEOF_SSIZE_T)

CHECK_TYPE_SIZE("uid_t" SIZEOF_UID_T)
IF(HAVE_SIZEOF_UID_T)
  SET (HAVE_UID_T 1)
ELSE(HAVE_SIZEOF_UID_T)
  SET (HAVE_UID_T 0)
  SET (uid_t "int")
ENDIF(HAVE_SIZEOF_UID_T)

#SET (HAVE_BASENAME 0)
#SET (HAVE_CTYPE_H 0)
#SET (HAVE_DEV_T 1)
#SET (HAVE_DIRNAME 0)
#SET (HAVE_FNMATCH 1)
#SET (HAVE_FNMATCH_H 1)
#SET (HAVE_INTTYPES_H 1)
#SET (HAVE_LCHOWN 1)
#SET (HAVE_LIBGEN_H 1)
SET (HAVE_LIBZ 1)
#SET (HAVE_MAJOR_T 0)
#SET (HAVE_MEMORY_H 1)
#SET (HAVE_MINOR_T 0)
#SET (HAVE_NLINK_T 1)
#SET (HAVE_SNPRINTF 1)
#SET (HAVE_STDINT_H 1)
#SET (HAVE_STDLIB_H 1)
#SET (HAVE_STRDUP 1)
#SET (HAVE_STRFTIME 1)
#SET (HAVE_STRINGS_H 1)
#SET (HAVE_STRING_H 1)
#SET (HAVE_STRLCPY 0)
#SET (HAVE_STRMODE 0)
#SET (HAVE_STRSEP 1)
#SET (HAVE_SYS_STAT_H 1)
#SET (HAVE_SYS_TYPES_H 1)
#SET (HAVE_UINT64_T 1)
#SET (HAVE_UNISTD_H 1)
SET (MAJOR_IN_MKDEV 0)
SET (MAJOR_IN_SYSMACROS 0)
SET (MAKEDEV_THREE_ARGS 0)
#SET (NEED_BASENAME 0)
#SET (NEED_DIRNAME 0)
#SET (NEED_FNMATCH 1)
Andy Cedilnik's avatar
Andy Cedilnik committed
227
228
229
IF(UNIX)
  SET (NEED_MAKEDEV 1)
ENDIF(UNIX)
Andy Cedilnik's avatar
Andy Cedilnik committed
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#SET (NEED_SNPRINTF 0)
#SET (NEED_STRDUP 0)
#SET (NEED_STRLCPY 0)
#SET (NEED_STRMODE 1)
#SET (NEED_STRSEP 0)
SET (PACKAGE_BUGREPORT "")
SET (PACKAGE_NAME "\"libtar\"")
SET (PACKAGE_STRING "\"libtar 1.2.11\"")
SET (PACKAGE_TARNAME "\"libtar\"")
SET (PACKAGE_VERSION "\"1.2.11\"")
#SET (STDC_HEADERS 1)
SET (const 0)
#SET (dev_t 0)
#SET (gid_t 0)
#SET (major_t "unsigned int")
#SET (minor_t "unsigned int")
#SET (mode_t 0)
#SET (nlink_t 0)
#SET (off_t 0)
#SET (size_t 0)
#SET (uid_t 0)
#SET (uint64_t 0)
SET (LISTHASH_PREFIX "libtar")

CONFIGURE_FILE(${LIBTAR_SOURCE_DIR}/listhash/listhash.h.in
  ${LIBTAR_BINARY_DIR}/libtar/libtar_listhash.h @ONLY IMMEDIATE)
CONFIGURE_FILE(${LIBTAR_SOURCE_DIR}/listhash/list.c.in
  ${LIBTAR_BINARY_DIR}/listhash/libtar_list.c @ONLY IMMEDIATE)
CONFIGURE_FILE(${LIBTAR_SOURCE_DIR}/listhash/hash.c.in
  ${LIBTAR_BINARY_DIR}/listhash/libtar_hash.c @ONLY IMMEDIATE)

FOREACH(hfile libtar.h tar.h compat/compat.h)
  GET_FILENAME_COMPONENT(outname "${hfile}" NAME)
  CONFIGURE_FILE(${LIBTAR_SOURCE_DIR}/${hfile}
    ${LIBTAR_BINARY_DIR}/libtar/${outname} @ONLY IMMEDIATE)
ENDFOREACH(hfile)

Andy Cedilnik's avatar
Andy Cedilnik committed
267
268
269
270
271
FOREACH(hfile internal.h filesystem.h)
  GET_FILENAME_COMPONENT(outname "${hfile}" NAME)
  CONFIGURE_FILE(${LIBTAR_SOURCE_DIR}/${hfile}
    ${LIBTAR_BINARY_DIR}/libtarint/${outname} @ONLY IMMEDIATE)
ENDFOREACH(hfile)
Andy Cedilnik's avatar
Andy Cedilnik committed
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
  
SET(libtar_SRC
  append.c
  block.c
  decode.c
  encode.c
  extract.c
  handle.c
  ${LIBTAR_BINARY_DIR}/listhash/libtar_hash.c
  ${LIBTAR_BINARY_DIR}/listhash/libtar_list.c
  output.c
  util.c
  wrapper.c
  internal.h
  ${LIBTAR_BINARY_DIR}/libtar/config.h
  config.h.in
  tar.h
  libtar.h
  compat/compat.h
  
#  compat/strlcpy.c
#  compat/basename.c
#  compat/dirname.c
#  compat/strmode.c 
#  compat/strsep.c 
)
Andy Cedilnik's avatar
Andy Cedilnik committed
298
IF(NOT HAVE_DIRENT_H)
Andy Cedilnik's avatar
Andy Cedilnik committed
299
300
301
  SET(libtar_SRC
    ${libtar_SRC}
    filesystem.c filesystem.h)
Andy Cedilnik's avatar
Andy Cedilnik committed
302
ENDIF(NOT HAVE_DIRENT_H)
Andy Cedilnik's avatar
Andy Cedilnik committed
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351

IF(NOT HAVE_STRLCPY)
SET(libtar_SRC ${libtar_SRC} compat/strlcpy.c)
SET(NEED_STRLCPY 1)
ENDIF(NOT HAVE_STRLCPY)

IF(NOT HAVE_STRMODE)
SET(libtar_SRC ${libtar_SRC} compat/strmode.c)
SET(NEED_STRMODE 1)
ENDIF(NOT HAVE_STRMODE)

IF(WIN32)
IF(NOT HAVE_SNPRINTF)
SET(libtar_SRC ${libtar_SRC} compat/snprintf.c)
SET(NEED_SNPRINTF 1)
ENDIF(NOT HAVE_SNPRINTF)
ENDIF(WIN32)

IF(NOT HAVE_DIRNAME)
SET(libtar_SRC ${libtar_SRC} compat/dirname.c)
SET(NEED_DIRNAME 1)
ENDIF(NOT HAVE_DIRNAME)


IF(NOT HAVE_STRSEP)
SET(libtar_SRC ${libtar_SRC} compat/strsep.c)
SET(NEED_STRSEP 1)
ENDIF(NOT HAVE_STRSEP)


IF(NOT HAVE_BASENAME)
SET(libtar_SRC ${libtar_SRC} compat/basename.c)
SET(NEED_BASENAME 1)
ENDIF(NOT HAVE_BASENAME)

IF(NOT HAVE_FNMATCH)
SET(libtar_SRC ${libtar_SRC} compat/fnmatch.c)
SET(NEED_FNMATCH 1)
ENDIF(NOT HAVE_FNMATCH)

#IF(NOT HAVE_GLOB)
#SET(libtar_SRC ${libtar_SRC} compat/glob.c)
#SET(NEED_GLOB 1)
#ENDIF(NOT HAVE_GLOB)


CONFIGURE_FILE(${LIBTAR_SOURCE_DIR}/config.h.in
  ${LIBTAR_BINARY_DIR}/libtar/config.h)

352
ADD_LIBRARY(cmtar STATIC ${libtar_SRC})
Andy Cedilnik's avatar
Andy Cedilnik committed
353
ADD_EXECUTABLE(tartest libtar.c)
354
TARGET_LINK_LIBRARIES(tartest cmtar ${CMAKE_ZLIB_LIBRARIES})
Andy Cedilnik's avatar
Andy Cedilnik committed
355