]> git.lizzy.rs Git - zlib.git/blob - CMakeLists.txt
zlib 1.2.3.7
[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 # We add these other definitions here because CheckTypeSize.cmake
25 # in CMake 2.4.x does not automatically do so and we want
26 # compatibility with CMake 2.4.x.
27 if(HAVE_SYS_TYPES_H)
28     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
29 endif()
30 if(HAVE_STDINT_H)
31     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
32 endif()
33 if(HAVE_STDDEF_H)
34     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
35 endif()
36 check_type_size(off64_t OFF64_T)
37 if(HAVE_OFF64_T)
38    add_definitions(-D_LARGEFILE64_SOURCE)
39 endif()
40 set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
41
42 #
43 # Check for fseeko
44 #
45 check_function_exists(fseeko HAVE_FSEEKO)
46 if(NOT HAVE_FSEEKO)
47     add_definitions(-DNO_FSEEKO)
48 endif()
49
50 #
51 # Check for unistd.h
52 #
53 check_include_file(unistd.h HAVE_UNISTD_H)
54
55 #
56 # Check for errno.h
57 check_include_file(errno.h HAVE_ERRNO_H)
58 if(NOT HAVE_ERRNO_H)
59    add_definitions(-DNO_ERRNO_H)
60 endif()
61
62 if(MSVC)
63     set(CMAKE_DEBUG_POSTFIX "d")
64     add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
65     add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
66 endif()
67
68 #============================================================================
69 # zlib
70 #============================================================================
71
72 set(ZLIB_PUBLIC_HDRS
73     zconf.h
74     zlib.h
75 )
76 set(ZLIB_PRIVATE_HDRS
77     crc32.h
78     deflate.h
79     gzguts.h
80     inffast.h
81     inffixed.h
82     inflate.h
83     inftrees.h
84     trees.h
85     zutil.h
86 )
87 set(ZLIB_SRCS
88     adler32.c
89     compress.c
90     crc32.c
91     deflate.c
92     gzclose.c
93     gzio.c
94     gzlib.c
95     gzread.c
96     gzwrite.c
97     inflate.c
98     infback.c
99     inftrees.c
100     inffast.c
101     trees.c
102     uncompr.c
103     zutil.c
104     win32/zlib1.rc
105 )
106
107 # parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
108 file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
109 string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([0-9A-Za-z.]+)\".*"
110     "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
111
112 if(MINGW)
113     # This gets us DLL resource information when compiling on MinGW.
114     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
115                        COMMAND windres.exe
116                             -D GCC_WINDRES
117                             -I ${CMAKE_CURRENT_SOURCE_DIR}
118                             -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
119                             -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
120     set(ZLIB_SRCS ${ZLIB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
121 endif(MINGW)
122
123 add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
124 set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
125
126 set_target_properties(zlib PROPERTIES SOVERSION 1)
127
128 if(NOT CYGWIN)
129     # This property causes shared libraries on Linux to have the full version
130     # encoded into their final filename.  We disable this on Cygwin because
131     # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
132     # seems to be the default.
133     #
134     # This has no effect with MSVC, on that platform the version info for
135     # the DLL comes from the resource file win32/zlib1.rc
136     set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
137 endif()
138
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 elseif(BUILD_SHARED_LIBS AND WIN32)
143     # Creates zlib1.dll when building shared library version
144     set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
145 endif()
146
147 if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
148     install(TARGETS zlib
149         RUNTIME DESTINATION bin
150         ARCHIVE DESTINATION lib
151         LIBRARY DESTINATION lib )
152 endif()
153 if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
154     install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include)
155 endif()
156 if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
157     install(FILES zlib.3 DESTINATION share/man/man3)
158 endif()
159
160 #============================================================================
161 # Example binaries
162 #============================================================================
163
164 add_executable(example example.c)
165 target_link_libraries(example zlib)
166 add_test(example example)
167
168 add_executable(minigzip minigzip.c)
169 target_link_libraries(minigzip zlib)
170
171 if(HAVE_OFF64_T)
172     add_executable(example64 example.c)
173     target_link_libraries(example64 zlib)
174     set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
175     add_test(example64 example64)
176
177     add_executable(minigzip64 minigzip.c)
178     target_link_libraries(minigzip64 zlib)
179     set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
180 endif()