annotate src/zlib-1.2.8/CMakeLists.txt @ 83:ae30d91d2ffe

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