Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake update. #25

Merged
merged 54 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
2f8e894
Fix architecture macro on MSVC.
ningfei May 28, 2018
c72bf88
Update '.gitignore'.
ningfei May 30, 2018
dfdff14
Add 'build' subdir to .gitignore
ningfei Jun 5, 2018
4201fb5
Fix architecture macro on MSVC.
ningfei Jun 5, 2018
1e43bd7
Update CMakeLists.txt
ningfei Jun 8, 2018
6232ae0
Define '_LARGEFILE64_SOURCE' by default in CMakeLists.txt.
ningfei Jun 8, 2018
a4fe9d3
Set 'CMAKE_MACOSX_RPATH' to TRUE.
ningfei Jun 10, 2018
90fa1cb
Update SSE4.2 and PCLMUL setting in CMakeLists.txt
ningfei Jun 10, 2018
8d36af7
Add 'HAVE_HIDDEN' to CMakeLists.txt
ningfei Jun 10, 2018
0046377
Fix building dll on MSVC.
ningfei Jun 10, 2018
67701b0
Fix zlib.pc file generation.
ningfei Jun 10, 2018
46641ce
Refine cmake settings.
ningfei Jun 11, 2018
59e664b
Change cmake function to lowercase.
ningfei Jun 12, 2018
a661082
Fix zlib.pc
ningfei May 30, 2019
0b76b61
Fix crc32_pclmul_le_16 type.
ningfei May 31, 2019
cc542ac
Set POSITION_INDEPENDENT_CODE flag to ON by default.
ningfei Oct 10, 2019
aa1deea
Replace GPL CRC with BSD CRC (https://github.com/zlib-ng/zlib-ng/issu…
neurolabusc Jan 23, 2020
1f5a420
Westmere detection
neurolabusc Jan 25, 2020
2937f89
Update configure for Westmere (https://github.com/InsightSoftwareCons…
neurolabusc Jan 25, 2020
dd3e924
use cpu_has_pclmul() to autodetect CPU hardware (https://github.com/I…
neurolabusc Jan 27, 2020
b3064e0
remove gpl code
neurolabusc Jan 27, 2020
4c77bc7
Improve support for compiling using Windows (https://github.com/ningf…
neurolabusc Jan 28, 2020
4bf55a2
Import ucm.cmake from https://github.com/ningfei/zlib
neurolabusc Jan 28, 2020
59c0c27
crc32_simd as separate file (https://github.com/cloudflare/zlib/pull/18)
neurolabusc Jan 29, 2020
dc28f91
atomic and SKIP_CPUID_CHECK (https://github.com/cloudflare/zlib/pull/18)
neurolabusc Jan 31, 2020
fc27690
Suppress some MSVC warnings.
ningfei Jan 31, 2020
b73befc
Remove unused code
neurolabusc Feb 2, 2020
f76d745
Merge from https://github.com/rordenlab/zlib/tree/gcc.amd64
ningfei Feb 2, 2020
5dd828c
Fix ucm_set_runtime when only C is enabled for the project.
ningfei Feb 2, 2020
c0cd6d2
Removed configured header file.
ningfei Feb 2, 2020
1e41546
Unify zconf.h template.
ningfei Feb 2, 2020
df5c4fe
Only allow compiler to use clmul instructions to crc_simd unit (https…
neurolabusc Feb 7, 2020
c99aa75
Atomic does not compile on Ubuntu 14.04
neurolabusc Feb 12, 2020
0324e35
Allow "cmake -DSKIP_CPUID_CHECK=ON .." to not check SIMD CRC support …
neurolabusc Feb 14, 2020
99f7b58
Restore Windows compilation using "nmake -f win32\Makefile.msc"
neurolabusc Feb 16, 2020
c8ca151
Merge branch 'gcc.amd64' of github.com:rordenlab/zlib into gcc.amd64
ningfei Feb 18, 2020
74b551f
Do not set SOVERSION on Cygwin.
ningfei Feb 18, 2020
a4c76ea
Fix file permission.
ningfei Feb 18, 2020
5d17ad4
Refine PCLMUL CMake option.
ningfei Feb 18, 2020
f9254d5
zconf.h required for Windows nmake
neurolabusc Feb 19, 2020
0c90471
Do not set visibility flag on Cygwin.
ningfei Feb 21, 2020
e544b74
Fix compiling dll resource.
ningfei Feb 21, 2020
d59c96b
Fix compiling using MinGW.
ningfei Feb 21, 2020
d1e5bb1
Merge branch 'gcc.amd64' of https://github.com/rordenlab/zlib into gc…
ningfei Feb 21, 2020
b71b47f
Fix zconf.h for Windows.
ningfei Feb 21, 2020
47171b6
support crc intrinsics for ARM CPUs
neurolabusc Feb 21, 2020
0062a6a
Merge branch 'gcc.amd64' of https://github.com/rordenlab/zlib into gc…
ningfei Feb 23, 2020
427dc10
Add gzip -k option to minigzip (to aid benchmarks)
neurolabusc Jun 5, 2020
d5864a3
Merge branch 'gcc.amd64' of https://github.com/cloudflare/zlib
ningfei Oct 13, 2020
ce4b03b
Support Intel and ARMv8 optimization in CMake.
ningfei Oct 16, 2020
7562162
Clean up.
ningfei Oct 17, 2020
7c3ca88
Merge branch 'gcc.amd64' into gcc.amd64
neurolabusc Nov 18, 2020
55e2f08
Fix compiling on Apple M1.
ningfei Nov 18, 2020
254f7d9
Restore MSVC warnings.
ningfei Dec 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/minigzip64
/minigzipsh
/zlib.pc
/zconf.h.included

.DS_Store

Expand Down
104 changes: 67 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ option(BUILD_EXAMPLES "Build examples" OFF)
option(SKIP_CPUID_CHECK "Assume CPU supports fast CRC" OFF)

if(SKIP_CPUID_CHECK)
add_definitions(-DSKIP_CPUID_CHECK)
add_definitions(-DSKIP_CPUID_CHECK)
endif()

# Set -fPIC option
Expand Down Expand Up @@ -66,16 +66,42 @@ endif()

# Compiler dependent flags
include (CheckCCompilerFlag)
if(UNIX)
check_c_compiler_flag(-msse4.2 HAS_SSE42)
if(HAS_SSE42)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2")
add_definitions(-DHAS_SSE42)
if(UNIX OR MINGW)
check_c_compiler_flag(-march=armv8-a+crc ARM_CRC)
if(ARM_CRC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crc")
else()
check_c_compiler_flag(-msse2 HAS_SSE2)
if(HAS_SSE2)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
add_definitions(-DHAS_SSE2)
endif()

check_c_compiler_flag(-mssse3 HAS_SSSE3)
if(HAS_SSSE3)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mssse3")
add_definitions(-DHAS_SSSE3)
endif()

check_c_compiler_flag(-msse4.2 HAS_SSE42)
if(HAS_SSE42)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2")
add_definitions(-DHAS_SSE42)
endif()

check_c_compiler_flag(-mpclmul HAS_PCLMUL)
if(HAS_PCLMUL)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mpclmul")
add_definitions(-DHAS_PCLMUL)
endif()
endif()
elseif(MSVC)
set(CMAKE_DEBUG_POSTFIX "d")
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4018") # '<': signed/unsigned mismatch
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should instead fix those warnings?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will check it again using MSVC. I think this only happens when we use MSVC.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can fix them myself really.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4101") # unreferenced local variable
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4244") # 'initializing': conversion from 'double' to 'int', possible loss of data

check_c_compiler_flag(/arch:AVX HAS_AVX)
if (HAS_AVX)
Expand Down Expand Up @@ -120,45 +146,49 @@ set(ZLIB_SRCS
zutil.c
)

# append "crc_simd.c" and compile with "mpclmul" if supported by compiler
if(UNIX)
check_c_compiler_flag(-mpclmul HAS_PCLMUL)
if(HAS_PCLMUL)
set(ENABLE_ASSEMBLY "PCLMUL" CACHE STRING "Choose assembly implementation.")
set_property(CACHE ENABLE_ASSEMBLY PROPERTY STRINGS "OFF;PCLMUL")

if("${ENABLE_ASSEMBLY}" STREQUAL "PCLMUL")
#set(ZLIB_ASMS contrib/amd64/crc32-pclmul_asm.S)
#set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE)
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mpclmul")
set_source_files_properties(crc32_simd.c PROPERTIES COMPILE_FLAGS -mpclmul)
list(APPEND ZLIB_SRCS crc32_simd.c)
add_definitions(-DHAS_PCLMUL)
endif()
if(UNIX OR MINGW)
# append "inffast_chunk.c" and "adler32_simd.c" for ARMv8 CPU
if(ARM_CRC)
list(APPEND ZLIB_SRCS inffast_chunk.c adler32_simd.c)
add_definitions(-DINFLATE_CHUNK_SIMD_NEON)
add_definitions(-DINFLATE_CHUNK_READ_64LE)
add_definitions(-DADLER32_SIMD_NEON)
endif()

# append "inffast_chunk.c" and compile with "sse2" if supported by compiler
if(HAS_SSE2)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both SSE2 and SSSE3 checks are redundant, since they are present on all x86-64 CPUs anyway.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, then I will add the flags and definitions directly. I added these two checks just recently since I saw they were checked in the configure

list(APPEND ZLIB_SRCS inffast_chunk.c)
add_definitions(-DINFLATE_CHUNK_SIMD_SSE2)
add_definitions(-DINFLATE_CHUNK_READ_64LE)
endif()
endif()

# support crc intrinsics for ARM CPUs
if(UNIX)
check_c_compiler_flag(-march=armv8-a+crc HAS_CRC)
if(HAS_CRC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crc")
# append "adler32_simd.c" and compile with "ssse3" if supported by compiler
if(HAS_SSSE3)
list(APPEND ZLIB_SRCS adler32_simd.c)
add_definitions(-DADLER32_SIMD_SSSE3)
endif()

# append "crc_simd.c" and compile with "pclmul" if supported by compiler
if(HAS_PCLMUL)
list(APPEND ZLIB_SRCS crc32_simd.c)
endif()
endif()

if(BUILD_SHARED_LIBS)
# Visibility
check_c_compiler_flag(-fvisibility=hidden HAVE_HIDDEN)
if(HAVE_HIDDEN)
add_definitions(-DHAVE_HIDDEN)
if(UNIX AND NOT CYGWIN)
check_c_compiler_flag(-fvisibility=hidden HAVE_HIDDEN)
if(HAVE_HIDDEN)
add_definitions(-DHAVE_HIDDEN)
endif()
endif()

# DLL resource setting
if(NOT MINGW)
if(MSVC)
set(ZLIB_DLL_SRCS
win32/zlib1.rc # If present will override custom build rule below.
)
else()
elseif(MINGW OR CYGWIN)
# This gets us DLL resource information when compiling on MinGW.
if(NOT CMAKE_RC_COMPILER)
set(CMAKE_RC_COMPILER windres.exe)
Expand All @@ -174,9 +204,8 @@ if(BUILD_SHARED_LIBS)
set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
endif()

add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
set_target_properties(zlib PROPERTIES SOVERSION 1)

if(NOT CYGWIN)
# This property causes shared libraries on Linux to have the full version
Expand All @@ -186,10 +215,11 @@ if(BUILD_SHARED_LIBS)
#
# This has no effect with MSVC, on that platform the version info for
# the DLL comes from the resource file win32/zlib1.rc
set_target_properties(zlib PROPERTIES SOVERSION 1)
set_target_properties(zlib PROPERTIES VERSION ${ZLIB_VERSION})
endif()

if(UNIX)
if(UNIX OR MINGW)
# On unix-like platforms the library is almost always called libz
set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
if(NOT APPLE)
Expand All @@ -200,8 +230,8 @@ if(BUILD_SHARED_LIBS)
set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
endif()
else()
add_library(zlib STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
if(UNIX)
add_library(zlib STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
if(UNIX OR MINGW)
set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
endif()
#============================================================================
Expand Down
4 changes: 2 additions & 2 deletions crc32.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ local unsigned long crc32_generic(crc, buf, len)
#define PCLMUL_ALIGN_MASK 15

#if defined(__GNUC__)
#if __GNUC__ < 5
#if __GNUC__ < 5
int cpu_has_pclmul = -1; //e.g. gcc 4.8.4 https://stackoverflow.com/questions/20326604/stdatomic-h-in-gcc-4-8
#else
_Atomic int cpu_has_pclmul = -1; //global: will be 0 or 1 after first test
Expand Down Expand Up @@ -553,4 +553,4 @@ uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
return crc32_combine_(crc1, crc2, len2);
}

#endif
#endif
Empty file modified crc32_simd.c
100755 → 100644
Empty file.
Empty file modified crc32_simd.h
100755 → 100644
Empty file.
Empty file modified deflate.c
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion test/minigzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ int main(argc, argv)
else if (strcmp(*argv, "-h") == 0)
outmode[3] = 'h';
else if (strcmp(*argv, "-k") == 0)
keep = 1;
keep = 1;
else if (strcmp(*argv, "-r") == 0)
outmode[3] = 'R';
else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' &&
Expand Down
24 changes: 12 additions & 12 deletions ucm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ macro(ucm_set_runtime)
# - for example if with MSVC and the user has removed the flags - here we just switch/replace them
if("${ARG_STATIC}")
foreach(flags ${flags_configs})
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4.7) # option "-static-libstdc++" available since GCC 4.5
if(NOT ${flags} MATCHES "-static-libstdc\\+\\+")
set(${flags} "${${flags}} -static-libstdc++")
Expand All @@ -226,7 +226,7 @@ macro(ucm_set_runtime)
endforeach()
elseif("${ARG_DYNAMIC}")
foreach(flags ${flags_configs})
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "GNU")
if(${flags} MATCHES "-static-libstdc\\+\\+")
string(REGEX REPLACE "-static-libstdc\\+\\+" "" ${flags} "${${flags}}")
endif()
Expand Down Expand Up @@ -556,13 +556,13 @@ macro(ucm_add_target)
set(do_unity FALSE)
endif()

# inform the developer that the current target might benefit from a unity build
if(NOT ARG_UNITY AND ${UCM_UNITY_BUILD})
ucm_count_sources(${ARG_SOURCES} RESULT num_sources)
if(${num_sources} GREATER 1)
message(AUTHOR_WARNING "Target '${ARG_NAME}' may benefit from a unity build.\nIt has ${num_sources} sources - enable with UNITY flag")
endif()
endif()
# inform the developer that the current target might benefit from a unity build
if(NOT ARG_UNITY AND ${UCM_UNITY_BUILD})
ucm_count_sources(${ARG_SOURCES} RESULT num_sources)
if(${num_sources} GREATER 1)
message(AUTHOR_WARNING "Target '${ARG_NAME}' may benefit from a unity build.\nIt has ${num_sources} sources - enable with UNITY flag")
endif()
endif()

# prepare for the unity build
set(orig_target ${ARG_NAME})
Expand All @@ -587,9 +587,9 @@ macro(ucm_add_target)
# set the number of unity cpp files to be used for the unity target
if(NOT "${ARG_CPP_PER_UNITY}" STREQUAL "")
set_property(TARGET ${orig_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES "${ARG_CPP_PER_UNITY}")
else()
set_property(TARGET ${orig_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES "100")
endif()
else()
set_property(TARGET ${orig_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES "100")
endif()

if(NOT "${ARG_PCH_FILE}" STREQUAL "")
set_target_properties(${orig_target} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "${ARG_PCH_FILE}")
Expand Down
4 changes: 2 additions & 2 deletions zconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ typedef uLong FAR uLongf;
#endif
#ifndef Z_SOLO
# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
# ifdef _MSC_VER
# ifdef _WIN32 /* _MSC_VER doesn't work for some reason when building dll*/
# include <io.h>
# else
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
# endif
# ifdef VMS
# include <unixio.h> /* for off_t */
Expand Down
4 changes: 2 additions & 2 deletions zconf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ typedef uLong FAR uLongf;
#endif
#ifndef Z_SOLO
# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
# ifdef _MSC_VER
# ifdef _WIN32 /* _MSC_VER doesn't work for some reason when building dll*/
# include <io.h>
# else
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
# endif
# ifdef VMS
# include <unixio.h> /* for off_t */
Expand Down
Loading