Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
*.orig
core
obj/
build/
benchlog.*
user.bazelrc
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ option(RE2_BUILD_FRAMEWORK "build RE2 as a framework" OFF)
option(RE2_TEST "build and run RE2 tests" OFF)
option(RE2_BENCHMARK "build RE2 benchmarks" OFF)
option(RE2_BUILD_TESTING "build and run RE2 tests; build RE2 benchmarks" OFF)
option(RE2_BUILD_MODULES "build RE2 modules" OFF)

# RE2_INSTALL (which defaults to ON) controls whether the installation
# rules are generated.
Expand Down Expand Up @@ -151,6 +152,15 @@ set_target_properties(re2 PROPERTIES PUBLIC_HEADER "${RE2_HEADERS}")
set_target_properties(re2 PROPERTIES SOVERSION ${SONAME} VERSION ${SONAME}.0.0)
add_library(re2::re2 ALIAS re2)

if(RE2_BUILD_MODULES)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
message(STATUS "Building re2 C++ modules")
add_subdirectory(re2/modules)
else()
message(WARNING "Skipping re2 C++ modules (requires CMake 3.28+, found ${CMAKE_VERSION})")
endif()
endif()

if(APPLE AND RE2_BUILD_FRAMEWORK)
set_target_properties(re2 PROPERTIES
FRAMEWORK TRUE
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ If you are using RE2 from another project, you need to make sure you are
using at least C++17.
See the RE2 [.bazelrc](https://github.com/google/re2/blob/main/.bazelrc) file for an example.

If you wish to use C++ modules, use `-DRE2_BUILD_MODULES=ON`. This requires at least C++20.

### Ports and Wrappers

RE2 is implemented in C++.
Expand Down
37 changes: 37 additions & 0 deletions re2/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.28)

add_library(re2modules)
add_library(re2::modules ALIAS re2modules)

set(RE2_MODULES
re2.cppm
)

target_link_libraries(re2modules PUBLIC re2::re2)

if(NOT COMMAND configure_cpp_module_target)
function(configure_cpp_module_target target)
target_sources(${target} PUBLIC FILE_SET CXX_MODULES FILES ${RE2_MODULES})
endfunction()
endif()

configure_cpp_module_target(re2modules)

set_target_properties(re2modules
PROPERTIES
VERSION ${SHARED_LIBRARY_VERSION}
SOVERSION ${SHARED_LIBRARY_VERSION}
OUTPUT_NAME re2modules
DEFINE_SYMBOL re2modules_EXPORTS
)

target_include_directories(re2modules
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE
${CMAKE_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
)

target_compile_features(re2modules PUBLIC cxx_std_20)
33 changes: 33 additions & 0 deletions re2/modules/re2.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2026 The RE2 Authors. All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

module;

#include "re2/filtered_re2.h"
#include "re2/re2.h"
#include "re2/set.h"
#include "re2/stringpiece.h"

export module re2;

export namespace re2 {
using re2::Prog;
using re2::Regexp;
using re2::RE2;
using re2::PrefilterTree;
using re2::FilteredRE2;
using re2::StringPiece;

namespace hooks {
using re2::hooks::context;
using re2::hooks::DFASearchFailure;
using re2::hooks::DFAStateCacheReset;
using re2::hooks::DFASearchFailureCallback;
using re2::hooks::DFAStateCacheResetCallback;
using re2::hooks::GetDFASearchFailureHook;
using re2::hooks::GetDFAStateCacheResetHook;
using re2::hooks::SetDFASearchFailureHook;
using re2::hooks::SetDFAStateCacheResetHook;
}
}