Skip to content

Commit

Permalink
Add ENABLE_PYPROTO_API option to CMake build, clean up compilation
Browse files Browse the repository at this point in the history
The PYBIND11_PROTOBUF_ENABLE_PYPROTO_API define was never set in
CMake builds, add a corresponding option.

As the check_unknown_fields code is only called dependent on the
define remove it from the build if not used.
  • Loading branch information
StefanBruens committed Jun 13, 2024
1 parent 4cdd828 commit 72eaae5
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Options

option(BUILD_TESTS "Build tests." OFF)
option(ENABLE_PYPROTO_API "Enable usage of proto_api." OFF)

# ============================================================================
# Find Python
Expand Down Expand Up @@ -69,9 +70,20 @@ add_library(
pybind11_protobuf/proto_cast_util.cc
pybind11_protobuf/proto_cast_util.h
pybind11_protobuf/proto_caster_impl.h
# bazel: cc_library::check_unknown_fields
pybind11_protobuf/check_unknown_fields.cc
pybind11_protobuf/check_unknown_fields.h)
)

if(ENABLE_PYPROTO_API)
target_sources(
pybind11_native_proto_caster
PRIVATE
# bazel: cc_library::check_unknown_fields
pybind11_protobuf/check_unknown_fields.cc
pybind11_protobuf/check_unknown_fields.h
)
target_compile_definitions(pybind11_native_proto_caster
PRIVATE PYBIND11_PROTOBUF_ENABLE_PYPROTO_API
)
endif()

target_link_libraries(
pybind11_native_proto_caster
Expand Down Expand Up @@ -99,9 +111,20 @@ add_library(
pybind11_protobuf/proto_cast_util.cc
pybind11_protobuf/proto_cast_util.h
pybind11_protobuf/proto_caster_impl.h
# bazel: cc_library: check_unknown_fields
pybind11_protobuf/check_unknown_fields.cc
pybind11_protobuf/check_unknown_fields.h)
)

if(ENABLE_PYPROTO_API)
target_sources(
pybind11_wrapped_proto_caster
PRIVATE
# bazel: cc_library::check_unknown_fields
pybind11_protobuf/check_unknown_fields.cc
pybind11_protobuf/check_unknown_fields.h
)
target_compile_definitions(pybind11_wrapped_proto_caster
PRIVATE PYBIND11_PROTOBUF_ENABLE_PYPROTO_API
)
endif()

target_link_libraries(
pybind11_wrapped_proto_caster
Expand All @@ -119,9 +142,6 @@ target_include_directories(
PRIVATE ${PROJECT_SOURCE_DIR} ${protobuf_INCLUDE_DIRS} ${protobuf_SOURCE_DIR}
${pybind11_INCLUDE_DIRS})

# TODO set defines PYBIND11_PROTOBUF_ENABLE_PYPROTO_API see: bazel:
# pybind_library: proto_cast_util

# bazel equivs. checklist
#
# bazel: pybind_library: enum_type_caster - enum_type_caster.h
Expand Down

0 comments on commit 72eaae5

Please sign in to comment.