Skip to content

Commit

Permalink
Fix the GNU make and CMake configurations and CI workflows.
Browse files Browse the repository at this point in the history
Change-Id: I0ed384b0598d2bdaec1d41b51cd0de5d49e83481
Reviewed-on: https://code-review.googlesource.com/c/re2/+/61270
Reviewed-by: Paul Wankadia <junyer@google.com>
Reviewed-by: Alex Chernyakhovsky <achernya@google.com>
  • Loading branch information
junyer committed May 17, 2023
1 parent 49d776b commit 552c2b8
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 32 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,20 @@ jobs:
os: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- if: matrix.os == 'macos-latest'
name: Install dependencies (macOS)
run: |
brew install abseil googletest google-benchmark
shell: bash
- if: matrix.os == 'ubuntu-latest'
name: Install dependencies (Ubuntu)
run: |
sudo apt install libabsl-dev libgtest-dev libbenchmark-dev
shell: bash
- if: matrix.os == 'windows-latest'
name: Install dependencies (Windows)
run: |
vcpkg install abseil gtest benchmark
shell: bash
- run: .github/cmake.sh
shell: bash
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
CXXFLAGS: -O3 -g -std=c++${{ matrix.ver }}
steps:
- uses: actions/checkout@v3
- name: Install dependencies (macOS)
run: |
brew install abseil googletest google-benchmark
shell: bash
- run: make && make test
shell: bash
build-clang:
Expand All @@ -39,6 +43,10 @@ jobs:
chmod +x ./llvm.sh
sudo ./llvm.sh ${{ matrix.ver }}
shell: bash
- name: Install dependencies (Ubuntu)
run: |
sudo apt install libabsl-dev libgtest-dev libbenchmark-dev
shell: bash
- run: make && make test
shell: bash
build-gcc:
Expand All @@ -53,5 +61,9 @@ jobs:
CXX: g++
steps:
- uses: actions/checkout@v3
- name: Install dependencies (Ubuntu)
run: |
sudo apt install libabsl-dev libgtest-dev libbenchmark-dev
shell: bash
- run: make && make test
shell: bash
55 changes: 43 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ set(REQUIRES)

# ABI version
# http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
set(SONAME 10)
set(SONAME 11)

set(EXTRA_TARGET_LINK_LIBRARIES)

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(MSVC_VERSION LESS 1900)
message(FATAL_ERROR "you need Visual Studio 2015 or later")
if(MSVC_VERSION LESS 1920)
message(FATAL_ERROR "you need Visual Studio 2019 or later")
endif()
if(BUILD_SHARED_LIBS)
# See http://www.kitware.com/blog/home/post/939 for details.
Expand All @@ -61,6 +61,24 @@ if(UNIX)
find_package(Threads REQUIRED)
endif()

set(ABSL_DEPS
absl_base
absl_core_headers
absl_fixed_array
absl_flags
absl_flat_hash_map
absl_flat_hash_set
absl_inlined_vector
absl_optional
absl_span
absl_str_format
absl_strings
absl_synchronization
)

find_package(absl REQUIRED)
list(APPEND REQUIRES ${ABSL_DEPS})

if(RE2_USE_ICU)
find_package(ICU REQUIRED COMPONENTS uc)
add_definitions(-DRE2_USE_ICU)
Expand All @@ -72,6 +90,12 @@ if(USEPCRE)
list(APPEND EXTRA_TARGET_LINK_LIBRARIES pcre)
endif()

# TODO(junyer): Use string(JOIN " " ...) whenever CMake 3.12 (or newer) becomes
# the minimum required: that will make this hack slightly less filthy. For now,
# CMake does the same thing as string(CONCAT ...), basically, if we don't quote
# ${REQUIRES}, so quote it despite prevailing style.
string(REPLACE ";" " " REQUIRES "${REQUIRES}")

