SgZLib.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #.rst:
  2. # SgZLib
  3. # ------
  4. #
  5. # Build ZLib.
  6. #
  7. # Build ZLib from Sagui building.
  8. #
  9. # ::
  10. #
  11. # ZLIB_INCLUDE_DIR - Directory of includes.
  12. # ZLIB_ARCHIVE_LIB - AR archive library.
  13. # _
  14. # ___ __ _ __ _ _ _(_)
  15. # / __|/ _` |/ _` | | | | |
  16. # \__ \ (_| | (_| | |_| | |
  17. # |___/\__,_|\__, |\__,_|_|
  18. # |___/
  19. #
  20. # Cross-platform library which helps to develop web servers or frameworks.
  21. #
  22. # Copyright (C) 2016-2024 Silvio Clecio <[email protected]>
  23. #
  24. # Sagui library is free software; you can redistribute it and/or
  25. # modify it under the terms of the GNU Lesser General Public
  26. # License as published by the Free Software Foundation; either
  27. # version 2.1 of the License, or (at your option) any later version.
  28. #
  29. # Sagui library is distributed in the hope that it will be useful,
  30. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  32. # Lesser General Public License for more details.
  33. #
  34. # You should have received a copy of the GNU Lesser General Public
  35. # License along with Sagui library; if not, write to the Free Software
  36. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  37. #
  38. if(__SG_ZLIB_INCLUDED)
  39. return()
  40. endif()
  41. set(__SG_ZLIB_INCLUDED ON)
  42. if(CMAKE_VERSION VERSION_GREATER "3.23")
  43. cmake_policy(SET CMP0135 NEW)
  44. endif()
  45. set(ZLIB_NAME "zlib")
  46. set(ZLIB_VER "1.3.1")
  47. set(ZLIB_FULL_NAME "${ZLIB_NAME}-${ZLIB_VER}")
  48. set(ZLIB_URL "https://zlib.net/${ZLIB_FULL_NAME}.tar.gz")
  49. set(ZLIB_URL_MIRROR
  50. "https://github.com/madler/zlib/releases/download/v${ZLIB_VER}/${ZLIB_FULL_NAME}.tar.gz"
  51. )
  52. set(ZLIB_SHA256
  53. "9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23")
  54. if(${CMAKE_VERSION} VERSION_LESS "3.7")
  55. unset(ZLIB_URL_MIRROR)
  56. endif()
  57. if(CMAKE_C_COMPILER)
  58. set(ZLIB_OPTIONS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER})
  59. endif()
  60. if(CMAKE_RC_COMPILER)
  61. set(ZLIB_OPTIONS ${ZLIB_OPTIONS} -DCMAKE_RC_COMPILER=${CMAKE_RC_COMPILER})
  62. endif()
  63. if(CMAKE_SYSTEM_NAME)
  64. set(ZLIB_OPTIONS ${ZLIB_OPTIONS} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME})
  65. endif()
  66. if(UNIX)
  67. set(ZLIB_OPTIONS ${ZLIB_OPTIONS} -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
  68. endif()
  69. if(ANDROID)
  70. set(ZLIB_OPTIONS
  71. ${ZLIB_OPTIONS}
  72. -DCMAKE_ANDROID_ARM_MODE=${CMAKE_ANDROID_ARM_MODE}
  73. -DCMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION}
  74. -DCMAKE_ANDROID_ARCH_ABI=${CMAKE_ANDROID_ARCH_ABI}
  75. -DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}
  76. )
  77. endif()
  78. set(ZLIB_OPTIONS ${ZLIB_OPTIONS} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  79. -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/${ZLIB_FULL_NAME})
  80. ExternalProject_Add(
  81. ${ZLIB_FULL_NAME}
  82. URL ${ZLIB_URL} ${ZLIB_URL_MIRROR}
  83. URL_HASH SHA256=${ZLIB_SHA256}
  84. TIMEOUT 15
  85. DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/lib
  86. PREFIX ${CMAKE_BINARY_DIR}/${ZLIB_FULL_NAME}
  87. SOURCE_DIR ${CMAKE_SOURCE_DIR}/lib/${ZLIB_FULL_NAME}
  88. CMAKE_ARGS ${ZLIB_OPTIONS}
  89. LOG_DOWNLOAD ON
  90. LOG_CONFIGURE ON
  91. LOG_BUILD ON
  92. LOG_INSTALL ON)
  93. ExternalProject_Get_Property(${ZLIB_FULL_NAME} INSTALL_DIR)
  94. set(ZLIB_INCLUDE_DIR ${INSTALL_DIR}/include)
  95. if(WIN32)
  96. set(ZLIB_NAME "zlibstatic")
  97. else()
  98. set(ZLIB_NAME "z")
  99. endif()
  100. set(ZLIB_ARCHIVE_LIB ${INSTALL_DIR}/lib/lib${ZLIB_NAME}.a)
  101. unset(INSTALL_DIR)