summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:26:49 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:26:49 -0700
commitd004b047838a7e803818b4973a2e39e0ff8c1fa2 (patch)
tree9e8c804f78d73152c70d4ff24c6a7531a0d46782 /CMakeLists.txt
parentf6194ef39af5864f792412460c354cc339dde7d1 (diff)
downloadzlib-1.2.3.5.tar.gz
zlib-1.2.3.5.tar.bz2
zlib-1.2.3.5.zip
zlib 1.2.3.5v1.2.3.5
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt177
1 files changed, 177 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..19deaa5
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,177 @@
1cmake_minimum_required(VERSION 2.4.4)
2set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3
4project(zlib C)
5
6if(NOT DEFINED BUILD_SHARED_LIBS)
7 option(BUILD_SHARED_LIBS "Build a shared library form of zlib" ON)
8endif()
9
10include(CheckTypeSize)
11include(CheckFunctionExists)
12include(CheckIncludeFile)
13include(CheckCSourceCompiles)
14enable_testing()
15
16check_include_file(sys/types.h HAVE_SYS_TYPES_H)
17check_include_file(stdint.h HAVE_STDINT_H)
18check_include_file(stddef.h HAVE_STDDEF_H)
19
20#
21# Check to see if we have large file support
22#
23set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE)
24
25# We add these other definitions here because CheckTypeSize.cmake
26# in CMake 2.4.x does not automatically do so and we want
27# compatibility with CMake 2.4.x.
28if(HAVE_SYS_TYPES_H)
29 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
30endif()
31if(HAVE_STDINT_H)
32 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
33endif()
34if(HAVE_STDDEF_H)
35 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
36endif()
37
38check_type_size(off64_t OFF64_T)
39
40if(HAVE_OFF64_T)
41 add_definitions(-D_LARGEFILE64_SOURCE)
42endif()
43set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
44
45#
46# Check for fseeko
47#
48check_function_exists(fseeko HAVE_FSEEKO)
49if(NOT HAVE_FSEEKO)
50 add_definitions(-DNO_FSEEKO)
51endif()
52
53#
54# Check for unistd.h
55#
56check_include_file(unistd.h HAVE_UNISTD_H)
57
58#
59# Check for errno.h
60check_include_file(errno.h HAVE_ERRNO_H)
61if(NOT HAVE_ERRNO_H)
62 add_definitions(-DNO_ERRNO_H)
63endif()
64
65#
66# Check for mmap support
67#
68set(mmap_test_code "
69#include <sys/types.h>
70#include <sys/mman.h>
71#include <sys/stat.h>
72caddr_t hello() {
73 return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
74}
75int main() { return 0; }
76")
77check_c_source_compiles("${mmap_test_code}" USE_MMAP)
78if(USE_MMAP)
79 add_definitions(-DUSE_MMAP)
80endif()
81
82#
83# Create the zlibdefs.h file.
84# Note: we create it in CMAKE_CURRENT_SOURCE_DIR instead
85# of CMAKE_CURRENT_BINARY_DIR because an empty zlibdefs.h
86# is shipped with zlib in the source tree.
87configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h.cmakein
88 ${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h)
89
90if(MSVC)
91 set(CMAKE_DEBUG_POSTFIX "D")
92 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
93 add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
94endif()
95
96#============================================================================
97# zlib
98#============================================================================
99
100set(ZLIB_PUBLIC_HDRS
101 zconf.h
102 zlib.h
103 zlibdefs.h
104)
105set(ZLIB_PRIVATE_HDRS
106 crc32.h
107 deflate.h
108 gzguts.h
109 inffast.h
110 inffixed.h
111 inflate.h
112 inftrees.h
113 trees.h
114 zutil.h
115)
116set(ZLIB_SRCS
117 adler32.c
118 compress.c
119 crc32.c
120 deflate.c
121 gzclose.c
122 gzio.c
123 gzlib.c
124 gzread.c
125 gzwrite.c
126 inflate.c
127 infback.c
128 inftrees.c
129 inffast.c
130 trees.c
131 uncompr.c
132 zutil.c
133)
134
135add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
136set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
137set_target_properties(zlib PROPERTIES VERSION 1.2.3.4)
138set_target_properties(zlib PROPERTIES SOVERSION 1)
139if(UNIX)
140 # On unix like platforms the library is almost always called libz
141 set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
142endif()
143
144if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
145 install(TARGETS zlib
146 RUNTIME DESTINATION bin
147 ARCHIVE DESTINATION lib
148 LIBRARY DESTINATION lib )
149endif()
150if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
151 install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include)
152endif()
153if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
154 install(FILES zlib.3 DESTINATION share/man/man3)
155endif()
156
157#============================================================================
158# Example binaries
159#============================================================================
160
161add_executable(example example.c)
162target_link_libraries(example zlib)
163add_test(example example)
164
165add_executable(minigzip minigzip.c)
166target_link_libraries(minigzip zlib)
167
168if(HAVE_OFF64_T)
169 add_executable(example64 example.c)
170 target_link_libraries(example64 zlib)
171 set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
172 add_test(example64 example64)
173
174 add_executable(minigzip64 minigzip.c)
175 target_link_libraries(minigzip64 zlib)
176 set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
177endif()