set(RE2_SOURCES
re2/bitmap256.cc
re2/bitstate.cc
Expand All @@ -90,7 +114,6 @@ set(RE2_SOURCES
re2/regexp.cc
re2/set.cc
re2/simplify.cc
re2/stringpiece.cc
re2/tostring.cc
re2/unicode_casefold.cc
re2/unicode_groups.cc
Expand All @@ -106,7 +129,7 @@ set(RE2_HEADERS
)

add_library(re2 ${RE2_SOURCES})
target_compile_features(re2 PUBLIC cxx_std_11)
target_compile_features(re2 PUBLIC cxx_std_14)
target_include_directories(re2 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
# CMake gives "set_target_properties called with incorrect number of arguments."
# errors if we don't quote ${RE2_HEADERS}, so quote it despite prevailing style.
Expand All @@ -125,11 +148,19 @@ if(UNIX)
target_link_libraries(re2 PUBLIC Threads::Threads)
endif()

foreach(dep ${ABSL_DEPS})
string(REGEX REPLACE "^absl_" "absl::" dep ${dep})
target_link_libraries(re2 PUBLIC ${dep})
endforeach()

if(RE2_USE_ICU)
target_link_libraries(re2 PUBLIC ICU::uc)
endif()

if(RE2_BUILD_TESTING)
find_package(GTest REQUIRED)
find_package(benchmark REQUIRED)

set(TESTING_SOURCES
re2/testing/backtrack.cc
re2/testing/dump.cc
Expand All @@ -142,7 +173,7 @@ if(RE2_BUILD_TESTING)
)

add_library(testing STATIC ${TESTING_SOURCES})
target_compile_features(testing PUBLIC cxx_std_11)
target_compile_features(testing PUBLIC cxx_std_14)
target_link_libraries(testing PUBLIC re2)

set(TEST_TARGETS
Expand Down Expand Up @@ -174,16 +205,16 @@ if(RE2_BUILD_TESTING)
)

foreach(target ${TEST_TARGETS})
add_executable(${target} re2/testing/${target}.cc util/test.cc)
target_compile_features(${target} PUBLIC cxx_std_11)
target_link_libraries(${target} testing ${EXTRA_TARGET_LINK_LIBRARIES})
add_executable(${target} re2/testing/${target}.cc)
target_compile_features(${target} PUBLIC cxx_std_14)
target_link_libraries(${target} testing GTest::GTest GTest::Main ${EXTRA_TARGET_LINK_LIBRARIES})
add_test(NAME ${target} COMMAND ${target})
endforeach()

foreach(target ${BENCHMARK_TARGETS})
add_executable(${target} re2/testing/${target}.cc util/benchmark.cc)
target_compile_features(${target} PUBLIC cxx_std_11)
target_link_libraries(${target} testing ${EXTRA_TARGET_LINK_LIBRARIES})
add_executable(${target} re2/testing/${target}.cc)
target_compile_features(${target} PUBLIC cxx_std_14)
target_link_libraries(${target} testing GTest::GTest benchmark::benchmark_main ${EXTRA_TARGET_LINK_LIBRARIES})
endforeach()
endif()

Expand Down
50 changes: 30 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# Build against Abseil.
ABSL_DEPS=\
absl_base\
absl_core_headers\
absl_fixed_array\
absl_flags\
absl_flat_hash_map\
absl_flat_hash_set\
absl_inlined_vector\
absl_optional\
absl_span\
absl_str_format\
absl_strings\
absl_synchronization\

CCABSL=$(shell pkg-config $(ABSL_DEPS) --cflags)
LDABSL=$(shell pkg-config $(ABSL_DEPS) --libs)

# To build against ICU for full Unicode properties support,
# uncomment the next two lines:
# CCICU=$(shell pkg-config icu-uc --cflags) -DRE2_USE_ICU
Expand All @@ -17,8 +35,8 @@ CXX?=g++
CXXFLAGS?=-O3 -g
LDFLAGS?=
# required
RE2_CXXFLAGS?=-pthread -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -I. $(CCICU) $(CCPCRE)
RE2_LDFLAGS?=-pthread $(LDICU) $(LDPCRE)
RE2_CXXFLAGS?=-pthread -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -I. $(CCABSL) $(CCICU) $(CCPCRE)
RE2_LDFLAGS?=-pthread $(LDABSL) $(LDICU) $(LDPCRE)
AR?=ar
ARFLAGS?=rsc
NM?=nm
Expand All @@ -43,14 +61,14 @@ SED_INPLACE=sed -i
endif

# The pkg-config Requires: field.
REQUIRES=
REQUIRES=$(ABSL_DEPS)
ifdef LDICU
REQUIRES+=icu-uc
endif

# ABI version
# http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
SONAME=10
SONAME=11

# To rebuild the Tables generated by Perl and Python scripts (requires Internet
# access for Unicode data), uncomment the following line:
Expand Down Expand Up @@ -84,17 +102,11 @@ INSTALL_HFILES=\
re2/stringpiece.h\

HFILES=\
util/benchmark.h\
util/flags.h\
util/logging.h\
util/malloc_counter.h\
util/mix.h\
util/mutex.h\
util/pcre.h\
util/strutil.h\
util/test.h\
util/utf.h\
util/util.h\
re2/bitmap256.h\
re2/filtered_re2.h\
re2/pod_array.h\
Expand Down Expand Up @@ -135,7 +147,6 @@ OFILES=\
obj/re2/regexp.o\
obj/re2/set.o\
obj/re2/simplify.o\
obj/re2/stringpiece.o\
obj/re2/tostring.o\
obj/re2/unicode_casefold.o\
obj/re2/unicode_groups.o\
Expand Down Expand Up @@ -216,25 +227,24 @@ obj/so/libre2.$(SOEXT): $(SOFILES) libre2.symbols libre2.symbols.darwin
ln -sf libre2.$(SOEXTVER) $@

.PRECIOUS: obj/dbg/test/%
obj/dbg/test/%: obj/dbg/libre2.a obj/dbg/re2/testing/%.o $(DTESTOFILES) obj/dbg/util/test.o
obj/dbg/test/%: obj/dbg/libre2.a obj/dbg/re2/testing/%.o $(DTESTOFILES)
@mkdir -p obj/dbg/test
$(CXX) -o $@ obj/dbg/re2/testing/$*.o $(DTESTOFILES) obj/dbg/util/test.o obj/dbg/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)
$(CXX) -o $@ obj/dbg/re2/testing/$*.o $(DTESTOFILES) -lgtest -lgtest_main obj/dbg/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)

.PRECIOUS: obj/test/%
obj/test/%: obj/libre2.a obj/re2/testing/%.o $(TESTOFILES) obj/util/test.o
obj/test/%: obj/libre2.a obj/re2/testing/%.o $(TESTOFILES)
@mkdir -p obj/test
$(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) obj/util/test.o obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)
$(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) -lgtest -lgtest_main obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)

