]> git.lizzy.rs Git - zlib.git/blob - CMakeLists.txt
zlib 1.2.3.5
[zlib.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.4.4)
2 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3
4 project(zlib C)
5
6 if(NOT DEFINED BUILD_SHARED_LIBS)
7     option(BUILD_SHARED_LIBS "Build a shared library form of zlib" ON)
8 endif()
9
10 include(CheckTypeSize)
11 include(CheckFunctionExists)
12 include(CheckIncludeFile)
13 include(CheckCSourceCompiles)
14 enable_testing()
15
16 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
17 check_include_file(stdint.h    HAVE_STDINT_H)
18 check_include_file(stddef.h    HAVE_STDDEF_H)
19
20 #
21 # Check to see if we have large file support
22 #
23 set(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.
28 if(HAVE_SYS_TYPES_H)
29     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
30 endif()
31 if(HAVE_STDINT_H)
32     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
33 endif()
34 if(HAVE_STDDEF_H)
35     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
36 endif()
37
38 check_type_size(off64_t OFF64_T)
39
40 if(HAVE_OFF64_T)
41    add_definitions(-D_LARGEFILE64_SOURCE)
42 endif()
43 set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
44
45 #
46 # Check for fseeko
47 #
48 check_function_exists(fseeko HAVE_FSEEKO)
49 if(NOT HAVE_FSEEKO)
50     add_definitions(-DNO_FSEEKO)
51 endif()
52
53 #
54 # Check for unistd.h
55 #
56 check_include_file(unistd.h HAVE_UNISTD_H)
57
58 #
59 # Check for errno.h
60 check_include_file(errno.h HAVE_ERRNO_H)
61 if(NOT HAVE_ERRNO_H)
62    add_definitions(-DNO_ERRNO_H)
63 endif()
64
65 #
66 # Check for mmap support
67 #
68 set(mmap_test_code "
69 #include <sys/types.h>
70 #include <sys/mman.h>
71 #include <sys/stat.h>
72 caddr_t hello() {
73   return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
74 }
75 int main() { return 0; }
76 ")
77 check_c_source_compiles("${mmap_test_code}" USE_MMAP)
78 if(USE_MMAP)
79     add_definitions(-DUSE_MMAP)
80 endif()
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.
87 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h.cmakein
88                ${CMAKE_CURRENT_SOURCE_DIR}/zlibdefs.h)
89
90 if(MSVC)
91     set(CMAKE_DEBUG_POSTFIX "D")
92     add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
93     add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
94 endif()
95
96 #============================================================================
97 # zlib
98 #============================================================================
99
100 set(ZLIB_PUBLIC_HDRS
101     zconf.h
102     zlib.h
103     zlibdefs.h
104 )
105 set(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 )
116 set(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
135 add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
136 set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
137 set_target_properties(zlib PROPERTIES VERSION 1.2.3.4)
138 set_target_properties(zlib PROPERTIES SOVERSION 1)
139 if(UNIX)
140    # On unix like platforms the library is almost always called libz
141    set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
142 endif()
143
144 if(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 )
149 endif()
150 if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
151     install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include)
152 endif()
153 if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
154     install(FILES zlib.3 DESTINATION share/man/man3)
155 endif()
156
157 #============================================================================
158 # Example binaries
159 #============================================================================
160
161 add_executable(example example.c)
162 target_link_libraries(example zlib)
163 add_test(example example)
164
165 add_executable(minigzip minigzip.c)
166 target_link_libraries(minigzip zlib)
167
168 if(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")
177 endif()