-
Notifications
You must be signed in to change notification settings - Fork 8
/
zlib-1.2.11+dfsg-2.cmake
206 lines (178 loc) · 6.89 KB
/
zlib-1.2.11+dfsg-2.cmake
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
# This file is part of OpenOrienteering.
# Copyright 2016-2019 Kai Pastor
#
# Redistribution and use is allowed according to the terms of the BSD license:
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# https://tracker.debian.org/pkg/zlib
# As long as zlib Debian sources and coypright are insufficient,
# we use libz-mingw-w64 instead:
# https://tracker.debian.org/pkg/libz-mingw-w64
set(version 1.2.11+dfsg) # libz-mingw-w64
set(download_hash SHA256=9d0404bc07629383dd71cb0b50749d7dcd156d28476f8a197bfb0f50005e4177)
set(patch_version ${version}-2) # libz-mingw-w64
set(patch_hash SHA256=b01dfe018f2558b96ea4ca83a69f887d7a1b1882c61383df0a6050451a308610)
set(base_url https://snapshot.debian.org/archive/debian/20180509T221858Z/pool/main/libz/libz-mingw-w64)
option(USE_SYSTEM_ZLIB "Use the system zlib if possible" ON)
set(test_system_zlib [[
if(USE_SYSTEM_ZLIB)
enable_language(C)
find_package(ZLIB CONFIG QUIET)
find_package(ZLIB MODULE QUIET)
if(TARGET ZLIB::ZLIB)
get_target_property(configurations ZLIB::ZLIB IMPORTED_CONFIGURATIONS)
if(configurations)
list(GET configurations 0 config)
get_target_property(zlib_location ZLIB::ZLIB "IMPORTED_LOCATION_${config}")
else()
get_target_property(zlib_location ZLIB::ZLIB "IMPORTED_LOCATION")
endif()
string(FIND "${zlib_location}" "${CMAKE_STAGING_PREFIX}/" staging_prefix_start)
if(NOT staging_prefix_start EQUAL 0)
message(STATUS "Found ${SYSTEM_NAME} zlib: ${zlib_location}")
set(BUILD_CONDITION 0)
endif()
elseif(NOT WIN32)
message(FATAL_ERROR "Missing system zlib on ${SYSTEM_NAME}")
endif()
endif()
]])
superbuild_package(
NAME zlib-patches
VERSION ${patch_version}
SOURCE
URL ${base_url}/libz-mingw-w64_${patch_version}.debian.tar.xz
URL_HASH ${patch_hash}
)
superbuild_package(
NAME zlib
VERSION ${patch_version}
DEPENDS
source:zlib-patches-${patch_version}
SOURCE
URL ${base_url}/libz-mingw-w64_${version}.orig.tar.xz
URL_HASH ${download_hash}
PATCH_COMMAND
"${CMAKE_COMMAND}"
-Dpackage=zlib-patches-${patch_version}
-P "${APPLY_PATCHES_SERIES}"
COMMAND
${CMAKE_COMMAND} -E
echo "set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)"
>> "<SOURCE_DIR>/CMakeLists.txt"
USING USE_SYSTEM_ZLIB patch_version
BUILD_CONDITION ${test_system_zlib}
BUILD [[
CMAKE_ARGS
"-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
-UCMAKE_STAGING_PREFIX # Has quirks with zlib sources
INSTALL_COMMAND
"${CMAKE_COMMAND}" --build . --target install/strip/fast -- DESTDIR=${DESTDIR}${INSTALL_DIR}
COMMAND
"${CMAKE_COMMAND}" -E copy
"<SOURCE_DIR>/../zlib-patches-${patch_version}/copyright"
"${DESTDIR}${CMAKE_STAGING_PREFIX}/share/doc/copyright/zlib-${patch_version}.txt"
]]
)
option(USE_SYSTEM_MINIZIP "Use the system Minizip if possible" ON)
set(test_system_minizip [[
if(${USE_SYSTEM_MINIZIP})
enable_language(C)
find_library(MINIZIP_LIBRARY NAMES minizip QUIET)
find_path(MINIZIP_INCLUDE_DIR NAMES minizip/mztools.h QUIET)
string(FIND "${MINIZIP_LIBRARY}" "${CMAKE_STAGING_PREFIX}/" staging_prefix_start)
if(MINIZIP_LIBRARY AND MINIZIP_INCLUDE_DIR AND NOT staging_prefix_start EQUAL 0)
message(STATUS "Found ${SYSTEM_NAME} Minizip: ${MINIZIP_LIBRARY}")
set(BUILD_CONDITION 0)
endif()
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(extra_flags "-Wno-parentheses-equality -Wno-unused-value" PARENT_SCOPE)
else()
set(extra_flags "" PARENT_SCOPE)
endif()
]])
string(CONCAT CMakeLists_txt [[
cmake_minimum_required(VERSION 3.1)
project(minizip C)
find_package(ZLIB CONFIG QUIET)
find_package(ZLIB MODULE QUIET)
include(GNUInstallDirs)
set(MINIZIP_SOURCE_DIR "" CACHE PATH "Path to minizip sources")
set(MINIZIP_SOURCES
"${MINIZIP_SOURCE_DIR}/ioapi.c"
"${MINIZIP_SOURCE_DIR}/mztools.c"
"${MINIZIP_SOURCE_DIR}/unzip.c"
"${MINIZIP_SOURCE_DIR}/zip.c"
)
if(WIN32)
list(APPEND MINIZIP_SOURCES "${MINIZIP_SOURCE_DIR}/iowin32.c")
endif()
set(MINIZIP_HEADERS
"${MINIZIP_SOURCE_DIR}/crypt.h"
"${MINIZIP_SOURCE_DIR}/ioapi.h"
"${MINIZIP_SOURCE_DIR}/mztools.h"
"${MINIZIP_SOURCE_DIR}/unzip.h"
"${MINIZIP_SOURCE_DIR}/zip.h"
)
if(WIN32)
list(APPEND MINIZIP_HEADERS "${MINIZIP_SOURCE_DIR}/iowin32.h")
endif()
add_library(minizip ${MINIZIP_SOURCES})
target_compile_definitions(minizip PUBLIC NOCRYPT USE_FILE32API)
target_link_libraries(minizip PUBLIC ZLIB::ZLIB)
install(TARGETS minizip
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
install(FILES ${MINIZIP_HEADERS}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/minizip"
)
]])
superbuild_package(
NAME minizip
VERSION zlib-${patch_version}
DEPENDS
source:zlib-${patch_version}
zlib
SOURCE_WRITE
CMakeLists.txt CMakeLists_txt
USING USE_SYSTEM_MINIZIP patch_version extra_flags
BUILD_CONDITION ${test_system_minizip}
BUILD [[
CMAKE_ARGS
"-DMINIZIP_SOURCE_DIR=<SOURCE_DIR>/../zlib-${patch_version}/contrib/minizip"
"-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
"-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} ${extra_flags}"
"-DCMAKE_BUILD_TYPE:STRING=$<CONFIG>"
-DBUILD_SHARED_LIBS=ON
INSTALL_COMMAND
"${CMAKE_COMMAND}" --build . --target install/strip/fast
COMMAND
"${CMAKE_COMMAND}" -E copy
"<SOURCE_DIR>/../zlib-patches-${patch_version}/copyright"
"${DESTDIR}${CMAKE_STAGING_PREFIX}/share/doc/copyright/minizip-zlib-${patch_version}.txt"
]]
)