1 1.1.1.1.4.2 pgoyette cmake_minimum_required(VERSION 2.4.4) 2 1.1.1.1.4.2 pgoyette set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) 3 1.1.1.1.4.2 pgoyette 4 1.1.1.1.4.2 pgoyette project(zlib C) 5 1.1.1.1.4.2 pgoyette 6 1.1.1.1.4.2 pgoyette set(VERSION "1.2.10") 7 1.1.1.1.4.2 pgoyette 8 1.1.1.1.4.2 pgoyette option(ASM686 "Enable building i686 assembly implementation") 9 1.1.1.1.4.2 pgoyette option(AMD64 "Enable building amd64 assembly implementation") 10 1.1.1.1.4.2 pgoyette 11 1.1.1.1.4.2 pgoyette set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") 12 1.1.1.1.4.2 pgoyette set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") 13 1.1.1.1.4.2 pgoyette set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") 14 1.1.1.1.4.2 pgoyette set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages") 15 1.1.1.1.4.2 pgoyette set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") 16 1.1.1.1.4.2 pgoyette 17 1.1.1.1.4.2 pgoyette include(CheckTypeSize) 18 1.1.1.1.4.2 pgoyette include(CheckFunctionExists) 19 1.1.1.1.4.2 pgoyette include(CheckIncludeFile) 20 1.1.1.1.4.2 pgoyette include(CheckCSourceCompiles) 21 1.1.1.1.4.2 pgoyette enable_testing() 22 1.1.1.1.4.2 pgoyette 23 1.1.1.1.4.2 pgoyette check_include_file(sys/types.h HAVE_SYS_TYPES_H) 24 1.1.1.1.4.2 pgoyette check_include_file(stdint.h HAVE_STDINT_H) 25 1.1.1.1.4.2 pgoyette check_include_file(stddef.h HAVE_STDDEF_H) 26 1.1.1.1.4.2 pgoyette 27 1.1.1.1.4.2 pgoyette # 28 1.1.1.1.4.2 pgoyette # Check to see if we have large file support 29 1.1.1.1.4.2 pgoyette # 30 1.1.1.1.4.2 pgoyette set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1) 31 1.1.1.1.4.2 pgoyette # We add these other definitions here because CheckTypeSize.cmake 32 1.1.1.1.4.2 pgoyette # in CMake 2.4.x does not automatically do so and we want 33 1.1.1.1.4.2 pgoyette # compatibility with CMake 2.4.x. 34 1.1.1.1.4.2 pgoyette if(HAVE_SYS_TYPES_H) 35 1.1.1.1.4.2 pgoyette list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H) 36 1.1.1.1.4.2 pgoyette endif() 37 1.1.1.1.4.2 pgoyette if(HAVE_STDINT_H) 38 1.1.1.1.4.2 pgoyette list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H) 39 1.1.1.1.4.2 pgoyette endif() 40 1.1.1.1.4.2 pgoyette if(HAVE_STDDEF_H) 41 1.1.1.1.4.2 pgoyette list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) 42 1.1.1.1.4.2 pgoyette endif() 43 1.1.1.1.4.2 pgoyette check_type_size(off64_t OFF64_T) 44 1.1.1.1.4.2 pgoyette if(HAVE_OFF64_T) 45 1.1.1.1.4.2 pgoyette add_definitions(-D_LARGEFILE64_SOURCE=1) 46 1.1.1.1.4.2 pgoyette endif() 47 1.1.1.1.4.2 pgoyette set(CMAKE_REQUIRED_DEFINITIONS) # clear variable 48 1.1.1.1.4.2 pgoyette 49 1.1.1.1.4.2 pgoyette # 50 1.1.1.1.4.2 pgoyette # Check for fseeko 51 1.1.1.1.4.2 pgoyette # 52 1.1.1.1.4.2 pgoyette check_function_exists(fseeko HAVE_FSEEKO) 53 1.1.1.1.4.2 pgoyette if(NOT HAVE_FSEEKO) 54 1.1.1.1.4.2 pgoyette add_definitions(-DNO_FSEEKO) 55 1.1.1.1.4.2 pgoyette endif() 56 1.1.1.1.4.2 pgoyette 57 1.1.1.1.4.2 pgoyette # 58 1.1.1.1.4.2 pgoyette # Check for unistd.h 59 1.1.1.1.4.2 pgoyette # 60 1.1.1.1.4.2 pgoyette check_include_file(unistd.h Z_HAVE_UNISTD_H) 61 1.1.1.1.4.2 pgoyette 62 1.1.1.1.4.2 pgoyette if(MSVC) 63 1.1.1.1.4.2 pgoyette set(CMAKE_DEBUG_POSTFIX "d") 64 1.1.1.1.4.2 pgoyette add_definitions(-D_CRT_SECURE_NO_DEPRECATE) 65 1.1.1.1.4.2 pgoyette add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) 66 1.1.1.1.4.2 pgoyette include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 67 1.1.1.1.4.2 pgoyette endif() 68 1.1.1.1.4.2 pgoyette 69 1.1.1.1.4.2 pgoyette if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) 70 1.1.1.1.4.2 pgoyette # If we're doing an out of source build and the user has a zconf.h 71 1.1.1.1.4.2 pgoyette # in their source tree... 72 1.1.1.1.4.2 pgoyette if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h) 73 1.1.1.1.4.2 pgoyette message(STATUS "Renaming") 74 1.1.1.1.4.2 pgoyette message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h") 75 1.1.1.1.4.2 pgoyette message(STATUS "to 'zconf.h.included' because this file is included with zlib") 76 1.1.1.1.4.2 pgoyette message(STATUS "but CMake generates it automatically in the build directory.") 77 1.1.1.1.4.2 pgoyette file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included) 78 1.1.1.1.4.2 pgoyette endif() 79 1.1.1.1.4.2 pgoyette endif() 80 1.1.1.1.4.2 pgoyette 81 1.1.1.1.4.2 pgoyette set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc) 82 1.1.1.1.4.2 pgoyette configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein 83 1.1.1.1.4.2 pgoyette ${ZLIB_PC} @ONLY) 84 1.1.1.1.4.2 pgoyette configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein 85 1.1.1.1.4.2 pgoyette ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) 86 1.1.1.1.4.2 pgoyette include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) 87 1.1.1.1.4.2 pgoyette 88 1.1.1.1.4.2 pgoyette 89 1.1.1.1.4.2 pgoyette #============================================================================ 90 1.1.1.1.4.2 pgoyette # zlib 91 1.1.1.1.4.2 pgoyette #============================================================================ 92 1.1.1.1.4.2 pgoyette 93 1.1.1.1.4.2 pgoyette set(ZLIB_PUBLIC_HDRS 94 1.1.1.1.4.2 pgoyette ${CMAKE_CURRENT_BINARY_DIR}/zconf.h 95 1.1.1.1.4.2 pgoyette zlib.h 96 1.1.1.1.4.2 pgoyette ) 97 1.1.1.1.4.2 pgoyette set(ZLIB_PRIVATE_HDRS 98 1.1.1.1.4.2 pgoyette crc32.h 99 1.1.1.1.4.2 pgoyette deflate.h 100 1.1.1.1.4.2 pgoyette gzguts.h 101 1.1.1.1.4.2 pgoyette inffast.h 102 1.1.1.1.4.2 pgoyette inffixed.h 103 1.1.1.1.4.2 pgoyette inflate.h 104 1.1.1.1.4.2 pgoyette inftrees.h 105 1.1.1.1.4.2 pgoyette trees.h 106 1.1.1.1.4.2 pgoyette zutil.h 107 1.1.1.1.4.2 pgoyette ) 108 1.1.1.1.4.2 pgoyette set(ZLIB_SRCS 109 1.1.1.1.4.2 pgoyette adler32.c 110 1.1.1.1.4.2 pgoyette compress.c 111 1.1.1.1.4.2 pgoyette crc32.c 112 1.1.1.1.4.2 pgoyette deflate.c 113 1.1.1.1.4.2 pgoyette gzclose.c 114 1.1.1.1.4.2 pgoyette gzlib.c 115 1.1.1.1.4.2 pgoyette gzread.c 116 1.1.1.1.4.2 pgoyette gzwrite.c 117 1.1.1.1.4.2 pgoyette inflate.c 118 1.1.1.1.4.2 pgoyette infback.c 119 1.1.1.1.4.2 pgoyette inftrees.c 120 1.1.1.1.4.2 pgoyette inffast.c 121 1.1.1.1.4.2 pgoyette trees.c 122 1.1.1.1.4.2 pgoyette uncompr.c 123 1.1.1.1.4.2 pgoyette zutil.c 124 1.1.1.1.4.2 pgoyette ) 125 1.1.1.1.4.2 pgoyette 126 1.1.1.1.4.2 pgoyette if(NOT MINGW) 127 1.1.1.1.4.2 pgoyette set(ZLIB_DLL_SRCS 128 1.1.1.1.4.2 pgoyette win32/zlib1.rc # If present will override custom build rule below. 129 1.1.1.1.4.2 pgoyette ) 130 1.1.1.1.4.2 pgoyette endif() 131 1.1.1.1.4.2 pgoyette 132 1.1.1.1.4.2 pgoyette if(CMAKE_COMPILER_IS_GNUCC) 133 1.1.1.1.4.2 pgoyette if(ASM686) 134 1.1.1.1.4.2 pgoyette set(ZLIB_ASMS contrib/asm686/match.S) 135 1.1.1.1.4.2 pgoyette elseif (AMD64) 136 1.1.1.1.4.2 pgoyette set(ZLIB_ASMS contrib/amd64/amd64-match.S) 137 1.1.1.1.4.2 pgoyette endif () 138 1.1.1.1.4.2 pgoyette 139 1.1.1.1.4.2 pgoyette if(ZLIB_ASMS) 140 1.1.1.1.4.2 pgoyette add_definitions(-DASMV) 141 1.1.1.1.4.2 pgoyette set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE) 142 1.1.1.1.4.2 pgoyette endif() 143 1.1.1.1.4.2 pgoyette endif() 144 1.1.1.1.4.2 pgoyette 145 1.1.1.1.4.2 pgoyette if(MSVC) 146 1.1.1.1.4.2 pgoyette if(ASM686) 147 1.1.1.1.4.2 pgoyette ENABLE_LANGUAGE(ASM_MASM) 148 1.1.1.1.4.2 pgoyette set(ZLIB_ASMS 149 1.1.1.1.4.2 pgoyette contrib/masmx86/inffas32.asm 150 1.1.1.1.4.2 pgoyette contrib/masmx86/match686.asm 151 1.1.1.1.4.2 pgoyette ) 152 1.1.1.1.4.2 pgoyette elseif (AMD64) 153 1.1.1.1.4.2 pgoyette ENABLE_LANGUAGE(ASM_MASM) 154 1.1.1.1.4.2 pgoyette set(ZLIB_ASMS 155 1.1.1.1.4.2 pgoyette contrib/masmx64/gvmat64.asm 156 1.1.1.1.4.2 pgoyette contrib/masmx64/inffasx64.asm 157 1.1.1.1.4.2 pgoyette ) 158 1.1.1.1.4.2 pgoyette endif() 159 1.1.1.1.4.2 pgoyette 160 1.1.1.1.4.2 pgoyette if(ZLIB_ASMS) 161 1.1.1.1.4.2 pgoyette add_definitions(-DASMV -DASMINF) 162 1.1.1.1.4.2 pgoyette endif() 163 1.1.1.1.4.2 pgoyette endif() 164 1.1.1.1.4.2 pgoyette 165 1.1.1.1.4.2 pgoyette # parse the full version number from zlib.h and include in ZLIB_FULL_VERSION 166 1.1.1.1.4.2 pgoyette file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents) 167 1.1.1.1.4.2 pgoyette string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*" 168 1.1.1.1.4.2 pgoyette "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents}) 169 1.1.1.1.4.2 pgoyette 170 1.1.1.1.4.2 pgoyette if(MINGW) 171 1.1.1.1.4.2 pgoyette # This gets us DLL resource information when compiling on MinGW. 172 1.1.1.1.4.2 pgoyette if(NOT CMAKE_RC_COMPILER) 173 1.1.1.1.4.2 pgoyette set(CMAKE_RC_COMPILER windres.exe) 174 1.1.1.1.4.2 pgoyette endif() 175 1.1.1.1.4.2 pgoyette 176 1.1.1.1.4.2 pgoyette add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj 177 1.1.1.1.4.2 pgoyette COMMAND ${CMAKE_RC_COMPILER} 178 1.1.1.1.4.2 pgoyette -D GCC_WINDRES 179 1.1.1.1.4.2 pgoyette -I ${CMAKE_CURRENT_SOURCE_DIR} 180 1.1.1.1.4.2 pgoyette -I ${CMAKE_CURRENT_BINARY_DIR} 181 1.1.1.1.4.2 pgoyette -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj 182 1.1.1.1.4.2 pgoyette -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc) 183 1.1.1.1.4.2 pgoyette set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) 184 1.1.1.1.4.2 pgoyette endif(MINGW) 185 1.1.1.1.4.2 pgoyette 186 1.1.1.1.4.2 pgoyette add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) 187 1.1.1.1.4.2 pgoyette add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) 188 1.1.1.1.4.2 pgoyette set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) 189 1.1.1.1.4.2 pgoyette set_target_properties(zlib PROPERTIES SOVERSION 1) 190 1.1.1.1.4.2 pgoyette 191 1.1.1.1.4.2 pgoyette if(NOT CYGWIN) 192 1.1.1.1.4.2 pgoyette # This property causes shared libraries on Linux to have the full version 193 1.1.1.1.4.2 pgoyette # encoded into their final filename. We disable this on Cygwin because 194 1.1.1.1.4.2 pgoyette # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll 195 1.1.1.1.4.2 pgoyette # seems to be the default. 196 1.1.1.1.4.2 pgoyette # 197 1.1.1.1.4.2 pgoyette # This has no effect with MSVC, on that platform the version info for 198 1.1.1.1.4.2 pgoyette # the DLL comes from the resource file win32/zlib1.rc 199 1.1.1.1.4.2 pgoyette set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION}) 200 1.1.1.1.4.2 pgoyette endif() 201 1.1.1.1.4.2 pgoyette 202 1.1.1.1.4.2 pgoyette if(UNIX) 203 1.1.1.1.4.2 pgoyette # On unix-like platforms the library is almost always called libz 204 1.1.1.1.4.2 pgoyette set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) 205 1.1.1.1.4.2 pgoyette if(NOT APPLE) 206 1.1.1.1.4.2 pgoyette set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") 207 1.1.1.1.4.2 pgoyette endif() 208 1.1.1.1.4.2 pgoyette elseif(BUILD_SHARED_LIBS AND WIN32) 209 1.1.1.1.4.2 pgoyette # Creates zlib1.dll when building shared library version 210 1.1.1.1.4.2 pgoyette set_target_properties(zlib PROPERTIES SUFFIX "1.dll") 211 1.1.1.1.4.2 pgoyette endif() 212 1.1.1.1.4.2 pgoyette 213 1.1.1.1.4.2 pgoyette if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) 214 1.1.1.1.4.2 pgoyette install(TARGETS zlib zlibstatic 215 1.1.1.1.4.2 pgoyette RUNTIME DESTINATION "${INSTALL_BIN_DIR}" 216 1.1.1.1.4.2 pgoyette ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" 217 1.1.1.1.4.2 pgoyette LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) 218 1.1.1.1.4.2 pgoyette endif() 219 1.1.1.1.4.2 pgoyette if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) 220 1.1.1.1.4.2 pgoyette install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}") 221 1.1.1.1.4.2 pgoyette endif() 222 1.1.1.1.4.2 pgoyette if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) 223 1.1.1.1.4.2 pgoyette install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3") 224 1.1.1.1.4.2 pgoyette endif() 225 1.1.1.1.4.2 pgoyette if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) 226 1.1.1.1.4.2 pgoyette install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}") 227 1.1.1.1.4.2 pgoyette endif() 228 1.1.1.1.4.2 pgoyette 229 1.1.1.1.4.2 pgoyette #============================================================================ 230 1.1.1.1.4.2 pgoyette # Example binaries 231 1.1.1.1.4.2 pgoyette #============================================================================ 232 1.1.1.1.4.2 pgoyette 233 1.1.1.1.4.2 pgoyette add_executable(example test/example.c) 234 1.1.1.1.4.2 pgoyette target_link_libraries(example zlib) 235 1.1.1.1.4.2 pgoyette add_test(example example) 236 1.1.1.1.4.2 pgoyette 237 1.1.1.1.4.2 pgoyette add_executable(minigzip test/minigzip.c) 238 1.1.1.1.4.2 pgoyette target_link_libraries(minigzip zlib) 239 1.1.1.1.4.2 pgoyette 240 1.1.1.1.4.2 pgoyette if(HAVE_OFF64_T) 241 1.1.1.1.4.2 pgoyette add_executable(example64 test/example.c) 242 1.1.1.1.4.2 pgoyette target_link_libraries(example64 zlib) 243 1.1.1.1.4.2 pgoyette set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") 244 1.1.1.1.4.2 pgoyette add_test(example64 example64) 245 1.1.1.1.4.2 pgoyette 246 1.1.1.1.4.2 pgoyette add_executable(minigzip64 test/minigzip.c) 247 1.1.1.1.4.2 pgoyette target_link_libraries(minigzip64 zlib) 248 1.1.1.1.4.2 pgoyette set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") 249 1.1.1.1.4.2 pgoyette endif() 250