@@ -4,16 +4,20 @@ if(CMAKE_VERSION VERSION_LESS 3.12)
44endif ()
55message (STATUS "Using CMake version ${CMAKE_VERSION} " )
66
7+ if (POLICY CMP0169)
8+ cmake_policy (SET CMP0169 OLD) # CMake 3.30: call FetchContent_Populate() with just the name of a dependency
9+ endif ()
10+
711# If not specified on the command line, enable C11 as the default
812# Configuration items that affect the global compiler environment standards
913# should be issued before the "project" command.
10- if (NOT CMAKE_C_STANDARD)
14+ if (NOT DEFINED CMAKE_C_STANDARD)
1115 set (CMAKE_C_STANDARD 11) # The C standard whose features are requested to build this target
1216endif ()
13- if (NOT CMAKE_C_STANDARD_REQUIRED)
17+ if (NOT DEFINED CMAKE_C_STANDARD_REQUIRED)
1418 set (CMAKE_C_STANDARD_REQUIRED ON ) # Boolean describing whether the value of C_STANDARD is a requirement
1519endif ()
16- if (NOT CMAKE_C_EXTENSIONS)
20+ if (NOT DEFINED CMAKE_C_EXTENSIONS)
1721 set (CMAKE_C_EXTENSIONS OFF ) # Boolean specifying whether compiler specific extensions are requested
1822endif ()
1923set (VALID_C_STANDARDS "99" "11" )
@@ -89,7 +93,6 @@ option(WITH_MAINTAINER_WARNINGS "Build with project maintainer warnings" OFF)
8993option (WITH_CODE_COVERAGE "Enable code coverage reporting" OFF )
9094option (WITH_INFLATE_STRICT "Build with strict inflate distance checking" OFF )
9195option (WITH_INFLATE_ALLOW_INVALID_DIST "Build with zero fill for inflate invalid distances" OFF )
92- option (WITH_UNALIGNED "Support unaligned reads on platforms that support it" ON )
9396
9497set (ZLIB_SYMBOL_PREFIX "" CACHE STRING "Give this prefix to all publicly exported symbols.
9598Useful when embedding into a larger library.
@@ -102,7 +105,7 @@ set_property(CACHE WITH_SANITIZER PROPERTY STRINGS "Memory" "Address" "Undefined
102105if (BASEARCH_ARM_FOUND)
103106 option (WITH_ACLE "Build with ACLE" ON )
104107 option (WITH_NEON "Build with NEON intrinsics" ON )
105- cmake_dependent_option(WITH_ARMV6 "Build with ARMv6 SIMD" ON "NOT ARCH STREQUAL \" aarch64\" " OFF )
108+ cmake_dependent_option(WITH_ARMV6 "Build with ARMv6 SIMD" ON "NOT ARCH MATCHES \" aarch64\" " OFF )
106109elseif (BASEARCH_PPC_FOUND)
107110 option (WITH_ALTIVEC "Build with AltiVec (VMX) optimisations for PowerPC" ON )
108111 option (WITH_POWER8 "Build with optimisations for POWER8" ON )
@@ -143,7 +146,6 @@ mark_as_advanced(FORCE
143146 WITH_RVV
144147 WITH_INFLATE_STRICT
145148 WITH_INFLATE_ALLOW_INVALID_DIST
146- WITH_UNALIGNED
147149 INSTALL_UTILS
148150 )
149151
@@ -189,9 +191,9 @@ elseif(MSVC)
189191 # (who'd use cmake from an IDE...) but checking for ICC before checking for MSVC should
190192 # avoid mistakes.
191193 # /Oi ?
192- set (WARNFLAGS /W3)
194+ set (WARNFLAGS /W3 /w34242 /WX )
193195 set (WARNFLAGS_MAINTAINER /W4)
194- set (WARNFLAGS_DISABLE)
196+ set (WARNFLAGS_DISABLE /wd4206 /wd4054 /wd4324 )
195197 if (BASEARCH_ARM_FOUND)
196198 add_definitions (-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
197199 if (NOT "${ARCH} " MATCHES "aarch64" )
@@ -299,7 +301,7 @@ if(NOT WITH_RUNTIME_CPU_DETECTION)
299301 message (STATUS "WARNING: Microsoft Visual Studio does not support compile time detection of CPU features for \" /arch\" before \" AVX\" " )
300302 # Workaround for MSVC. By default MSVC does not define the __SSE*__ macros.
301303 # Fix it if AVX is enabled.
302- set (CMAKE_REQUIRED_FLAGS "${NATIVEFLAG} " )
304+ set (CMAKE_REQUIRED_FLAGS "${NATIVEFLAG} ${ZNOLTOFLAG} " )
303305 check_c_source_compiles(
304306 "#ifndef __AVX__
305307 # error \" AVX is not enabled.\"
@@ -332,12 +334,6 @@ if(NOT WITH_NATIVE_INSTRUCTIONS)
332334 endforeach ()
333335endif ()
334336
335- # Set architecture alignment requirements
336- if (NOT WITH_UNALIGNED)
337- add_definitions (-DNO_UNALIGNED)
338- message (STATUS "Unaligned reads manually disabled" )
339- endif ()
340-
341337# Apply warning compiler flags
342338if (WITH_MAINTAINER_WARNINGS)
343339 add_compile_options (${WARNFLAGS} ${WARNFLAGS_MAINTAINER} ${WARNFLAGS_DISABLE} )
@@ -356,6 +352,16 @@ if(NOT WITH_CODE_COVERAGE AND NOT MSVC AND NOT CMAKE_C_FLAGS MATCHES "([\\/\\-]O
356352 CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} " )
357353endif ()
358354
355+ # Force Visual C++ to use UTF-8
356+ if (MSVC )
357+ if (NOT CMAKE_C_FLAGS MATCHES "[\\ /\\ -]utf-8" )
358+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8" )
359+ endif ()
360+ if (NOT CMAKE_CXX_FLAGS MATCHES "[\\ /\\ -]utf-8" )
361+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8" )
362+ endif ()
363+ endif ()
364+
359365#
360366# Check for standard/system includes
361367#
@@ -485,6 +491,7 @@ endif()
485491#
486492# Check for __builtin_assume_aligned(x,n) support in the compiler
487493#
494+ set (CMAKE_REQUIRED_FLAGS ${ZNOLTOFLAG} )
488495check_c_source_compiles(
489496 "char *test(char *buffer) {
490497 char *abuffer = __builtin_assume_aligned(buffer,64);
@@ -497,10 +504,12 @@ check_c_source_compiles(
497504if (HAVE_BUILTIN_ASSUME_ALIGNED)
498505 add_definitions (-DHAVE_BUILTIN_ASSUME_ALIGNED)
499506endif ()
507+ set (CMAKE_REQUIRED_FLAGS)
500508
501509#
502510# check for __builtin_ctz() support in the compiler
503511#
512+ set (CMAKE_REQUIRED_FLAGS ${ZNOLTOFLAG} )
504513check_c_source_compiles(
505514 "int main(void) {
506515 unsigned int zero = 0;
@@ -513,10 +522,12 @@ check_c_source_compiles(
513522if (HAVE_BUILTIN_CTZ)
514523 add_definitions (-DHAVE_BUILTIN_CTZ)
515524endif ()
525+ set (CMAKE_REQUIRED_FLAGS)
516526
517527#
518528# check for __builtin_ctzll() support in the compiler
519529#
530+ set (CMAKE_REQUIRED_FLAGS ${ZNOLTOFLAG} )
520531check_c_source_compiles(
521532 "int main(void) {
522533 unsigned int zero = 0;
@@ -529,6 +540,7 @@ check_c_source_compiles(
529540if (HAVE_BUILTIN_CTZLL)
530541 add_definitions (-DHAVE_BUILTIN_CTZLL)
531542endif ()
543+ set (CMAKE_REQUIRED_FLAGS)
532544
533545#
534546# check for ptrdiff_t support
@@ -965,8 +977,10 @@ if(WITH_OPTIM)
965977 add_definitions (-DX86_AVX512)
966978 list (APPEND AVX512_SRCS ${ARCHDIR} /adler32_avx512.c)
967979 add_feature_info(AVX512_ADLER32 1 "Support AVX512-accelerated adler32, using \" ${AVX512FLAG} \" " )
968- list (APPEND ZLIB_ARCH_SRCS ${AVX512_SRCS} )
980+ list (APPEND AVX512_SRCS ${ARCHDIR} /chunkset_avx512.c)
981+ add_feature_info(AVX512_CHUNKSET 1 "Support AVX512 optimized chunkset, using \" ${AVX512FLAG} \" " )
969982 list (APPEND ZLIB_ARCH_HDRS ${ARCHDIR} /adler32_avx512_p.h)
983+ list (APPEND ZLIB_ARCH_SRCS ${AVX512_SRCS} )
970984 set_property (SOURCE ${AVX512_SRCS} PROPERTY COMPILE_FLAGS "${AVX512FLAG} ${NOLTOFLAG} " )
971985 else ()
972986 set (WITH_AVX512 OFF )
@@ -1066,6 +1080,9 @@ set(ZLIB_PUBLIC_HDRS
10661080 ${CMAKE_CURRENT_BINARY_DIR} /zlib${SUFFIX} .h
10671081)
10681082set (ZLIB_PRIVATE_HDRS
1083+ arch/generic/chunk_permute_table.h
1084+ arch/generic/compare256_p.h
1085+ arch/generic/generic_functions.h
10691086 adler32_p.h
10701087 chunkset_tpl.h
10711088 compare256_rle.h
@@ -1172,10 +1189,6 @@ if (ZLIB_COMPAT)
11721189 endif ()
11731190endif ()
11741191
1175- include_directories (${CMAKE_CURRENT_SOURCE_DIR} )
1176- include_directories (${ARCHDIR} )
1177- include_directories (${CMAKE_CURRENT_SOURCE_DIR} /arch/generic)
1178-
11791192foreach (ZLIB_INSTALL_LIBRARY ${ZLIB_INSTALL_LIBRARIES} )
11801193 if (NOT ZLIB_COMPAT)
11811194 target_compile_definitions (${ZLIB_INSTALL_LIBRARY} PUBLIC ZLIBNG_NATIVE_API)
0 commit comments