cmake: add pcre2 support
Fix one of the TODOs listed in the CMakeLists.txt by adding support for building with pcre2. As pcre2 doesn't provide cmake find module, we find it with pkgconf. This patch also works with vcpkg on Windows, with pkgconf and pcre2 installed. Pkgconf and pcre2 is detected automatically just like curl, expat and iconv. The output of CMake indicates whether pcre2 is found. Signed-off-by: Yuyi Wang <Strawberry_Str@hotmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Yuyi Wang committed
May 24, 2022 at 06:38 UTC
80431510a2b97e08bd577f39934e2b5ea9a43034
1 file changed
+15
-1
contrib/buildsystems/CMakeLists.txt
+15
-1
@@ -108,7 +108,6 @@ project(git
108
109
#TODO gitk git-gui gitweb
110
#TODO Enable NLS on windows natively
111
-#TODO Add pcre support
111
112
#macros for parsing the Makefile for sources and scripts
113
macro(parse_makefile_for_sources list_var regex)
@@ -160,6 +159,14 @@ if(NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID ST
159
find_package(Intl)
160
endif()
161
162
+find_package(PkgConfig)
163
+if(PkgConfig_FOUND)
164
+ pkg_check_modules(PCRE2 libpcre2-8)
165
+ if(PCRE2_FOUND)
166
+ add_compile_definitions(USE_LIBPCRE2)
167
+ endif()
168
+endif()
169
+
170
if(NOT Intl_FOUND)
171
add_compile_definitions(NO_GETTEXT)
172
if(NOT Iconv_FOUND)
@@ -180,6 +187,9 @@ endif()
187
if(Intl_FOUND)
188
include_directories(SYSTEM ${Intl_INCLUDE_DIRS})
189
endif()
190
+if(PCRE2_FOUND)
191
+ include_directories(SYSTEM ${PCRE2_INCLUDE_DIRS})
192
+endif()
193
194
195
if(WIN32 AND NOT MSVC)#not required for visual studio builds
@@ -700,6 +710,10 @@ endif()
710
if(Iconv_FOUND)
711
target_link_libraries(common-main ${Iconv_LIBRARIES})
712
endif()
713
+if(PCRE2_FOUND)
714
+ target_link_libraries(common-main ${PCRE2_LIBRARIES})
715
+ target_link_directories(common-main PUBLIC ${PCRE2_LIBRARY_DIRS})
716
+endif()
717
if(WIN32)
718
target_link_libraries(common-main ws2_32 ntdll ${CMAKE_BINARY_DIR}/git.res)
719
add_dependencies(common-main git-rc)