• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2025 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http:/www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specif(ic language governing permissions and
12# limitations under the License.
13
14project(pcre2)
15
16set(PCRE2_DIR
17    ${PANDA_THIRD_PARTY_SOURCES_DIR}/pcre2/pcre2/
18)
19
20set(PCRE2_SRC_DIR
21    ${PCRE2_DIR}/src/
22)
23
24add_definitions(-DHAVE_CONFIG_H)
25
26set(PCRE2_EBCDIC OFF CACHE BOOL
27    "Use EBCDIC coding instead of ASCII. (This is rarely used outside of mainframe systems.)")
28
29set(PCRE2_EBCDIC_NL25 OFF CACHE BOOL
30    "Use 0x25 as EBCDIC NL character instead of 0x15; implies EBCDIC.")
31
32set(PCRE2_LINK_SIZE "2" CACHE STRING
33    "Internal link size (2, 3 or 4 allowed). See LINK_SIZE in config.h.in for details.")
34
35set(PCRE2_PARENS_NEST_LIMIT "250" CACHE STRING
36    "Default nested parentheses limit. See PARENS_NEST_LIMIT in config.h.in for details.")
37
38set(PCRE2_HEAP_LIMIT "20000000" CACHE STRING
39    "Default limit on heap memory (kibibytes). See HEAP_LIMIT in config.h.in for details.")
40
41set(PCRE2_MATCH_LIMIT "10000000" CACHE STRING
42    "Default limit on internal looping. See MATCH_LIMIT in config.h.in for details.")
43
44set(PCRE2_MATCH_LIMIT_DEPTH "MATCH_LIMIT" CACHE STRING
45    "Default limit on internal depth of search. See MATCH_LIMIT_DEPTH in config.h.in for details.")
46
47set(PCRE2GREP_BUFSIZE "20480" CACHE STRING
48    "Buffer starting size parameter for pcre2grep. See PCRE2GREP_BUFSIZE in config.h.in for details.")
49
50set(PCRE2GREP_MAX_BUFSIZE "1048576" CACHE STRING
51    "Buffer maximum size parameter for pcre2grep. See PCRE2GREP_MAX_BUFSIZE in config.h.in for details.")
52
53set(PCRE2_NEWLINE "LF" CACHE STRING
54    "What to recognize as a newline (one of CR, LF, CRLF, ANY, ANYCRLF, NUL).")
55
56set(PCRE2_HEAP_MATCH_RECURSE OFF CACHE BOOL
57    "Obsolete option: do not use")
58
59set(PCRE2_SUPPORT_JIT OFF CACHE BOOL
60    "Enable support for Just-in-time compiling.")
61
62set(NEWLINE_DEFAULT "")
63
64if(PCRE2_NEWLINE STREQUAL "CR")
65    set(NEWLINE_DEFAULT "1")
66endif(PCRE2_NEWLINE STREQUAL "CR")
67if(PCRE2_NEWLINE STREQUAL "LF")
68    set(NEWLINE_DEFAULT "2")
69endif(PCRE2_NEWLINE STREQUAL "LF")
70if(PCRE2_NEWLINE STREQUAL "CRLF")
71    set(NEWLINE_DEFAULT "3")
72endif(PCRE2_NEWLINE STREQUAL "CRLF")
73if(PCRE2_NEWLINE STREQUAL "ANY")
74    set(NEWLINE_DEFAULT "4")
75endif(PCRE2_NEWLINE STREQUAL "ANY")
76if(PCRE2_NEWLINE STREQUAL "ANYCRLF")
77    set(NEWLINE_DEFAULT "5")
78endif(PCRE2_NEWLINE STREQUAL "ANYCRLF")
79if(PCRE2_NEWLINE STREQUAL "NUL")
80    set(NEWLINE_DEFAULT "6")
81endif(PCRE2_NEWLINE STREQUAL "NUL")
82
83if(NEWLINE_DEFAULT STREQUAL "")
84    message(FATAL_ERROR "The PCRE2_NEWLINE variable must be set to one of the following values: \"LF\", \"CR\", \"CRLF\", \"ANY\", \"ANYCRLF\".")
85endif(NEWLINE_DEFAULT STREQUAL "")
86
87if(PCRE2_EBCDIC)
88    set(EBCDIC 1)
89endif(PCRE2_EBCDIC)
90
91if(PCRE2_EBCDIC_NL25)
92    set(EBCDIC 1)
93    set(EBCDIC_NL25 1)
94endif(PCRE2_EBCDIC_NL25)
95
96set(PCRE2_CFLAGS_CC
97    -fPIC
98)
99
100set(PCRE2_SOURCES
101  ${PCRE2_SRC_DIR}/pcre2_auto_possess.c
102  ${PCRE2_SRC_DIR}/pcre2_chartables.c
103  ${PCRE2_SRC_DIR}/pcre2_chkdint.c
104  ${PCRE2_SRC_DIR}/pcre2_compile.c
105  ${PCRE2_SRC_DIR}/pcre2_config.c
106  ${PCRE2_SRC_DIR}/pcre2_context.c
107  ${PCRE2_SRC_DIR}/pcre2_convert.c
108  ${PCRE2_SRC_DIR}/pcre2_dfa_match.c
109  ${PCRE2_SRC_DIR}/pcre2_error.c
110  ${PCRE2_SRC_DIR}/pcre2_extuni.c
111  ${PCRE2_SRC_DIR}/pcre2_find_bracket.c
112  ${PCRE2_SRC_DIR}/pcre2_jit_compile.c
113  ${PCRE2_SRC_DIR}/pcre2_maketables.c
114  ${PCRE2_SRC_DIR}/pcre2_match.c
115  ${PCRE2_SRC_DIR}/pcre2_match_data.c
116  ${PCRE2_SRC_DIR}/pcre2_newline.c
117  ${PCRE2_SRC_DIR}/pcre2_ord2utf.c
118  ${PCRE2_SRC_DIR}/pcre2_pattern_info.c
119  ${PCRE2_SRC_DIR}/pcre2_script_run.c
120  ${PCRE2_SRC_DIR}/pcre2_serialize.c
121  ${PCRE2_SRC_DIR}/pcre2_string_utils.c
122  ${PCRE2_SRC_DIR}/pcre2_study.c
123  ${PCRE2_SRC_DIR}/pcre2_substitute.c
124  ${PCRE2_SRC_DIR}/pcre2_substring.c
125  ${PCRE2_SRC_DIR}/pcre2_tables.c
126  ${PCRE2_SRC_DIR}/pcre2_ucd.c
127  ${PCRE2_SRC_DIR}/pcre2_valid_utf.c
128  ${PCRE2_SRC_DIR}/pcre2_xclass.c
129)
130
131set(PCRE2_HEADERS ${PROJECT_BINARY_DIR}/pcre2.h)
132
133panda_target_include_directories(arkruntime_obj SYSTEM PUBLIC
134    ${PCRE2_SRC_DIR}/
135    ${PROJECT_BINARY_DIR}/
136)
137
138file(STRINGS ${PCRE2_DIR}/configure.ac
139  configure_lines
140  LIMIT_COUNT 50 # Read only the first 50 lines of the file
141)
142
143set(SEARCHED_VARIABLES "pcre2_major" "pcre2_minor" "pcre2_prerelease" "pcre2_date"
144  "libpcre2_posix_version" "libpcre2_8_version" "libpcre2_16_version" "libpcre2_32_version")
145foreach(configure_line ${configure_lines})
146    foreach(_substitution_variable ${SEARCHED_VARIABLES})
147        string(TOUPPER ${_substitution_variable} _substitution_variable_upper)
148        if(NOT ${_substitution_variable_upper})
149            string(REGEX MATCH "m4_define\\(${_substitution_variable}, *\\[(.*)\\]" MATCHED_STRING ${configure_line})
150            if(CMAKE_MATCH_1)
151                set(${_substitution_variable_upper} ${CMAKE_MATCH_1})
152            endif()
153        endif()
154    endforeach()
155endforeach()
156
157macro(PARSE_LIB_VERSION VARIABLE_PREFIX)
158  string(REPLACE ":" ";" ${VARIABLE_PREFIX}_VERSION_LIST ${${VARIABLE_PREFIX}_VERSION})
159  list(GET ${VARIABLE_PREFIX}_VERSION_LIST 0 ${VARIABLE_PREFIX}_VERSION_CURRENT)
160  list(GET ${VARIABLE_PREFIX}_VERSION_LIST 1 ${VARIABLE_PREFIX}_VERSION_REVISION)
161  list(GET ${VARIABLE_PREFIX}_VERSION_LIST 2 ${VARIABLE_PREFIX}_VERSION_AGE)
162
163  math(EXPR ${VARIABLE_PREFIX}_SOVERSION "${${VARIABLE_PREFIX}_VERSION_CURRENT} - ${${VARIABLE_PREFIX}_VERSION_AGE}")
164  math(EXPR ${VARIABLE_PREFIX}_MACHO_COMPATIBILITY_VERSION "${${VARIABLE_PREFIX}_VERSION_CURRENT} + 1")
165  math(EXPR ${VARIABLE_PREFIX}_MACHO_CURRENT_VERSION "${${VARIABLE_PREFIX}_VERSION_CURRENT} + 1")
166  set(${VARIABLE_PREFIX}_MACHO_CURRENT_VERSION "${${VARIABLE_PREFIX}_MACHO_CURRENT_VERSION}.${${VARIABLE_PREFIX}_VERSION_REVISION}}")
167  set(${VARIABLE_PREFIX}_VERSION "${${VARIABLE_PREFIX}_SOVERSION}.${${VARIABLE_PREFIX}_VERSION_AGE}.${${VARIABLE_PREFIX}_VERSION_REVISION}")
168endmacro()
169
170PARSE_LIB_VERSION(LIBPCRE2_POSIX)
171PARSE_LIB_VERSION(LIBPCRE2_8)
172PARSE_LIB_VERSION(LIBPCRE2_16)
173PARSE_LIB_VERSION(LIBPCRE2_32)
174
175add_dependencies(arkruntime_obj pcre2-8-static)
176add_dependencies(arkruntime_obj pcre2-16-static)
177
178SET(SUPPORT_UNICODE 1)
179
180configure_file(${PCRE2_SRC_DIR}/pcre2.h.in ${PROJECT_BINARY_DIR}/pcre2.h @ONLY)
181configure_file(${PCRE2_SRC_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h @ONLY)
182
183configure_file(${PCRE2_DIR}/config-cmake.h.in
184               ${PROJECT_BINARY_DIR}/config.h
185               @ONLY)
186
187configure_file(${PCRE2_DIR}/libpcre2-8.pc.in libpcre2-8.pc @ONLY)
188configure_file(${PCRE2_DIR}/libpcre2-16.pc.in libpcre2-16.pc @ONLY)
189configure_file(${PCRE2_DIR}/pcre2-config.in pcre2-config @ONLY)
190
191panda_add_library(pcre2-8-static STATIC ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h)
192set_target_properties(pcre2-8-static PROPERTIES
193  COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=8
194  MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_8_MACHO_COMPATIBILITY_VERSION}"
195  MACHO_CURRENT_VERSION "${LIBPCRE2_8_MACHO_CURRENT_VERSION}"
196  VERSION ${LIBPCRE2_8_VERSION}
197  SOVERSION ${LIBPCRE2_8_SOVERSION}
198)
199panda_target_compile_definitions(pcre2-8-static PUBLIC PCRE2_STATIC)
200set(targets ${targets} pcre2-8-static)
201
202if(MSVC)
203  set_target_properties(pcre2-8-static PROPERTIES OUTPUT_NAME pcre2-8-static)
204else(MSVC)
205  set_target_properties(pcre2-8-static PROPERTIES OUTPUT_NAME pcre2-8)
206endif(MSVC)
207
208panda_add_library(pcre2-16-static STATIC ${PCRE2_HEADERS} ${PCRE2_SOURCES} ${PROJECT_BINARY_DIR}/config.h)
209set_target_properties(pcre2-16-static PROPERTIES
210  COMPILE_DEFINITIONS PCRE2_CODE_UNIT_WIDTH=16
211  MACHO_COMPATIBILITY_VERSION "${LIBPCRE2_32_MACHO_COMPATIBILITY_VERSION}"
212  MACHO_CURRENT_VERSION "${LIBPCRE2_32_MACHO_CURRENT_VERSION}"
213  VERSION ${LIBPCRE2_16_VERSION}
214  SOVERSION ${LIBPCRE2_16_SOVERSION})
215panda_target_compile_definitions(pcre2-16-static PUBLIC PCRE2_STATIC)
216set(targets ${targets} pcre2-16-static)
217
218if(MSVC)
219  set_target_properties(pcre2-16-static PROPERTIES OUTPUT_NAME pcre2-16-static)
220else(MSVC)
221  set_target_properties(pcre2-16-static PROPERTIES OUTPUT_NAME pcre2-16)
222endif(MSVC)
223
224panda_target_include_directories(pcre2-8-static SYSTEM PUBLIC
225    ${PCRE2_SRC_DIR}/
226    ${PROJECT_BINARY_DIR}/
227)
228
229panda_target_include_directories(pcre2-16-static SYSTEM PUBLIC
230    ${PCRE2_SRC_DIR}/
231    ${PROJECT_BINARY_DIR}/
232)
233
234panda_target_compile_options(pcre2-8-static
235    PRIVATE
236    ${PCRE2_CFLAGS_CC}
237)
238
239panda_target_compile_options(pcre2-16-static
240    PRIVATE
241    ${PCRE2_CFLAGS_CC}
242)
243
244panda_target_link_libraries(arkruntime_obj pcre2-8-static)
245panda_target_link_libraries(arkruntime_obj pcre2-16-static)
246