1
- cmake_minimum_required (VERSION 3.0.2 )
1
+ cmake_minimum_required (VERSION 3.4.0 )
2
2
3
3
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} /cmake)
4
4
if (${CMAKE_VERSION} VERSION_LESS "3.17.0" )
5
5
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} /cmake-compat)
6
6
endif ()
7
7
8
8
project (libzip
9
- VERSION 1.9.2
9
+ VERSION 1.10.0
10
10
LANGUAGES C)
11
11
12
12
option (ENABLE_COMMONCRYPTO "Enable use of CommonCrypto" ON )
@@ -19,6 +19,8 @@ option(ENABLE_BZIP2 "Enable use of BZip2" ON)
19
19
option (ENABLE_LZMA "Enable use of LZMA" ON )
20
20
option (ENABLE_ZSTD "Enable use of Zstandard" ON )
21
21
22
+ option (ENABLE_FDOPEN "Enable zip_fdopen, which is not allowed in Microsoft CRT secure libraries" ON )
23
+
22
24
option (BUILD_TOOLS "Build tools in the src directory (zipcmp, zipmerge, ziptool)" ON )
23
25
option (BUILD_REGRESS "Build regression tests" ON )
24
26
option (BUILD_EXAMPLES "Build examples" ON )
@@ -87,12 +89,17 @@ endif()
87
89
88
90
# Checks
89
91
92
+ # Request ISO C secure library functions (memcpy_s &c)
93
+ list (APPEND CMAKE_REQUIRED_DEFINITIONS -D__STDC_WANT_LIB_EXT1__=1)
94
+
90
95
check_function_exists(_close HAVE__CLOSE)
91
96
check_function_exists(_dup HAVE__DUP)
92
97
check_function_exists(_fdopen HAVE__FDOPEN)
93
98
check_function_exists(_fileno HAVE__FILENO)
94
99
check_function_exists(_setmode HAVE__SETMODE)
95
100
check_symbol_exists(_snprintf stdio.h HAVE__SNPRINTF)
101
+ check_symbol_exists(_snprintf_s stdio.h HAVE__SNPRINTF_S)
102
+ check_symbol_exists(_snwprintf_s stdio.h HAVE__SNWPRINTF_S)
96
103
check_function_exists(_strdup HAVE__STRDUP)
97
104
check_symbol_exists(_stricmp string .h HAVE__STRICMP)
98
105
check_function_exists(_strtoi64 HAVE__STRTOI64)
@@ -107,12 +114,18 @@ check_function_exists(fileno HAVE_FILENO)
107
114
check_function_exists(fseeko HAVE_FSEEKO)
108
115
check_function_exists(ftello HAVE_FTELLO)
109
116
check_function_exists(getprogname HAVE_GETPROGNAME)
110
- check_function_exists(localtime_r HAVE_LOCALTIME_R)
117
+ check_symbol_exists(localtime_r time.h HAVE_LOCALTIME_R)
118
+ check_symbol_exists(localtime_s time.h HAVE_LOCALTIME_S)
119
+ check_function_exists(memcpy_s HAVE_MEMCPY_S)
111
120
check_function_exists(setmode HAVE_SETMODE)
112
121
check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF)
122
+ check_symbol_exists(snprintf_s stdio.h HAVE_SNPRINTF_S)
113
123
check_symbol_exists(strcasecmp strings .h HAVE_STRCASECMP)
114
124
check_function_exists(strdup HAVE_STRDUP)
125
+ check_function_exists(strerror_s HAVE_STRERROR_S)
126
+ check_function_exists(strerrorlen_s HAVE_STRERRORLEN_S)
115
127
check_function_exists(stricmp HAVE_STRICMP)
128
+ check_function_exists(strncpy_s HAVE_STRNCPY_S)
116
129
check_function_exists(strtoll HAVE_STRTOLL)
117
130
check_function_exists(strtoull HAVE_STRTOULL)
118
131
@@ -177,6 +190,34 @@ int main(int argc, char *argv[]) { }" HAVE_NULLABLE)
177
190
test_big_endian(WORDS_BIGENDIAN)
178
191
179
192
find_package (ZLIB 1.1.2 REQUIRED)
193
+ # so developers on systems where zlib is named differently (Windows, sometimes)
194
+ # can override the name used in the pkg-config file
195
+ if (NOT ZLIB_LINK_LIBRARY_NAME)
196
+ set (ZLIB_LINK_LIBRARY_NAME "z" )
197
+
198
+ # Get the correct name in common cases
199
+ list (LENGTH ZLIB_LIBRARIES N_ZLIB_LIBRARIES)
200
+ if (N_ZLIB_LIBRARIES EQUAL 1)
201
+ set (ZLIB_FILENAME ${ZLIB_LIBRARIES} )
202
+ elseif (N_ZLIB_LIBRARIES EQUAL 4)
203
+ # ZLIB_LIBRARIES might have the target_link_library() format like
204
+ # "optimized;path/to/zlib.lib;debug;path/to/zlibd.lib". Use the 'optimized'
205
+ # case unless we know we are in a Debug build.
206
+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
207
+ list (FIND ZLIB_LIBRARIES "debug" ZLIB_LIBRARIES_INDEX_OF_CONFIG)
208
+ else ()
209
+ list (FIND ZLIB_LIBRARIES "optimized" ZLIB_LIBRARIES_INDEX_OF_CONFIG)
210
+ endif ()
211
+ if (ZLIB_LIBRARIES_INDEX_OF_CONFIG GREATER_EQUAL 0)
212
+ math (EXPR ZLIB_FILENAME_INDEX "${ZLIB_LIBRARIES_INDEX_OF_CONFIG} +1" )
213
+ list (GET ZLIB_LIBRARIES ${ZLIB_FILENAME_INDEX} ZLIB_FILENAME)
214
+ endif ()
215
+ endif ()
216
+ if (ZLIB_FILENAME)
217
+ get_filename_component (ZLIB_FILENAME ${ZLIB_FILENAME} NAME_WE )
218
+ string (REGEX REPLACE "^lib" "" ZLIB_LINK_LIBRARY_NAME ${ZLIB_FILENAME} )
219
+ endif ()
220
+ endif (NOT ZLIB_LINK_LIBRARY_NAME)
180
221
181
222
if (ENABLE_BZIP2)
182
223
find_package (BZip2)
@@ -197,12 +238,17 @@ if(ENABLE_LZMA)
197
238
endif (ENABLE_LZMA)
198
239
199
240
if (ENABLE_ZSTD)
200
- find_package (Zstd 1.3.6)
201
- if (Zstd_FOUND )
241
+ find_package (zstd 1.3.6)
242
+ if (zstd_FOUND )
202
243
set (HAVE_LIBZSTD 1)
244
+ if (TARGET zstd::libzstd_shared)
245
+ set (zstd_TARGET zstd::libzstd_shared)
246
+ else ()
247
+ set (zstd_TARGET zstd::libzstd_static)
248
+ endif ()
203
249
else ()
204
250
message (WARNING "-- zstd library not found; zstandard support disabled" )
205
- endif (Zstd_FOUND )
251
+ endif (zstd_FOUND )
206
252
endif (ENABLE_ZSTD)
207
253
208
254
if (COMMONCRYPTO_FOUND)
@@ -211,12 +257,12 @@ if (COMMONCRYPTO_FOUND)
211
257
elseif (WINDOWS_CRYPTO_FOUND)
212
258
set (HAVE_CRYPTO 1)
213
259
set (HAVE_WINDOWS_CRYPTO 1)
214
- elseif (GNUTLS_FOUND AND NETTLE_FOUND)
215
- set (HAVE_CRYPTO 1)
216
- set (HAVE_GNUTLS 1)
217
260
elseif (OPENSSL_FOUND)
218
261
set (HAVE_CRYPTO 1)
219
262
set (HAVE_OPENSSL 1)
263
+ elseif (GNUTLS_FOUND AND NETTLE_FOUND)
264
+ set (HAVE_CRYPTO 1)
265
+ set (HAVE_GNUTLS 1)
220
266
elseif (MBEDTLS_FOUND)
221
267
set (HAVE_CRYPTO 1)
222
268
set (HAVE_MBEDTLS 1)
@@ -265,10 +311,10 @@ else(BUILD_TOOLS)
265
311
endif (BUILD_REGRESS)
266
312
endif ()
267
313
268
- include (FindPerl )
314
+ find_program (NIHTEST nihtest )
269
315
270
- if (BUILD_REGRESS AND NOT PERL_FOUND )
271
- message (WARNING "-- perl not found, regression testing disabled" )
316
+ if (BUILD_REGRESS AND NOT NIHTEST )
317
+ message (WARNING "-- nihtest not found, regression testing disabled" )
272
318
set (BUILD_REGRESS OFF )
273
319
endif ()
274
320
@@ -299,11 +345,12 @@ foreach(LIB ${LIBS_PRIVATE})
299
345
endif ()
300
346
set (LIBS "${LIBS} -l${LIB} " )
301
347
endforeach ()
348
+ STRING (CONCAT zlib_link_name "-l" ${ZLIB_LINK_LIBRARY_NAME} )
302
349
string (REGEX REPLACE "-lBZip2::BZip2" "-lbz2" LIBS ${LIBS} )
303
350
string (REGEX REPLACE "-lLibLZMA::LibLZMA" "-llzma" LIBS ${LIBS} )
304
- string (REGEX REPLACE "-lZstd::Zstd " "-lzstd" LIBS ${LIBS} )
351
+ string (REGEX REPLACE "-l ${zstd_TARGET} " "-lzstd" LIBS ${LIBS} )
305
352
string (REGEX REPLACE "-lOpenSSL::Crypto" "-lssl -lcrypto" LIBS ${LIBS} )
306
- string (REGEX REPLACE "-lZLIB::ZLIB" "-lz" LIBS ${LIBS} )
353
+ string (REGEX REPLACE "-lZLIB::ZLIB" ${zlib_link_name} LIBS ${LIBS} )
307
354
string (REGEX REPLACE "-lGnuTLS::GnuTLS" "-lgnutls" LIBS ${LIBS} )
308
355
string (REGEX REPLACE "-lNettle::Nettle" "-lnettle" LIBS ${LIBS} )
309
356
configure_file (libzip.pc.in libzip.pc @ONLY)
@@ -413,17 +460,6 @@ set(srcdir ${CMAKE_CURRENT_SOURCE_DIR}/regress)
413
460
set (abs_srcdir ${CMAKE_CURRENT_SOURCE_DIR} /regress)
414
461
set (top_builddir ${PROJECT_BINARY_DIR} ) # used to find config.h
415
462
416
- configure_file (regress/nihtest.conf.in ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /nihtest.conf @ONLY)
417
- file (COPY ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /nihtest.conf
418
- DESTINATION ${PROJECT_BINARY_DIR} /regress
419
- FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
420
-
421
- configure_file (regress/runtest.in ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /runtest @ONLY)
422
- file (COPY ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /runtest
423
- DESTINATION ${PROJECT_BINARY_DIR} /regress
424
- FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
425
- )
426
-
427
463
# create package config file
428
464
include (CMakePackageConfigHelpers)
429
465
write_basic_package_version_file("${PROJECT_BINARY_DIR} /${PROJECT_NAME} -config-version.cmake"
@@ -432,6 +468,15 @@ write_basic_package_version_file("${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-v
432
468
configure_package_config_file("${PROJECT_NAME} -config.cmake.in" "${PROJECT_BINARY_DIR} /${PROJECT_NAME} -config.cmake"
433
469
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/libzip)
434
470
471
+ # Install Find* modules, they are required by libzip-config.cmake to resolve dependencies
472
+ install (FILES
473
+ ${CMAKE_CURRENT_SOURCE_DIR} /cmake/FindNettle.cmake
474
+ ${CMAKE_CURRENT_SOURCE_DIR} /cmake/Findzstd.cmake
475
+ ${CMAKE_CURRENT_SOURCE_DIR} /cmake/FindMbedTLS.cmake
476
+ DESTINATION
477
+ ${CMAKE_INSTALL_LIBDIR} /cmake/libzip/modules
478
+ )
479
+
435
480
if (LIBZIP_DO_INSTALL)
436
481
# Add targets to the build-tree export set
437
482
export (TARGETS zip
0 commit comments