• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required(VERSION 2.4.4)
2set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3
4project(zlib C)
5
6set(VERSION "1.2.11")
7
8option(ASM686 "Enable building i686 assembly implementation")
9option(AMD64 "Enable building amd64 assembly implementation")
10
11set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
12set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
13set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
14set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
15set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
16
17include(CheckTypeSize)
18include(CheckFunctionExists)
19include(CheckIncludeFile)
20include(CheckCSourceCompiles)
21enable_testing()
22
23check_include_file(sys/types.h HAVE_SYS_TYPES_H)
24check_include_file(stdint.h    HAVE_STDINT_H)
25check_include_file(stddef.h    HAVE_STDDEF_H)
26
27#
28# Check to see if we have large file support
29#
30set(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.
34if(HAVE_SYS_TYPES_H)
35    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
36endif()
37if(HAVE_STDINT_H)
38    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
39endif()
40if(HAVE_STDDEF_H)
41    list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
42endif()
43check_type_size(off64_t OFF64_T)
44if(HAVE_OFF64_T)
45   add_definitions(-D_LARGEFILE64_SOURCE=1)
46endif()
47set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
48
49#
50# Check for fseeko
51#
52check_function_exists(fseeko HAVE_FSEEKO)
53if(NOT HAVE_FSEEKO)
54    add_definitions(-DNO_FSEEKO)
55endif()
56
57#
58# Check for unistd.h
59#
60check_include_file(unistd.h Z_HAVE_UNISTD_H)
61
62if(MSVC)
63    set(CMAKE_DEBUG_POSTFIX "d")
64    add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
65    add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
66    include_directories(${CMAKE_CURRENT_SOURCE_DIR})
67endif()
68
69if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
70    # If we're doing an out of source build and the user has a zconf.h
71    # in their source tree...
72    if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
73        message(STATUS "Renaming")
74        message(STATUS "    ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h")
75        message(STATUS "to 'zconf.h.included' because this file is included with zlib")
76        message(STATUS "but CMake generates it automatically in the build directory.")
77        file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included)
78  endif()
79endif()
80
81set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc)
82configure_file( ${PANDA_THIRD_PARTY_SOURCES_DIR}/zlib/zlib.pc.cmakein
83		${ZLIB_PC} @ONLY)
84configure_file(	${PANDA_THIRD_PARTY_SOURCES_DIR}/zlib/zconf.h.cmakein
85		${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
86include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
87
88
89#============================================================================
90# zlib
91#============================================================================
92
93set(ZLIB_PUBLIC_HDRS
94    ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
95    ${ZLIB_ROOT}/zlib.h
96)
97set(ZLIB_PRIVATE_HDRS
98    ${ZLIB_ROOT}/crc32.h
99    ${ZLIB_ROOT}/deflate.h
100    ${ZLIB_ROOT}/gzguts.h
101    ${ZLIB_ROOT}/inffast.h
102    ${ZLIB_ROOT}/inffixed.h
103    ${ZLIB_ROOT}/inflate.h
104    ${ZLIB_ROOT}/inftrees.h
105    ${ZLIB_ROOT}/trees.h
106    ${ZLIB_ROOT}/zutil.h
107)
108set(ZLIB_SRCS
109    ${ZLIB_ROOT}/adler32.c
110    ${ZLIB_ROOT}/compress.c
111    ${ZLIB_ROOT}/contrib/minizip/ioapi.c
112    ${ZLIB_ROOT}/contrib/minizip/unzip.c
113    ${ZLIB_ROOT}/contrib/minizip/zip.c
114    ${ZLIB_ROOT}/crc32.c
115    ${ZLIB_ROOT}/deflate.c
116    ${ZLIB_ROOT}/gzclose.c
117    ${ZLIB_ROOT}/gzlib.c
118    ${ZLIB_ROOT}/gzread.c
119    ${ZLIB_ROOT}/gzwrite.c
120    ${ZLIB_ROOT}/inflate.c
121    ${ZLIB_ROOT}/infback.c
122    ${ZLIB_ROOT}/inftrees.c
123    ${ZLIB_ROOT}/inffast.c
124    ${ZLIB_ROOT}/trees.c
125    ${ZLIB_ROOT}/uncompr.c
126    ${ZLIB_ROOT}/zutil.c
127)
128
129if(NOT MINGW)
130    set(ZLIB_DLL_SRCS
131        ${ZLIB_ROOT}/win32/zlib1.rc # If present will override custom build rule below.
132    )
133endif()
134
135if(CMAKE_COMPILER_IS_GNUCC)
136    if(ASM686)
137        set(ZLIB_ASMS  ${ZLIB_ROOT}/contrib/asm686/match.S)
138    elseif (AMD64)
139        set(ZLIB_ASMS  ${ZLIB_ROOT}/contrib/amd64/amd64-match.S)
140    endif ()
141
142	if(ZLIB_ASMS)
143		add_definitions(-DASMV)
144		set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE)
145	endif()
146endif()
147
148if(MSVC)
149    if(ASM686)
150		ENABLE_LANGUAGE(ASM_MASM)
151        set(ZLIB_ASMS
152            ${ZLIB_ROOT}/contrib/masmx86/inffas32.asm
153            ${ZLIB_ROOT}/contrib/masmx86/match686.asm
154		)
155    elseif (AMD64)
156		ENABLE_LANGUAGE(ASM_MASM)
157        set(ZLIB_ASMS
158            ${ZLIB_ROOT}/contrib/masmx64/gvmat64.asm
159            ${ZLIB_ROOT}/contrib/masmx64/inffasx64.asm
160		)
161    endif()
162
163	if(ZLIB_ASMS)
164		add_definitions(-DASMV -DASMINF)
165	endif()
166endif()
167
168# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
169file(READ ${PANDA_THIRD_PARTY_SOURCES_DIR}/zlib/zlib.h _zlib_h_contents)
170string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
171    "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
172
173add_library(zlib STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
174target_include_directories(zlib PUBLIC ${ZLIB_ROOT})
175
176target_compile_options(zlib PUBLIC -Wno-return-type-c-linkage)
177
178if(HOST_TOOLS)
179    set_target_properties(zlib
180        PROPERTIES
181        ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/third_party/zlib
182        LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/third_party/zlib
183        RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/third_party/zlib
184    )
185endif()
186
187# NB! We always build zlib statically, but there seems
188# no obvious reasons for that. If we reconsider, the logic
189# below should be replaced with something like:
190#
191# add_library(zlib ${PANDA_DEFAULT_LIB_TYPE} zlib.c)
192#
193# **Besides** build of host tools should be fixed to
194# take into account new shared library
195if(NOT PANDA_TARGET_WINDOWS)
196    target_compile_options(zlib PRIVATE -fPIC)
197endif()
198