# Test the shared lib, falling back to the static lib for private symbols
.PRECIOUS: obj/so/test/%
obj/so/test/%: obj/so/libre2.$(SOEXT) obj/libre2.a obj/re2/testing/%.o $(TESTOFILES) obj/util/test.o
obj/so/test/%: obj/so/libre2.$(SOEXT) obj/libre2.a obj/re2/testing/%.o $(TESTOFILES)
@mkdir -p obj/so/test
$(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) obj/util/test.o -Lobj/so -lre2 obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)
$(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) -lgtest -lgtest_main -Lobj/so -lre2 obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)

# Filter out dump.o because testing::TempDir() isn't available for it.
obj/test/regexp_benchmark: obj/libre2.a obj/re2/testing/regexp_benchmark.o $(TESTOFILES) obj/util/benchmark.o
obj/test/regexp_benchmark: obj/libre2.a obj/re2/testing/regexp_benchmark.o $(TESTOFILES)
@mkdir -p obj/test
$(CXX) -o $@ obj/re2/testing/regexp_benchmark.o $(filter-out obj/re2/testing/dump.o, $(TESTOFILES)) obj/util/benchmark.o obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)
$(CXX) -o $@ obj/re2/testing/regexp_benchmark.o $(TESTOFILES) -lgtest -lbenchmark -lbenchmark_main obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)

# re2_fuzzer is a target for fuzzers like libFuzzer and AFL. This fake fuzzing
# is simply a way to check that the target builds and then to run it against a
Expand Down
5 changes: 5 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ make test
make install
make testinstall

Building RE2 requires Abseil (https://github.com/abseil/abseil-cpp)
to be installed on your system. Building the testing for RE2 requires
GoogleTest (https://github.com/google/googletest) and Benchmark
(https://github.com/google/benchmark) to be installed as well.

There is a fair amount of documentation (including code snippets) in
the re2.h header file.

Expand Down
2 changes: 2 additions & 0 deletions re2Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if(UNIX)
find_dependency(Threads REQUIRED)
endif()

find_dependency(absl REQUIRED)

if(@RE2_USE_ICU@)
find_dependency(ICU REQUIRED COMPONENTS uc)
endif()
Expand Down

0 comments on commit 552c2b8

Please sign in to comment.