SgPCRE2.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #.rst:
  2. # SgPCRE2
  3. # -------
  4. #
  5. # Build PCRE2.
  6. #
  7. # Build PCRE2 from Sagui building.
  8. #
  9. # ::
  10. #
  11. # PCRE2_INCLUDE_DIR - Directory of includes.
  12. # PCRE2_ARCHIVE_LIB - AR archive library.
  13. # PCRE2_JIT_SUPPORT - Enable/disable JIT support.
  14. # _
  15. # ___ __ _ __ _ _ _(_)
  16. # / __|/ _` |/ _` | | | | |
  17. # \__ \ (_| | (_| | |_| | |
  18. # |___/\__,_|\__, |\__,_|_|
  19. # |___/
  20. #
  21. # Cross-platform library which helps to develop web servers or frameworks.
  22. #
  23. # Copyright (C) 2016-2024 Silvio Clecio <[email protected]>
  24. #
  25. # Sagui library is free software; you can redistribute it and/or
  26. # modify it under the terms of the GNU Lesser General Public
  27. # License as published by the Free Software Foundation; either
  28. # version 2.1 of the License, or (at your option) any later version.
  29. #
  30. # Sagui library is distributed in the hope that it will be useful,
  31. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  33. # Lesser General Public License for more details.
  34. #
  35. # You should have received a copy of the GNU Lesser General Public
  36. # License along with Sagui library; if not, write to the Free Software
  37. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  38. #
  39. if(__SG_PCRE2_INCLUDED)
  40. return()
  41. endif()
  42. set(__SG_PCRE2_INCLUDED ON)
  43. option(PCRE2_JIT_SUPPORT "Enable JIT support" ON)
  44. if(CMAKE_VERSION VERSION_GREATER "3.23")
  45. cmake_policy(SET CMP0135 NEW)
  46. endif()
  47. set(PCRE2_NAME "pcre2")
  48. set(PCRE2_VER "10.42")
  49. set(PCRE2_FULL_NAME "${PCRE2_NAME}-${PCRE2_VER}")
  50. set(PCRE2_URL
  51. "https://github.com/PCRE2Project/pcre2/releases/download/${PCRE2_FULL_NAME}/${PCRE2_FULL_NAME}.tar.gz"
  52. )
  53. set(PCRE2_URL_MIRROR
  54. "https://github.com/PCRE2Project/pcre2/releases/download/${PCRE2_FULL_NAME}/${PCRE2_FULL_NAME}.tar.gz"
  55. )
  56. set(PCRE2_SHA256 "c33b418e3b936ee3153de2c61cc638e7e4fe3156022a5c77d0711bcbb9d64f1f")
  57. if(${CMAKE_VERSION} VERSION_LESS "3.7")
  58. unset(PCRE2_URL_MIRROR)
  59. endif()
  60. if(CMAKE_C_COMPILER)
  61. set(PCRE2_OPTIONS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER})
  62. endif()
  63. if(CMAKE_RC_COMPILER)
  64. set(PCRE2_OPTIONS ${PCRE2_OPTIONS} -DCMAKE_RC_COMPILER=${CMAKE_RC_COMPILER})
  65. endif()
  66. if(CMAKE_SYSTEM_NAME)
  67. set(PCRE2_OPTIONS ${PCRE2_OPTIONS} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME})
  68. endif()
  69. if(UNIX)
  70. set(PCRE2_OPTIONS ${PCRE2_OPTIONS} -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
  71. endif()
  72. if(ANDROID)
  73. set(PCRE2_OPTIONS
  74. ${PCRE2_OPTIONS}
  75. -DCMAKE_ANDROID_ARM_MODE=${CMAKE_ANDROID_ARM_MODE}
  76. -DCMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION}
  77. -DCMAKE_ANDROID_ARCH_ABI=${CMAKE_ANDROID_ARCH_ABI}
  78. -DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}
  79. )
  80. endif()
  81. set(PCRE2_OPTIONS
  82. ${PCRE2_OPTIONS}
  83. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  84. -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/${PCRE2_FULL_NAME}
  85. -DPCRE2_BUILD_PCRE2GREP=OFF
  86. -DPCRE2_BUILD_TESTS=OFF
  87. -DPCRE2_SUPPORT_JIT=${PCRE2_JIT_SUPPORT}
  88. -DPCRE2_SUPPORT_UNICODE=OFF
  89. -DPCRE2_SUPPORT_VALGRIND=OFF
  90. -DPCRE2_SUPPORT_LIBBZ2=OFF
  91. -DPCRE2_SUPPORT_LIBZ=OFF
  92. -DPCRE2_SUPPORT_LIBEDIT=OFF
  93. -DPCRE2_SUPPORT_LIBREADLINE=OFF)
  94. ExternalProject_Add(
  95. ${PCRE2_FULL_NAME}
  96. URL ${PCRE2_URL} ${PCRE2_URL_MIRROR}
  97. URL_HASH SHA256=${PCRE2_SHA256}
  98. TIMEOUT 15
  99. DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/lib
  100. PREFIX ${CMAKE_BINARY_DIR}/${PCRE2_FULL_NAME}
  101. SOURCE_DIR ${CMAKE_SOURCE_DIR}/lib/${PCRE2_FULL_NAME}
  102. CMAKE_ARGS ${PCRE2_OPTIONS}
  103. LOG_DOWNLOAD ON
  104. LOG_CONFIGURE ON
  105. LOG_BUILD ON
  106. LOG_INSTALL ON)
  107. ExternalProject_Get_Property(${PCRE2_FULL_NAME} INSTALL_DIR)
  108. set(PCRE2_INCLUDE_DIR ${INSTALL_DIR}/include)
  109. if(WIN32 AND (CMAKE_BUILD_TYPE MATCHES "[Dd]ebug|DEBUG"))
  110. set(PCRE2_SUFFIX "d")
  111. endif()
  112. set(PCRE2_ARCHIVE_LIB ${INSTALL_DIR}/lib/lib${PCRE2_NAME}-8${PCRE2_SUFFIX}.a)
  113. add_definitions(-DPCRE2_STATIC=1)
  114. add_definitions(-DPCRE2_CODE_UNIT_WIDTH=8)
  115. if(PCRE2_JIT_SUPPORT)
  116. add_definitions(-DPCRE2_JIT_SUPPORT=1)
  117. endif()
  118. unset(INSTALL_DIR)