|
| 1 | +diff --git a/CMakeLists.txt b/CMakeLists.txt |
| 2 | +index 15ceebe..03825a2 100644 |
| 3 | +--- a/CMakeLists.txt |
| 4 | ++++ b/CMakeLists.txt |
| 5 | +@@ -1,23 +1,21 @@ |
| 6 | +-cmake_minimum_required(VERSION 2.4.4...3.15.0) |
| 7 | +-set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) |
| 8 | ++cmake_minimum_required(VERSION 3.15) |
| 9 | + |
| 10 | +-project(zlib C) |
| 11 | +- |
| 12 | +-set(VERSION "1.3.1") |
| 13 | ++project(zlib VERSION 1.3.1 LANGUAGES C) |
| 14 | + |
| 15 | + option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON) |
| 16 | + |
| 17 | +-set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") |
| 18 | +-set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") |
| 19 | +-set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") |
| 20 | +-set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages") |
| 21 | +-set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") |
| 22 | ++include(GNUInstallDirs) |
| 23 | ++set(INSTALL_BIN_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH "Installation directory for executables") |
| 24 | ++set(INSTALL_LIB_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation directory for libraries") |
| 25 | ++set(INSTALL_INC_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE PATH "Installation directory for headers") |
| 26 | ++set(INSTALL_MAN_DIR "${CMAKE_INSTALL_MANDIR}" CACHE PATH "Installation directory for manual pages") |
| 27 | ++set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_DATADIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") |
| 28 | + |
| 29 | + include(CheckTypeSize) |
| 30 | + include(CheckFunctionExists) |
| 31 | + include(CheckIncludeFile) |
| 32 | + include(CheckCSourceCompiles) |
| 33 | +-enable_testing() |
| 34 | ++include(CTest) |
| 35 | + |
| 36 | + check_include_file(sys/types.h HAVE_SYS_TYPES_H) |
| 37 | + check_include_file(stdint.h HAVE_STDINT_H) |
| 38 | +@@ -149,12 +147,21 @@ if(MINGW) |
| 39 | + set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) |
| 40 | + endif(MINGW) |
| 41 | + |
| 42 | +-add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) |
| 43 | +-target_include_directories(zlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) |
| 44 | +-add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) |
| 45 | +-target_include_directories(zlibstatic PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) |
| 46 | +-set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) |
| 47 | +-set_target_properties(zlib PROPERTIES SOVERSION 1) |
| 48 | ++if(BUILD_SHARED_LIBS) |
| 49 | ++ add_library(ZLIB SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) |
| 50 | ++ set_target_properties(ZLIB PROPERTIES DEFINE_SYMBOL ZLIB_DLL) |
| 51 | ++ set_target_properties(ZLIB PROPERTIES SOVERSION 1) |
| 52 | ++else() |
| 53 | ++ add_library(ZLIB STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) |
| 54 | ++endif() |
| 55 | ++ |
| 56 | ++target_include_directories(ZLIB PUBLIC |
| 57 | ++ $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> |
| 58 | ++ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> |
| 59 | ++ $<INSTALL_INTERFACE:include>) |
| 60 | ++ |
| 61 | ++add_library(ZLIB::ZLIB ALIAS ZLIB) |
| 62 | ++ |
| 63 | + |
| 64 | + if(NOT CYGWIN) |
| 65 | + # This property causes shared libraries on Linux to have the full version |
| 66 | +@@ -164,26 +171,49 @@ if(NOT CYGWIN) |
| 67 | + # |
| 68 | + # This has no effect with MSVC, on that platform the version info for |
| 69 | + # the DLL comes from the resource file win32/zlib1.rc |
| 70 | +- set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION}) |
| 71 | ++ set_target_properties(ZLIB PROPERTIES VERSION ${ZLIB_FULL_VERSION}) |
| 72 | + endif() |
| 73 | + |
| 74 | + if(UNIX) |
| 75 | + # On unix-like platforms the library is almost always called libz |
| 76 | +- set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) |
| 77 | +- if(NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX)) |
| 78 | +- set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") |
| 79 | ++ set_target_properties(ZLIB PROPERTIES OUTPUT_NAME z) |
| 80 | ++ if(NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX) AND BUILD_SHARED_LIBS) |
| 81 | ++ set_target_properties(ZLIB PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") |
| 82 | + endif() |
| 83 | + elseif(BUILD_SHARED_LIBS AND WIN32) |
| 84 | + # Creates zlib1.dll when building shared library version |
| 85 | +- set_target_properties(zlib PROPERTIES SUFFIX "1.dll") |
| 86 | ++ set_target_properties(ZLIB PROPERTIES SUFFIX "1.dll") |
| 87 | ++endif() |
| 88 | ++ |
| 89 | ++if(NOT UNIX) |
| 90 | ++ if(BUILD_SHARED_LIBS) |
| 91 | ++ set_target_properties(ZLIB PROPERTIES OUTPUT_NAME zlib) |
| 92 | ++ else() |
| 93 | ++ set_target_properties(ZLIB PROPERTIES OUTPUT_NAME zlibstatic) |
| 94 | ++ endif() |
| 95 | + endif() |
| 96 | + |
| 97 | +-if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) |
| 98 | +- install(TARGETS zlib zlibstatic |
| 99 | +- RUNTIME DESTINATION "${INSTALL_BIN_DIR}" |
| 100 | +- ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" |
| 101 | +- LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) |
| 102 | ++if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) |
| 103 | ++ install(TARGETS ZLIB |
| 104 | ++ EXPORT ZLIBTargets |
| 105 | ++ RUNTIME DESTINATION "${INSTALL_BIN_DIR}" |
| 106 | ++ ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" |
| 107 | ++ LIBRARY DESTINATION "${INSTALL_LIB_DIR}") |
| 108 | ++ install(EXPORT ZLIBTargets |
| 109 | ++ NAMESPACE ZLIB:: |
| 110 | ++ DESTINATION lib/cmake/ZLIB) |
| 111 | ++ include(CMakePackageConfigHelpers) |
| 112 | ++ write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/ZLIBConfigVersion.cmake" |
| 113 | ++ VERSION ${PROJECT_VERSION} |
| 114 | ++ COMPATIBILITY SameMajorVersion) |
| 115 | ++ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/ZLIBConfig.cmake" |
| 116 | ++ "include(\"\${CMAKE_CURRENT_LIST_DIR}/ZLIBTargets.cmake\")" |
| 117 | ++ ) |
| 118 | ++ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ZLIBConfig.cmake" |
| 119 | ++ "${CMAKE_CURRENT_BINARY_DIR}/ZLIBConfigVersion.cmake" |
| 120 | ++ DESTINATION lib/cmake/ZLIB) |
| 121 | + endif() |
| 122 | ++ |
| 123 | + if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) |
| 124 | + install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}") |
| 125 | + endif() |
| 126 | +@@ -199,20 +229,20 @@ endif() |
| 127 | + #============================================================================ |
| 128 | + if(ZLIB_BUILD_EXAMPLES) |
| 129 | + add_executable(example test/example.c) |
| 130 | +- target_link_libraries(example zlib) |
| 131 | ++ target_link_libraries(example ZLIB) |
| 132 | + add_test(example example) |
| 133 | + |
| 134 | + add_executable(minigzip test/minigzip.c) |
| 135 | +- target_link_libraries(minigzip zlib) |
| 136 | ++ target_link_libraries(minigzip ZLIB) |
| 137 | + |
| 138 | + if(HAVE_OFF64_T) |
| 139 | + add_executable(example64 test/example.c) |
| 140 | +- target_link_libraries(example64 zlib) |
| 141 | ++ target_link_libraries(example64 ZLIB) |
| 142 | + set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") |
| 143 | + add_test(example64 example64) |
| 144 | + |
| 145 | + add_executable(minigzip64 test/minigzip.c) |
| 146 | +- target_link_libraries(minigzip64 zlib) |
| 147 | ++ target_link_libraries(minigzip64 ZLIB) |
| 148 | + set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") |
| 149 | + endif() |
| 150 | + endif() |
0 commit comments