-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
166 lines (131 loc) · 3.11 KB
/
CMakeLists.txt
1
2
3
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
72
73
74
75
76
77
78
79
80
81
82
83
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
#[=============================================================================[
# The zip extension
Configure the `zip` extension.
This extension provides support for reading and writing ZIP compressed archives.
## PHP_EXT_ZIP
* Default: `OFF`
* Values: `ON|OFF`
Enable the extension.
## PHP_EXT_ZIP_SHARED
* Default: `OFF`
* Values: `ON|OFF`
Build extension as shared.
#]=============================================================================]
cmake_minimum_required(VERSION 3.25...3.31)
project(
PhpExtensionZip
LANGUAGES C
)
include(CheckLibraryExists)
include(CMakeDependentOption)
include(FeatureSummary)
option(PHP_EXT_ZIP "Enable the zip extension")
add_feature_info(
"ext/zip"
PHP_EXT_ZIP
"ZIP (.zip) compressed archives support"
)
cmake_dependent_option(
PHP_EXT_ZIP_SHARED
"Build the zip extension as a shared library"
OFF
"PHP_EXT_ZIP;NOT BUILD_SHARED_LIBS"
OFF
)
if(NOT PHP_EXT_ZIP)
return()
endif()
if(PHP_EXT_ZIP_SHARED)
add_library(php_ext_zip SHARED)
else()
add_library(php_ext_zip)
endif()
target_sources(
php_ext_zip
PRIVATE
php_zip.c
php_zip.stub.php
zip_stream.c
)
add_dependencies(php_ext_zip php_ext_pcre)
find_package(libzip 1.7.1)
set_package_properties(
libzip
PROPERTIES
TYPE REQUIRED
PURPOSE "Necessary to enable the zip extension."
)
if(NOT libzip_FOUND)
find_package(libzip 1.3.2...1.6.999)
endif()
if(NOT libzip_FOUND)
find_package(libzip 0.11...1.3.0)
endif()
if(libzip_VERSION VERSION_EQUAL 1.3.1 OR libzip_VERSION VERSION_EQUAL 1.7.0)
message(
FATAL_ERROR
"ext/zip: libzip ${libzip_VERSION} is not supported. Try upgrading libzip."
)
endif()
target_link_libraries(php_ext_zip PRIVATE libzip::libzip)
# Note: ZIP_STATIC needs to be defined when using static libzip on Windows only
# since version 1.0 to 1.3.2
if(
CMAKE_SYSTEM_NAME STREQUAL "Windows"
AND libzip_VERSION VERSION_GREATER_EQUAL 1.0
AND libzip_VERSION VERSION_LESS 1.4.0
)
# TODO: Adjust this if the libzip is a static library.
if(TODO)
set(ZIP_STATIC TRUE)
#set(LZMA_API_STATIC TRUE)
endif()
endif()
# TODO: When downloading and building libzip from source additional deps are
# required.
if(TARGET libzip::libzip)
check_library_exists(
libzip::libzip
zip_file_set_mtime
""
HAVE_SET_MTIME
)
if(NOT HAVE_SET_MTIME)
message(WARNING "Libzip >= 1.0.0 needed for setting mtime")
endif()
check_library_exists(
libzip::libzip
zip_file_set_encryption
""
HAVE_ENCRYPTION
)
if(NOT HAVE_ENCRYPTION)
message(WARNING "Libzip >= 1.2.0 needed for encryption support")
endif()
check_library_exists(
libzip::libzip
zip_libzip_version
""
HAVE_LIBZIP_VERSION
)
check_library_exists(
libzip::libzip
zip_register_progress_callback_with_state
""
HAVE_PROGRESS_CALLBACK
)
check_library_exists(
libzip::libzip
zip_register_cancel_callback_with_state
""
HAVE_CANCEL_CALLBACK
)
check_library_exists(
libzip::libzip
zip_compression_method_supported
""
HAVE_METHOD_SUPPORTED
)
endif()
set(HAVE_ZIP TRUE)
configure_file(cmake/config.h.in config.h)