1 cmake_minimum_required(VERSION 2.4.4)
2 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
6 if(NOT DEFINED BUILD_SHARED_LIBS)
7 option(BUILD_SHARED_LIBS "Build a shared library form of zlib" ON)
10 include(CheckTypeSize)
11 include(CheckFunctionExists)
12 include(CheckIncludeFile)
13 include(CheckCSourceCompiles)
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)
21 # Check to see if we have large file support
23 set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE)
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.
29 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
32 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
35 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
38 check_type_size(off64_t OFF64_T)
41 add_definitions(-D_LARGEFILE64_SOURCE)
43 set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
48 check_function_exists(fseeko HAVE_FSEEKO)
50 add_definitions(-DNO_FSEEKO)
56 check_include_file(unistd.h HAVE_UNISTD_H)
60 check_include_file(errno.h HAVE_ERRNO_H)
62 add_definitions(-DNO_ERRNO_H)
66 # Check for mmap support
69 #include <sys/types.h>
73 return mmap((caddr_t)0, (off_t)0, PROT_READ, MAP_SHARED, 0, (off_t)0);
75 int main() { return 0; }
77 check_c_source_compiles("${mmap_test_code}" USE_MMAP)
79 add_definitions(-DUSE_MMAP)
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)
91 set(CMAKE_DEBUG_POSTFIX "D")
92 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
93 add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
96 #============================================================================
98 #============================================================================
105 set(ZLIB_PRIVATE_HDRS
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)
140 # On unix like platforms the library is almost always called libz
141 set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
144 if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
146 RUNTIME DESTINATION bin
147 ARCHIVE DESTINATION lib
148 LIBRARY DESTINATION lib )
150 if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
151 install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include)
153 if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
154 install(FILES zlib.3 DESTINATION share/man/man3)
157 #============================================================================
159 #============================================================================
161 add_executable(example example.c)
162 target_link_libraries(example zlib)
163 add_test(example example)
165 add_executable(minigzip minigzip.c)
166 target_link_libraries(minigzip zlib)
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)
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")