[DO-984] add-zlib-recipe (!4)

Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/4
This commit is contained in:
Aleksandr Vodyanov
2024-11-22 17:15:46 +03:00
parent e3106d807c
commit 4bbce79e03
15 changed files with 743 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7f1b69f..618ea02 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -57,7 +57,6 @@ endif()
check_include_file(unistd.h Z_HAVE_UNISTD_H)
if(MSVC)
- set(CMAKE_DEBUG_POSTFIX "d")
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
@@ -120,7 +119,7 @@ set(ZLIB_SRCS
zutil.c
)
-if(NOT MINGW)
+if(MSVC)
set(ZLIB_DLL_SRCS
win32/zlib1.rc # If present will override custom build rule below.
)
@@ -131,7 +130,7 @@ file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
"\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
-if(MINGW)
+if(WIN32 AND NOT MSVC)
# This gets us DLL resource information when compiling on MinGW.
if(NOT CMAKE_RC_COMPILER)
set(CMAKE_RC_COMPILER windres.exe)
@@ -145,12 +144,16 @@ if(MINGW)
-o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
-i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
-endif(MINGW)
+endif()
+if(BUILD_SHARED_LIBS)
add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
set_target_properties(zlib PROPERTIES SOVERSION 1)
+else()
+add_library(zlib STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
+endif()
if(NOT CYGWIN)
# This property causes shared libraries on Linux to have the full version
@@ -163,19 +166,24 @@ if(NOT CYGWIN)
set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
endif()
-if(UNIX)
+if(WIN32 AND NOT MINGW)
+ if(BUILD_SHARED_LIBS)
+ set_target_properties(zlib PROPERTIES ARCHIVE_OUTPUT_NAME zdll)
+ endif()
+else()
# On unix-like platforms the library is almost always called libz
- set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)
+ set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
if(NOT APPLE)
set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
endif()
-elseif(BUILD_SHARED_LIBS AND WIN32)
+endif()
+if(BUILD_SHARED_LIBS AND WIN32)
# Creates zlib1.dll when building shared library version
- set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
+ set_target_properties(zlib PROPERTIES PREFIX "" RUNTIME_OUTPUT_NAME "zlib1")
endif()
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
- install(TARGETS zlib zlibstatic
+ install(TARGETS zlib
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
@@ -193,7 +201,7 @@ endif()
#============================================================================
# Example binaries
#============================================================================
-
+if(0)
add_executable(example test/example.c)
target_link_libraries(example zlib)
add_test(example example)
@@ -211,3 +219,4 @@ if(HAVE_OFF64_T)
target_link_libraries(minigzip64 zlib)
set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
endif()
+endif()