1 cmake_minimum_required(VERSION 3.12...3.31) 2 3 project( 4 zlib1-dll 5 LANGUAGES C 6 VERSION 1.3.2 7 HOMEPAGE_URL "https://zlib.net/" 8 DESCRIPTION "zlib1.dll is the legacy DLL with zlib and minizip") 9 10 # ============================================================================ 11 # configuration 12 # ============================================================================ 13 14 if(NOT WIN32) 15 message(FATAL_ERROR "This creates zlib1.<DLL>, Nothing else") 16 endif(NOT WIN32) 17 18 option(ENABLE_BZIP2 "Build with bzip2 support" OFF) 19 set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) 20 21 include(CheckCSourceCompiles) 22 include(CheckFunctionExists) 23 include(CheckIncludeFile) 24 include(CMakePackageConfigHelpers) 25 include(CheckTypeSize) 26 include(CPack) 27 include(GNUInstallDirs) 28 29 if(NOT ZLIB_CONF_WRITTEN) 30 set(CONF_OUT_FILE ${zlib1-dll_BINARY_DIR}/zconf.h.cmakein) 31 file(READ ../../zconf.h ZCONF_CONTENT LIMIT 245) 32 file(WRITE ${CONF_OUT_FILE} ${ZCONF_CONTENT}) 33 file(APPEND ${CONF_OUT_FILE} "#cmakedefine Z_PREFIX 1\n") 34 file(APPEND ${CONF_OUT_FILE} "#cmakedefine HAVE_STDARG_H 1\n") 35 file(APPEND ${CONF_OUT_FILE} "#cmakedefine HAVE_UNISTD_H 1\n") 36 file(READ ../../zconf.h ZCONF_CONTENT OFFSET 244) 37 set(FIRST_ITEM TRUE) 38 39 foreach(item IN LISTS ZCONF_CONTENT) 40 if(FIRST_ITEM) 41 string(APPEND OUT_CONTENT ${item}) 42 set(FIRST_ITEM FALSE) 43 else(FIRST_ITEM) 44 string(APPEND OUT_CONTENT "\;" ${item}) 45 endif(FIRST_ITEM) 46 endforeach(item IN LISTS ${ZCONF_CONTENT}) 47 48 file(APPEND ${CONF_OUT_FILE} ${OUT_CONTENT}) 49 set(ZLIB_CONF_WRITTEN 50 TRUE 51 CACHE BOOL "zconf.h.cmakein was created") 52 mark_as_advanced(ZLIB_CONF_WRITTEN) 53 endif(NOT ZLIB_CONF_WRITTEN) 54 55 if(ENABLE_BZIP2) 56 find_package(BZip2 REQUIRED) 57 endif(ENABLE_BZIP2) 58 59 # 60 # Check for fopen64 61 # 62 check_function_exists(fopen64 HAVE_FOPEN64) 63 64 # 65 # Check to see if we have large file support 66 # 67 set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1) 68 check_type_size(off64_t OFF64_T) 69 unset(CMAKE_REQUIRED_DEFINITIONS) # clear variable 70 71 # 72 # Check for fseeko 73 # 74 check_function_exists(fseeko HAVE_FSEEKO) 75 76 # 77 # Check for stdarg.h 78 # 79 check_include_file(stdarg.h HAVE_STDARG_H) 80 81 # 82 # Check for unistd.h 83 # 84 check_include_file(unistd.h HAVE_UNISTD_H) 85 86 # 87 # Check visibility attribute is supported 88 # 89 if(MSVC) 90 set(CMAKE_REQUIRED_FLAGS "-WX") 91 else(MSVC) 92 set(CMAKE_REQUIRED_FLAGS "-Werror") 93 endif(MSVC) 94 95 check_c_source_compiles( 96 " 97 #include <stdlib.h> 98 static void f(void) __attribute__ ((visibility(\"hidden\"))); 99 int main(void) {return 0;} 100 " 101 HAVE___ATTR__VIS_HIDDEN) 102 103 unset(CMAKE_COMPILE_FLAGS) 104 configure_file(${zlib1-dll_BINARY_DIR}/zconf.h.cmakein ${zlib1-dll_BINARY_DIR}/zconf.h) 105 106 # ============================================================================ 107 # zlib1-dll 108 # ============================================================================ 109 set(ZLIB1-DLL_PUBLIC_HDRS 110 ${zlib1-dll_BINARY_DIR}/zconf.h 111 ../../zlib.h 112 ../minizip/crypt.h 113 ../minizip/ints.h 114 ../minizip/ioapi.h 115 ../minizip/mztools.h 116 ../minizip/unzip.h 117 ../minizip/zip.h) 118 119 set(ZLIB1-DLL_PRIVATE_HDRS 120 ../../crc32.h 121 ../../deflate.h 122 ../../gzguts.h 123 ../../inffast.h 124 ../../inffixed.h 125 ../../inflate.h 126 ../../inftrees.h 127 ../../trees.h 128 ../../zutil.h) 129 130 set(ZLIB1-DLL_SRCS 131 ../../adler32.c 132 ../../compress.c 133 ../../crc32.c 134 ../../deflate.c 135 ../../gzclose.c 136 ../../gzlib.c 137 ../../gzread.c 138 ../../gzwrite.c 139 ../../inflate.c 140 ../../infback.c 141 ../../inftrees.c 142 ../../inffast.c 143 ../../trees.c 144 ../../uncompr.c 145 ../../win32/zlib1.rc 146 ../../zutil.c 147 ../minizip/ioapi.c 148 ../minizip/mztools.c 149 ../minizip/unzip.c 150 ../minizip/zip.c) 151 152 add_library(zlib1 SHARED ${ZLIB1-DLL_SRCS} 153 ${ZLIB1-DLL_PUBLIC_HDRS} 154 ${ZLIB1-DLL_PRIVATE_HDRS}) 155 156 #taget_include_directories doesn't like relative paths 157 include_directories(../../ 158 ../minizip 159 ${CMAKE_CURRENT_BINARY_DIR}) 160 161 target_compile_definitions(zlib1 162 PRIVATE ZLIB_BUILD 163 $<$<BOOL:NOT:${HAVE_FSEEKO}>:NO_FSEEKO> 164 $<$<BOOL:${HAVE_UNISTD_H}>:HAVE_UNISTD_H=1> 165 $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN> 166 $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_DEPRECATE> 167 $<$<BOOL:${MSVC}>:_CRT_NONSTDC_NO_DEPRECATE> 168 PUBLIC $<$<BOOL:${HAVE_OFF64_T}>:_LARGEFILE64_SOURCE=1> 169 $<$<BOOL:${BZIP2_FOUND}>:HAVE_BZIP2=1> 170 $<$<BOOL:NOT:${HAVE_FOPEN64}>:USE_FILE32API=1>) 171 172 target_link_libraries(zlib1 173 PUBLIC $<$<BOOL:${BZIP2_FOUND}>:BZip2::BZip2>) 174 175 if(NOT CYGWIN) 176 set_target_properties(zlib1 PROPERTIES 177 SOVERSION ${zlib1-dll_VERSION_MAJOR} 178 VERSION ${zlib1-dll_VERSION}) 179 endif(NOT CYGWIN) 180 181 set_target_properties(zlib1 PROPERTIES 182 DEFINE_SYMBOL ZLIB_DLL) 183 184 install( 185 TARGETS zlib1 186 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" 187 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 188 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") 189 190 install( 191 FILES ${ZLIB1-DLL_PUBLIC_HDRS} 192 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") 193 194 install( 195 FILES ../../LICENSE 196 DESTINATION "${CMAKE_INSTALL_DOCDIR}/zlib1-dll") 197