mirror of
https://github.com/google/re2.git
synced 2025-10-14 02:17:38 +08:00
Improve support for the optional ICU dependency.
For GNU make, conditionally populate the `Requires:` field in `re2.pc`. Use `pkg-config` to obtain the necessary compiler and linker flags when building `static-testinstall` and `shared-testinstall`. For CMake, the dependency has to be expressed to CMake itself, not just to `pkg-config` as above. Fixes #407. Change-Id: Ie5e0ea88e0662f54be011b3bc0c57f2cfa852f88 Reviewed-on: https://code-review.googlesource.com/c/re2/+/60931 Reviewed-by: Paul Wankadia <junyer@google.com> Reviewed-by: Perry Lorier <perryl@google.com>
This commit is contained in:
@@ -12,12 +12,18 @@ include(CTest)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
option(BUILD_SHARED_LIBS "build shared libraries" OFF)
|
||||
option(USEPCRE "use PCRE in tests and benchmarks" OFF)
|
||||
option(RE2_USE_ICU "build against ICU for full Unicode properties support" OFF)
|
||||
|
||||
# For historical reasons, this is just "USEPCRE", not "RE2_USE_PCRE".
|
||||
option(USEPCRE "build against PCRE for testing and benchmarking" OFF)
|
||||
|
||||
# CMake seems to have no way to enable/disable testing per subproject,
|
||||
# so we provide an option similar to BUILD_TESTING, but just for RE2.
|
||||
option(RE2_BUILD_TESTING "enable testing for RE2" ON)
|
||||
|
||||
# The pkg-config Requires: field.
|
||||
set(REQUIRES)
|
||||
|
||||
# ABI version
|
||||
# http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
|
||||
set(SONAME 10)
|
||||
@@ -43,11 +49,19 @@ endif()
|
||||
if(WIN32)
|
||||
add_definitions(-DUNICODE -D_UNICODE -DSTRICT -DNOMINMAX)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
|
||||
elseif(UNIX)
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
endif()
|
||||
|
||||
if(RE2_USE_ICU)
|
||||
find_package(ICU REQUIRED COMPONENTS uc)
|
||||
add_definitions(-DRE2_USE_ICU)
|
||||
list(APPEND REQUIRES icu-uc)
|
||||
endif()
|
||||
|
||||
if(USEPCRE)
|
||||
add_definitions(-DUSEPCRE)
|
||||
list(APPEND EXTRA_TARGET_LINK_LIBRARIES pcre)
|
||||
@@ -89,6 +103,10 @@ if(UNIX)
|
||||
target_link_libraries(re2 PUBLIC Threads::Threads)
|
||||
endif()
|
||||
|
||||
if(RE2_USE_ICU)
|
||||
target_link_libraries(re2 PUBLIC ICU::uc)
|
||||
endif()
|
||||
|
||||
if(RE2_BUILD_TESTING)
|
||||
set(TESTING_SOURCES
|
||||
re2/testing/backtrack.cc
|
||||
|
25
Makefile
25
Makefile
@@ -7,7 +7,7 @@
|
||||
# CCICU=$(shell pkg-config icu-uc --cflags) -DRE2_USE_ICU
|
||||
# LDICU=$(shell pkg-config icu-uc --libs)
|
||||
|
||||
# To build against PCRE for testing or benchmarking,
|
||||
# To build against PCRE for testing and benchmarking,
|
||||
# uncomment the next two lines:
|
||||
# CCPCRE=-I/usr/local/include -DUSEPCRE
|
||||
# LDPCRE=-L/usr/local/lib -lpcre
|
||||
@@ -42,6 +42,12 @@ else
|
||||
SED_INPLACE=sed -i
|
||||
endif
|
||||
|
||||
# The pkg-config Requires: field.
|
||||
REQUIRES=
|
||||
ifdef LDICU
|
||||
REQUIRES+=icu-uc
|
||||
endif
|
||||
|
||||
# ABI version
|
||||
# http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
|
||||
SONAME=10
|
||||
@@ -320,6 +326,7 @@ common-install:
|
||||
$(INSTALL_DATA) re2.pc.in $(DESTDIR)$(libdir)/pkgconfig/re2.pc
|
||||
$(SED_INPLACE) -e "s#@CMAKE_INSTALL_FULL_INCLUDEDIR@#$(includedir)#" $(DESTDIR)$(libdir)/pkgconfig/re2.pc
|
||||
$(SED_INPLACE) -e "s#@CMAKE_INSTALL_FULL_LIBDIR@#$(libdir)#" $(DESTDIR)$(libdir)/pkgconfig/re2.pc
|
||||
$(SED_INPLACE) -e "s#@REQUIRES@#$(REQUIRES)#" $(DESTDIR)$(libdir)/pkgconfig/re2.pc
|
||||
$(SED_INPLACE) -e "s#@SONAME@#$(SONAME)#" $(DESTDIR)$(libdir)/pkgconfig/re2.pc
|
||||
|
||||
.PHONY: testinstall
|
||||
@@ -329,27 +336,27 @@ testinstall: static-testinstall shared-testinstall
|
||||
@echo
|
||||
|
||||
.PHONY: static-testinstall
|
||||
static-testinstall: CXXFLAGS:=-pthread -I$(DESTDIR)$(includedir) $(CXXFLAGS)
|
||||
static-testinstall: LDFLAGS:=-pthread -L$(DESTDIR)$(libdir) -l:libre2.a $(LDICU) $(LDFLAGS)
|
||||
static-testinstall:
|
||||
@mkdir -p obj
|
||||
@cp testinstall.cc obj/static-testinstall.cc
|
||||
ifeq ($(shell uname),Darwin)
|
||||
@echo Skipping test for libre2.a on Darwin.
|
||||
else ifeq ($(shell uname),SunOS)
|
||||
@echo Skipping test for libre2.a on SunOS.
|
||||
else
|
||||
(cd obj && $(CXX) static-testinstall.cc -o static-testinstall $(CXXFLAGS) $(LDFLAGS))
|
||||
@mkdir -p obj
|
||||
@cp testinstall.cc obj/static-testinstall.cc
|
||||
(cd obj && export PKG_CONFIG_PATH=$(DESTDIR)$(libdir)/pkgconfig; \
|
||||
$(CXX) static-testinstall.cc -o static-testinstall $(CXXFLAGS) $(LDFLAGS) \
|
||||
$$(pkg-config re2 --cflags --libs | sed -e "s#-lre2#-l:libre2.a#"))
|
||||
obj/static-testinstall
|
||||
endif
|
||||
|
||||
.PHONY: shared-testinstall
|
||||
shared-testinstall: CXXFLAGS:=-pthread -I$(DESTDIR)$(includedir) $(CXXFLAGS)
|
||||
shared-testinstall: LDFLAGS:=-pthread -L$(DESTDIR)$(libdir) -lre2 $(LDICU) $(LDFLAGS)
|
||||
shared-testinstall:
|
||||
@mkdir -p obj
|
||||
@cp testinstall.cc obj/shared-testinstall.cc
|
||||
(cd obj && $(CXX) shared-testinstall.cc -o shared-testinstall $(CXXFLAGS) $(LDFLAGS))
|
||||
(cd obj && export PKG_CONFIG_PATH=$(DESTDIR)$(libdir)/pkgconfig; \
|
||||
$(CXX) shared-testinstall.cc -o shared-testinstall $(CXXFLAGS) $(LDFLAGS) \
|
||||
$$(pkg-config re2 --cflags --libs))
|
||||
ifeq ($(shell uname),Darwin)
|
||||
DYLD_LIBRARY_PATH="$(DESTDIR)$(libdir):$(DYLD_LIBRARY_PATH)" obj/shared-testinstall
|
||||
else
|
||||
|
@@ -3,6 +3,7 @@ libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||
|
||||
Name: re2
|
||||
Description: RE2 is a fast, safe, thread-friendly regular expression engine.
|
||||
Requires: @REQUIRES@
|
||||
Version: @SONAME@.0.0
|
||||
Cflags: -pthread -I${includedir}
|
||||
Libs: -pthread -L${libdir} -lre2
|
||||
|
@@ -13,6 +13,10 @@ if(UNIX)
|
||||
find_dependency(Threads REQUIRED)
|
||||
endif()
|
||||
|
||||
if(@RE2_USE_ICU@)
|
||||
find_dependency(ICU REQUIRED COMPONENTS uc)
|
||||
endif()
|
||||
|
||||
check_required_components(re2)
|
||||
|
||||
if(TARGET re2::re2)
|
||||
|
Reference in New Issue
Block a user