Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to protobuf 3.25.1 #3394

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
75 changes: 47 additions & 28 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ if (USE_ALTERNATE_FORMATS)
endif ()

# Find all the required libraries and programs.
find_package(absl)
# Use "CONFIG" as there is no built-in cmake module for absl.
find_package(absl CONFIG REQUIRED)

if(NOT absl_FOUND)
# Overide abseil install rules for subprojects
Expand Down Expand Up @@ -169,14 +170,24 @@ if (USE_RE2)
find_required_library (RE2 re2/re2.h re2 "Google RE2")
endif ()

if (USE_PROTOBUF_LITE)
find_required_library (PROTOBUF google/protobuf/message_lite.h protobuf-lite
"Google Protocol Buffers")
check_library_version (PC_PROTOBUF protobuf-lite>=2.4)
find_package(Protobuf CONFIG)
if(NOT Protobuf_FOUND)
find_package(Protobuf REQUIRED)
endif()

if (${Protobuf_VERSION} VERSION_LESS "3.21.0.0")
if (USE_PROTOBUF_LITE)
set (PROTOBUF_LIB ${Protobuf_LITE_LIBRARIES})
else ()
set (PROTOBUF_LIB ${Protobuf_LIBRARIES})
endif ()
# find_required_program (PROTOC protoc "Google Protocol Buffers compiler (protoc)")
else ()
find_required_library (PROTOBUF google/protobuf/message_lite.h protobuf
"Google Protocol Buffers")
check_library_version (PC_PROTOBUF protobuf>=2.4)
if (USE_PROTOBUF_LITE)
set (PROTOBUF_LIB protobuf::libprotobuf-lite)
else ()
set (PROTOBUF_LIB protobuf::libprotobuf)
endif ()
endif ()

find_required_library (ICU_UC unicode/uchar.h icuuc "ICU")
Expand All @@ -192,9 +203,6 @@ if (USE_ICU_REGEXP OR BUILD_GEOCODER)
list (APPEND ICU_LIB ${ICU_I18N_LIB})
endif ()

find_required_program (PROTOC protoc
"Google Protocol Buffers compiler (protoc)")

if (REGENERATE_METADATA)
find_required_program (JAVA java
"Java Runtime Environment")
Expand All @@ -220,24 +228,36 @@ endif ()
set (RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../resources")

set (
PROTOBUF_SOURCES "${RESOURCES_DIR}/phonemetadata.proto"
"${RESOURCES_DIR}/phonenumber.proto"
PROTO_FILES "${RESOURCES_DIR}/phonemetadata.proto"
"${RESOURCES_DIR}/phonenumber.proto"
)

set (
PROTOBUF_OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/phonenumbers/phonemetadata.pb.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/phonenumbers/phonemetadata.pb.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/phonenumbers/phonenumber.pb.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/phonenumbers/phonenumber.pb.h"
)
if (${Protobuf_VERSION} VERSION_LESS "3.21.0.0")
set (
PROTOBUF_OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/phonenumbers/phonemetadata.pb.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/phonenumbers/phonemetadata.pb.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/phonenumbers/phonenumber.pb.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/phonenumbers/phonenumber.pb.h"
)

add_custom_command (
COMMAND ${PROTOC_BIN} --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/src/phonenumbers/
--proto_path=${RESOURCES_DIR} ${PROTOBUF_SOURCES}
# COMMAND ${PROTOC_BIN}
add_custom_command (
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
ARGS --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/src/phonenumbers/ --proto_path=${RESOURCES_DIR} ${PROTO_FILES}
VERBATIM

OUTPUT ${PROTOBUF_OUTPUT}
DEPENDS ${PROTOBUF_SOURCES}
)
OUTPUT ${PROTOBUF_OUTPUT}
DEPENDS ${PROTO_FILES}
)
else ()
set (PROTO_BINARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
protobuf_generate (
PROTOS ${PROTO_FILES}
OUT_VAR PROTOBUF_OUTPUT
IMPORT_DIRS "${RESOURCES_DIR}"
PROTOC_OUT_DIR "${PROTO_BINARY_DIR}/phonenumbers"
)
endif ()

if (BUILD_GEOCODER)
# Geocoding data cpp file generation
Expand Down Expand Up @@ -267,9 +287,7 @@ set (
"src/phonenumbers/base/strings/string_piece.cc"
"src/phonenumbers/default_logger.cc"
"src/phonenumbers/logger.cc"
"src/phonenumbers/phonemetadata.pb.cc" # Generated by Protocol Buffers.
"src/phonenumbers/phonenumber.cc"
"src/phonenumbers/phonenumber.pb.cc" # Generated by Protocol Buffers.
"src/phonenumbers/phonenumberutil.cc"
"src/phonenumbers/regex_based_matcher.cc"
"src/phonenumbers/regexp_cache.cc"
Expand All @@ -282,6 +300,8 @@ set (
"src/phonenumbers/utf/unilib.cc"
)

list (APPEND SOURCES ${PROTOBUF_OUTPUT})

if (BUILD_GEOCODER)
set (
GEOCODING_SOURCES
Expand All @@ -290,7 +310,6 @@ if (BUILD_GEOCODER)
"src/phonenumbers/geocoding/geocoding_data.cc"
"src/phonenumbers/geocoding/mapping_file_provider.cc"
"src/phonenumbers/geocoding/phonenumber_offline_geocoder.cc"
"src/phonenumbers/phonenumber.pb.h" # Forces proto buffer generation.
)
endif ()

Expand Down
4 changes: 2 additions & 2 deletions cpp/cmake/config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

include(CMakeFindDependencyMacro)

find_dependency(absl)
find_dependency(Protobuf)
find_dependency(absl CONFIG)
find_dependency(Protobuf CONFIG)

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")