-
Notifications
You must be signed in to change notification settings - Fork 79
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
CMake update. #25
Changes from 53 commits
2f8e894
c72bf88
dfdff14
4201fb5
1e43bd7
6232ae0
a4fe9d3
90fa1cb
8d36af7
0046377
67701b0
46641ce
59e664b
a661082
0b76b61
cc542ac
aa1deea
1f5a420
2937f89
dd3e924
b3064e0
4c77bc7
4bf55a2
59c0c27
dc28f91
fc27690
b73befc
f76d745
5dd828c
c0cd6d2
1e41546
df5c4fe
c99aa75
0324e35
99f7b58
c8ca151
74b551f
a4c76ea
5d17ad4
f9254d5
0c90471
e544b74
d59c96b
d1e5bb1
b71b47f
47171b6
0062a6a
427dc10
d5864a3
ce4b03b
7562162
7c3ca88
55e2f08
254f7d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
/minigzip64 | ||
/minigzipsh | ||
/zlib.pc | ||
/zconf.h.included | ||
|
||
.DS_Store | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
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) | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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) | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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() | ||
#============================================================================ | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!