Skip to content

Commit 50144cf

Browse files
authored
Merge pull request #589 from dstoup/patch-zlib-libname
Patch zlib libname
2 parents 7b883ef + c9b7616 commit 50144cf

File tree

3 files changed

+251
-96
lines changed

3 files changed

+251
-96
lines changed

CMake/External_ZLib.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ ExternalProject_Add(ZLib
66
DOWNLOAD_NAME ${zlib_dlname}
77
${COMMON_EP_ARGS}
88
${COMMON_CMAKE_EP_ARGS}
9+
PATCH_COMMAND ${CMAKE_COMMAND}
10+
-DZLib_patch=${fletch_SOURCE_DIR}/Patches/ZLib
11+
-DZLib_source=${fletch_BUILD_PREFIX}/src/ZLib
12+
-P ${fletch_SOURCE_DIR}/Patches/ZLib/Patch.cmake
913
CMAKE_ARGS
1014
${COMMON_CMAKE_ARGS}
1115
-DBUILD_SHARED_LIBS:BOOL=ON

Patches/ZLib/CMakeLists.txt

Lines changed: 246 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,248 @@
1-
cmake_minimum_required(VERSION 2.8)
2-
3-
PROJECT(ZLIB)
4-
5-
SET(ZLIB_MANGLE_PREFIX "" CACHE STRING "Mangle prefix. For example 'cm_zlib_', 'z_', ...")
6-
7-
SET(ZLIB_VERSION_MAJOR "1")
8-
SET(ZLIB_VERSION_MINOR "2")
9-
SET(ZLIB_VERSION_PATCH "9")
10-
11-
INCLUDE_DIRECTORIES(
12-
"${ZLIB_SOURCE_DIR}"
13-
"${ZLIB_SOURCE_DIR}"
14-
"${ZLIB_BINARY_DIR}"
15-
)
16-
17-
# source files for zlib
18-
SET(ZLIB_SRCS
19-
adler32.c compress.c crc32.c deflate.c gzio.c inffast.c
20-
inflate.c inftrees.c trees.c uncompr.c zutil.c
21-
)
22-
23-
# for windows add the .def and .rc files to the source list
24-
# if building shared libs
25-
IF(WIN32)
26-
IF(BUILD_SHARED_LIBS)
27-
SET(ZLIB_DLL 1)
28-
IF(NOT UNIX)
29-
IF(NOT BORLAND)
30-
IF(NOT MINGW)
31-
CONFIGURE_FILE(zlib.def.in ${ZLIB_BINARY_DIR}/zlib.def)
32-
SET(ZLIB_SRCS ${ZLIB_SRCS} ${ZLIB_BINARY_DIR}/zlib.def zlib.rc)
33-
ENDIF(NOT MINGW)
34-
ENDIF(NOT BORLAND)
35-
ENDIF(NOT UNIX)
36-
ENDIF(BUILD_SHARED_LIBS)
37-
ENDIF(WIN32)
38-
39-
CONFIGURE_FILE(${ZLIB_SOURCE_DIR}/.NoDartCoverage
40-
${ZLIB_BINARY_DIR}/.NoDartCoverage)
41-
CONFIGURE_FILE(${ZLIB_SOURCE_DIR}/zlibDllConfig.h.in
42-
${ZLIB_BINARY_DIR}/zlibDllConfig.h)
43-
CONFIGURE_FILE(${ZLIB_SOURCE_DIR}/zlib_mangle.h.in
44-
${ZLIB_BINARY_DIR}/zlib_mangle.h)
45-
46-
FOREACH(name zlib zconf)
47-
CONFIGURE_FILE(${ZLIB_SOURCE_DIR}/${name}.h
48-
${ZLIB_BINARY_DIR}/${name}.h COPYONLY)
49-
ENDFOREACH(name)
50-
51-
ADD_LIBRARY(zlib ${ZLIB_SRCS})
52-
53-
# To fix compilation problem: relocation R_X86_64_32 against `a local symbol' can not be
54-
# used when making a shared object; recompile with -fPIC
55-
# See http://www.cmake.org/pipermail/cmake/2007-May/014350.html
1+
cmake_minimum_required(VERSION 2.4.4)
2+
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3+
4+
project(zlib C)
5+
6+
set(VERSION "1.2.9")
7+
8+
option(ASM686 "Enable building i686 assembly implementation")
9+
option(AMD64 "Enable building amd64 assembly implementation")
10+
11+
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
12+
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
13+
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
14+
set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
15+
set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
16+
17+
include(CheckTypeSize)
18+
include(CheckFunctionExists)
19+
include(CheckIncludeFile)
20+
include(CheckCSourceCompiles)
21+
enable_testing()
22+
23+
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
24+
check_include_file(stdint.h HAVE_STDINT_H)
25+
check_include_file(stddef.h HAVE_STDDEF_H)
26+
27+
#
28+
# Check to see if we have large file support
29+
#
30+
set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
31+
# We add these other definitions here because CheckTypeSize.cmake
32+
# in CMake 2.4.x does not automatically do so and we want
33+
# compatibility with CMake 2.4.x.
34+
if(HAVE_SYS_TYPES_H)
35+
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
36+
endif()
37+
if(HAVE_STDINT_H)
38+
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
39+
endif()
40+
if(HAVE_STDDEF_H)
41+
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
42+
endif()
43+
check_type_size(off64_t OFF64_T)
44+
if(HAVE_OFF64_T)
45+
add_definitions(-D_LARGEFILE64_SOURCE=1)
46+
endif()
47+
set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
48+
49+
#
50+
# Check for fseeko
51+
#
52+
check_function_exists(fseeko HAVE_FSEEKO)
53+
if(NOT HAVE_FSEEKO)
54+
add_definitions(-DNO_FSEEKO)
55+
endif()
56+
57+
#
58+
# Check for unistd.h
5659
#
57-
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
58-
SET_TARGET_PROPERTIES(zlib PROPERTIES COMPILE_FLAGS "-fPIC")
59-
ENDIF()
60-
61-
# Configure install locations. This allows parent projects to modify
62-
# the install location.
63-
IF(NOT ZLIB_INSTALL_BIN_DIR)
64-
SET(ZLIB_INSTALL_BIN_DIR bin)
65-
ENDIF()
66-
67-
IF(NOT ZLIB_INSTALL_INCLUDE_DIR)
68-
SET(ZLIB_INSTALL_INCLUDE_DIR include)
69-
ENDIF()
70-
71-
IF(NOT ZLIB_INSTALL_LIB_DIR)
72-
SET(ZLIB_INSTALL_LIB_DIR lib)
73-
ENDIF()
74-
75-
IF(NOT ZLIB_INSTALL_DOC_DIR)
76-
SET(ZLIB_INSTALL_DOC_DIR
77-
doc/zlib-${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}
60+
check_include_file(unistd.h Z_HAVE_UNISTD_H)
61+
62+
if(MSVC)
63+
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
64+
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
65+
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
66+
endif()
67+
68+
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
69+
# If we're doing an out of source build and the user has a zconf.h
70+
# in their source tree...
71+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
72+
message(STATUS "Renaming")
73+
message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h")
74+
message(STATUS "to 'zconf.h.included' because this file is included with zlib")
75+
message(STATUS "but CMake generates it automatically in the build directory.")
76+
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included)
77+
endif()
78+
endif()
79+
80+
set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc)
81+
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
82+
${ZLIB_PC} @ONLY)
83+
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
84+
${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
85+
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
86+
87+
88+
#============================================================================
89+
# zlib
90+
#============================================================================
91+
92+
set(ZLIB_PUBLIC_HDRS
93+
${CMAKE_CURRENT_BINARY_DIR}/zconf.h
94+
zlib.h
95+
)
96+
set(ZLIB_PRIVATE_HDRS
97+
crc32.h
98+
deflate.h
99+
gzguts.h
100+
inffast.h
101+
inffixed.h
102+
inflate.h
103+
inftrees.h
104+
trees.h
105+
zutil.h
106+
)
107+
set(ZLIB_SRCS
108+
adler32.c
109+
compress.c
110+
crc32.c
111+
deflate.c
112+
gzclose.c
113+
gzlib.c
114+
gzread.c
115+
gzwrite.c
116+
inflate.c
117+
infback.c
118+
inftrees.c
119+
inffast.c
120+
trees.c
121+
uncompr.c
122+
zutil.c
123+
)
124+
125+
if(NOT MINGW)
126+
set(ZLIB_DLL_SRCS
127+
win32/zlib1.rc # If present will override custom build rule below.
78128
)
79-
ENDIF()
80-
81-
# Install library
82-
INSTALL(TARGETS zlib
83-
RUNTIME DESTINATION ${ZLIB_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
84-
LIBRARY DESTINATION ${ZLIB_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
85-
ARCHIVE DESTINATION ${ZLIB_INSTALL_LIB_DIR} COMPONENT Development
86-
)
87-
88-
# Install public headers
89-
INSTALL(FILES
90-
zlib.h
91-
zconf.h
92-
${ZLIB_BINARY_DIR}/zlib_mangle.h
93-
${ZLIB_BINARY_DIR}/zlibDllConfig.h
94-
DESTINATION ${ZLIB_INSTALL_INCLUDE_DIR} COMPONENT Development
95-
)
96-
97-
INSTALL(FILES Copyright.txt DESTINATION ${ZLIB_INSTALL_DOC_DIR} COMPONENT RuntimeLibraries)
129+
endif()
130+
131+
if(CMAKE_COMPILER_IS_GNUCC)
132+
if(ASM686)
133+
set(ZLIB_ASMS contrib/asm686/match.S)
134+
elseif (AMD64)
135+
set(ZLIB_ASMS contrib/amd64/amd64-match.S)
136+
endif ()
137+
138+
if(ZLIB_ASMS)
139+
add_definitions(-DASMV)
140+
set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE)
141+
endif()
142+
endif()
143+
144+
if(MSVC)
145+
if(ASM686)
146+
ENABLE_LANGUAGE(ASM_MASM)
147+
set(ZLIB_ASMS
148+
contrib/masmx86/inffas32.asm
149+
contrib/masmx86/match686.asm
150+
)
151+
elseif (AMD64)
152+
ENABLE_LANGUAGE(ASM_MASM)
153+
set(ZLIB_ASMS
154+
contrib/masmx64/gvmat64.asm
155+
contrib/masmx64/inffasx64.asm
156+
)
157+
endif()
158+
159+
if(ZLIB_ASMS)
160+
add_definitions(-DASMV -DASMINF)
161+
endif()
162+
endif()
163+
164+
# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
165+
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
166+
string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
167+
"\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
168+
169+
if(MINGW)
170+
# This gets us DLL resource information when compiling on MinGW.
171+
if(NOT CMAKE_RC_COMPILER)
172+
set(CMAKE_RC_COMPILER windres.exe)
173+
endif()
174+
175+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
176+
COMMAND ${CMAKE_RC_COMPILER}
177+
-D GCC_WINDRES
178+
-I ${CMAKE_CURRENT_SOURCE_DIR}
179+
-I ${CMAKE_CURRENT_BINARY_DIR}
180+
-o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
181+
-i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
182+
set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
183+
endif(MINGW)
184+
185+
add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
186+
add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
187+
set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
188+
set_target_properties(zlib PROPERTIES SOVERSION 1)
189+
190+
if(NOT CYGWIN)
191+
# This property causes shared libraries on Linux to have the full version
192+
# encoded into their final filename. We disable this on Cygwin because
193+
# it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
194+
# seems to be the default.
195+
#
196+
# This has no effect with MSVC, on that platform the version info for
197+
# the DLL comes from the resource file win32/zlib1.rc
198+
set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
199+
endif()
200+
201+
if(UNIX)
202+
# On unix-like platforms the library is almost always called libz
203+
set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)
204+
if(NOT APPLE)
205+
set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
206+
endif()
207+
elseif(BUILD_SHARED_LIBS AND WIN32)
208+
# Creates zlib1.dll when building shared library version
209+
set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
210+
endif()
211+
212+
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
213+
install(TARGETS zlib zlibstatic
214+
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
215+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
216+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
217+
endif()
218+
if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
219+
install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}")
220+
endif()
221+
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
222+
install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3")
223+
endif()
224+
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
225+
install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
226+
endif()
227+
228+
#============================================================================
229+
# Example binaries
230+
#============================================================================
231+
232+
add_executable(example test/example.c)
233+
target_link_libraries(example zlib)
234+
add_test(example example)
235+
236+
add_executable(minigzip test/minigzip.c)
237+
target_link_libraries(minigzip zlib)
238+
239+
if(HAVE_OFF64_T)
240+
add_executable(example64 test/example.c)
241+
target_link_libraries(example64 zlib)
242+
set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
243+
add_test(example64 example64)
244+
245+
add_executable(minigzip64 test/minigzip.c)
246+
target_link_libraries(minigzip64 zlib)
247+
set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
248+
endif()

Patches/ZLib/Patch.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# External_Zlib.cmake
44
#-
55

6-
file(COPY ${zlib_patch}/CMakeLists.txt DESTINATION ${zlib_source})
6+
file(COPY ${ZLib_patch}/CMakeLists.txt DESTINATION ${ZLib_source})

0 commit comments

Comments
 (0)