-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
236 lines (202 loc) · 5.5 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
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
227
228
229
230
231
232
233
234
235
236
cmake_minimum_required(VERSION 3.2)
project(ZLIB)
set(cpu_is_x64 FALSE)
set(cpu_is_arm64 FALSE)
set(is_clang FALSE)
if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(is_clang TRUE)
endif()
# Neon {
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm.*")
set(default ON)
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
set(cpu_is_arm64 TRUE)
endif()
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
set(default ON)
set(cpu_is_arm64 TRUE)
else()
set(default OFF)
endif()
option(ZLIB_ARM_NEON_OPTIMIZATIONS "ARM Neon optimizations" ${default})
# }
# x86/x64 {
if(IOS)
set(default OFF)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
set(default ON)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
set(default ON)
set(cpu_is_x64 TRUE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
set(default ON)
set(cpu_is_x64 TRUE)
else()
set(default OFF)
endif()
option(ZLIB_X86_X64_OPTIMIZATIONS "x86/x64 optimizations" ${default})
# }
set(sources "")
if(ZLIB_X86_X64_OPTIMIZATIONS)
list(APPEND sources adler32_simd.c adler32_simd.h)
if(NOT WIN32 OR is_clang)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mssse3")
endif()
endif()
if(ZLIB_ARM_NEON_OPTIMIZATIONS)
list(APPEND sources adler32_simd.c adler32_simd.h)
if(NOT IOS)
if(ANDROID)
# third_party/android_ndk:cpu_features
include_directories("${CMAKE_ANDROID_NDK}/sources/android/cpufeatures")
list(
APPEND
sources
"${CMAKE_ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c"
)
elseif(NOT WIN32 AND NOT is_clang)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crc")
endif()
list(APPEND sources arm_features.c arm_features.h crc32_simd.c crc32_simd.h)
endif()
endif()
if(ZLIB_X86_X64_OPTIMIZATIONS OR ZLIB_ARM_NEON_OPTIMIZATIONS)
list(
APPEND
sources
contrib/optimizations/chunkcopy.h
contrib/optimizations/inffast_chunk.c
contrib/optimizations/inffast_chunk.h
contrib/optimizations/inflate.c
)
endif()
if(ZLIB_X86_X64_OPTIMIZATIONS)
list(APPEND sources crc32_simd.c crc32_simd.h crc_folding.c fill_window_sse.c)
if(NOT WIN32 OR is_clang)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2 -mpclmul")
endif()
else()
list(APPEND sources simd_stub.c)
endif()
list(
APPEND
sources
adler32.c
chromeconf.h
compress.c
crc32.c
crc32.h
deflate.c
deflate.h
gzclose.c
gzguts.h
gzlib.c
gzread.c
gzwrite.c
infback.c
inffast.c
inffast.h
inffixed.h
inflate.h
inftrees.c
inftrees.h
trees.c
trees.h
uncompr.c
x86.h
zconf.h
zlib.h
zutil.c
zutil.h
)
if(ZLIB_X86_X64_OPTIMIZATIONS)
list(APPEND sources x86.c)
elseif(ZLIB_ARM_NEON_OPTIMIZATIONS)
list(APPEND sources contrib/optimizations/slide_hash_neon.h)
else()
list(APPEND sources inflate.c)
endif()
add_library(ZLIB ${sources})
target_include_directories(
ZLIB PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
)
find_package(Threads REQUIRED)
target_link_libraries(ZLIB PUBLIC Threads::Threads)
target_compile_definitions(ZLIB PRIVATE ZLIB_IMPLEMENTATION)
if(ZLIB_ARM_NEON_OPTIMIZATIONS)
target_compile_definitions(ZLIB PRIVATE ADLER32_SIMD_NEON)
endif()
if(ZLIB_X86_X64_OPTIMIZATIONS)
target_compile_definitions(ZLIB PRIVATE ADLER32_SIMD_SSSE3)
endif()
if(ZLIB_ARM_NEON_OPTIMIZATIONS)
if(NOT IOS)
target_compile_definitions(ZLIB PRIVATE CRC32_ARMV8_CRC32)
if(ANDROID)
target_compile_definitions(ZLIB PRIVATE ARMV8_OS_ANDROID)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
target_compile_definitions(ZLIB PRIVATE ARMV8_OS_LINUX)
elseif(WIN32)
target_compile_definitions(ZLIB PRIVATE ARMV8_OS_WINDOWS)
else()
message(FATAL_ERROR "Unsupported ARM OS")
endif()
endif()
endif()
if(ZLIB_X86_X64_OPTIMIZATIONS)
target_compile_definitions(ZLIB PRIVATE INFLATE_CHUNK_SIMD_SSE2)
if(cpu_is_x64)
target_compile_definitions(ZLIB PRIVATE INFLATE_CHUNK_READ_64LE)
endif()
endif()
if(ZLIB_ARM_NEON_OPTIMIZATIONS)
target_compile_definitions(ZLIB PRIVATE INFLATE_CHUNK_SIMD_NEON)
if(cpu_is_arm64)
target_compile_definitions(ZLIB PRIVATE INFLATE_CHUNK_READ_64LE)
endif()
endif()
if(ZLIB_X86_X64_OPTIMIZATIONS)
target_compile_definitions(ZLIB PRIVATE CRC32_SIMD_SSE42_PCLMUL)
endif()
### Installation (https://github.com/forexample/package-example) {
# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
# * CMAKE_INSTALL_INCLUDEDIR
include(GNUInstallDirs)
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(NAMESPACE "${PROJECT_NAME}::")
include(CMakePackageConfigHelpers)
# Use:
# * TARGETS_EXPORT_NAME
# * PROJECT_NAME
configure_package_config_file(
"cmake/template/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
install(
FILES zlib.h zconf.h chromeconf.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
FILES "${project_config}"
DESTINATION "${config_install_dir}"
)
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${NAMESPACE}"
DESTINATION "${config_install_dir}"
)
install(
TARGETS ZLIB
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
### }