1- cmake_minimum_required(VERSION 2.4.4...3.15.0)
2- set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3-
4- project(zlib C)
1+ cmake_minimum_required (VERSION 3.18)
2+ set (CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3+ project (ZLIB C)
54
65set(VERSION "1.3.1")
76
8- include(CheckTypeSize)
9- include(CheckFunctionExists)
10- include(CheckIncludeFile)
11- include(CheckCSourceCompiles)
12- enable_testing()
7+ include (CheckTypeSize)
8+ include (CheckFunctionExists)
9+ include (CheckIncludeFile)
10+ include (CheckCSourceCompiles)
1311
14- check_include_file(sys/types.h HAVE_SYS_TYPES_H)
15- check_include_file(stdint.h HAVE_STDINT_H)
16- check_include_file(stddef.h HAVE_STDDEF_H)
12+ check_include_file (sys/types.h HAVE_SYS_TYPES_H)
13+ check_include_file (stdint.h HAVE_STDINT_H)
14+ check_include_file (stddef.h HAVE_STDDEF_H)
1715
1816#
1917# Check to see if we have large file support
2018#
21- set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
19+ set (CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
2220# We add these other definitions here because CheckTypeSize.cmake
2321# in CMake 2.4.x does not automatically do so and we want
2422# compatibility with CMake 2.4.x.
25- if(HAVE_SYS_TYPES_H)
26- list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
27- endif()
28- if(HAVE_STDINT_H)
29- list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
30- endif()
31- if(HAVE_STDDEF_H)
32- list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
33- endif()
34- check_type_size(off64_t OFF64_T)
35- if(HAVE_OFF64_T)
36- add_definitions(-D_LARGEFILE64_SOURCE=1)
37- endif()
38- set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
23+ if (HAVE_SYS_TYPES_H)
24+ list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
25+ endif ()
26+ if (HAVE_STDINT_H)
27+ list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
28+ endif ()
29+ if (HAVE_STDDEF_H)
30+ list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
31+ endif ()
32+ check_type_size (off64_t OFF64_T)
33+ if (HAVE_OFF64_T)
34+ add_definitions(-D_LARGEFILE64_SOURCE=1)
35+ endif ()
36+ set (CMAKE_REQUIRED_DEFINITIONS) # clear variable
3937
4038#
4139# Check for fseeko
4240#
43- check_function_exists(fseeko HAVE_FSEEKO)
44- if(NOT HAVE_FSEEKO)
45- add_definitions(-DNO_FSEEKO)
46- endif()
41+ check_function_exists (fseeko HAVE_FSEEKO)
42+ if (NOT HAVE_FSEEKO)
43+ add_definitions (-DNO_FSEEKO)
44+ endif ()
4745
4846#
4947# Check for unistd.h
5048#
51- check_include_file(unistd.h Z_HAVE_UNISTD_H)
49+ check_include_file (unistd.h Z_HAVE_UNISTD_H)
50+
51+ if (MSVC)
52+ set(CMAKE_DEBUG_POSTFIX "d")
53+ add_definitions (-D_BIND_TO_CURRENT_VCLIBS_VERSION=1)
54+ add_definitions (-D_CRT_SECURE_NO_DEPRECATE)
55+ add_definitions (-D_CRT_SECURE_NO_WARNINGS)
56+ add_definitions (-D_CONSOLE)
57+ add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
58+ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
59+ endif ()
5260
53- if(MSVC)
54- set(CMAKE_DEBUG_POSTFIX "d")
55- add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
56- add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
57- include_directories(${CMAKE_CURRENT_SOURCE_DIR})
58- endif()
61+ #============================================================================
62+ # zconf.h
63+ #============================================================================
5964
6065if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
6166 # If we're doing an out of source build and the user has a zconf.h
6267 # in their source tree...
6368 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
64- message(STATUS "Renaming")
65- message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h")
66- message(STATUS "to 'zconf.h.included' because this file is included with zlib")
67- message(STATUS "but CMake generates it automatically in the build directory.")
69+ message(VERBOSE "Renaming")
70+ message(VERBOSE " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h")
71+ message(VERBOSE "to 'zconf.h.included' because this file is included with zlib")
72+ message(VERBOSE "but CMake generates it automatically in the build directory.")
6873 file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included)
6974 endif()
7075endif()
@@ -77,9 +82,9 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
7782include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
7883
7984
80- #============================================================================
81- # zlib
82- #============================================================================
85+ #-----------------------------------------------------------------------------
86+ # Define ZLIB Library
87+ #-----------------------------------------------------------------------------
8388
8489set(ZLIB_PUBLIC_HDRS
8590 ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
@@ -141,4 +146,27 @@ if(MINGW)
141146 set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
142147endif(MINGW)
143148
149+ ### Define library
144150add_library(zlibstat STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
151+ if (MSVC AND CMAKE_CL_64)
152+ set_target_properties (zlibstat PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
153+ endif ()
154+ set_target_properties(zlibstat PROPERTIES
155+ PUBLIC_HEADER ""
156+ LINKER_LANGUAGE C
157+ INTERFACE_INCLUDE_DIRECTORIES "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>"
158+ )
159+
160+ #-----------------------------------------------------------------------------
161+ # Compiler specific flags
162+ #-----------------------------------------------------------------------------
163+ if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
164+ target_compile_options(zlibstat PRIVATE -Wno-strict-prototypes -Wno-implicit-function-declaration)
165+ endif ()
166+ if (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM" OR CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
167+ target_compile_options(zlibstat PRIVATE -Wno-implicit-function-declaration)
168+ endif ()
169+ if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
170+ target_compile_options(zlibstat PRIVATE -fmessage-length=0)
171+ endif ()
172+
0 commit comments