|
| 1 | +cmake_minimum_required(VERSION 3.18) |
| 2 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 3 | + |
| 4 | +project(pybind11_protobuf) |
| 5 | + |
| 6 | +if(MSVC) |
| 7 | + set(CMAKE_CXX_STANDARD 20) |
| 8 | +else() |
| 9 | + set(CMAKE_CXX_STANDARD 17) |
| 10 | +endif() |
| 11 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 12 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 13 | + |
| 14 | +set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 15 | + |
| 16 | +# ============================================================================ |
| 17 | +# Options |
| 18 | + |
| 19 | +option(BUILD_TESTS "Build tests." OFF) |
| 20 | + |
| 21 | +# ============================================================================ |
| 22 | +# Find Python |
| 23 | + |
| 24 | +find_package(Python COMPONENTS Interpreter Development) |
| 25 | + |
| 26 | +# ============================================================================ |
| 27 | +# Build dependencies |
| 28 | + |
| 29 | +set(_absl_repository "https://github.com/abseil/abseil-cpp.git") |
| 30 | +set(_absl_version 20220623.1) |
| 31 | +set(_absl_tag 20220623.1) |
| 32 | + |
| 33 | +set(_protobuf_repository "https://github.com/protocolbuffers/protobuf.git") |
| 34 | +set(_protobuf_version 21.5) |
| 35 | +set(_protobuf_tag v21.5) |
| 36 | + |
| 37 | +set(_pybind11_repository "https://github.com/pybind/pybind11.git") |
| 38 | +set(_pybind11_version 2.10) |
| 39 | +set(_pybind11_tag v2.10.1) |
| 40 | + |
| 41 | +add_subdirectory(cmake/dependencies dependencies) |
| 42 | + |
| 43 | +# ============================================================================ |
| 44 | +# pybind11_proto_utils pybind11 extension module |
| 45 | +pybind11_add_module( |
| 46 | + pybind11_proto_utils MODULE pybind11_protobuf/proto_utils.cc |
| 47 | + pybind11_protobuf/proto_utils.h) |
| 48 | + |
| 49 | +target_link_libraries( |
| 50 | + pybind11_proto_utils PRIVATE absl::strings protobuf::libprotobuf |
| 51 | + ${Python_LIBRARIES}) |
| 52 | + |
| 53 | +target_include_directories( |
| 54 | + pybind11_proto_utils PRIVATE ${PROJECT_SOURCE_DIR} ${protobuf_INCLUDE_DIRS} |
| 55 | + ${protobuf_SOURCE_DIR} ${pybind11_INCLUDE_DIRS}) |
| 56 | + |
| 57 | +# ============================================================================ |
| 58 | +# pybind11_native_proto_caster shared library |
| 59 | +add_library( |
| 60 | + pybind11_native_proto_caster SHARED |
| 61 | + # bazel: pybind_library: native_proto_caster |
| 62 | + pybind11_protobuf/native_proto_caster.h |
| 63 | + # bazel: pybind_library: enum_type_caster |
| 64 | + pybind11_protobuf/enum_type_caster.h |
| 65 | + # bazel: pybind_library: proto_cast_util |
| 66 | + pybind11_protobuf/proto_cast_util.cc |
| 67 | + pybind11_protobuf/proto_cast_util.h |
| 68 | + pybind11_protobuf/proto_caster_impl.h |
| 69 | + # bazel: cc_library::check_unknown_fields |
| 70 | + pybind11_protobuf/check_unknown_fields.cc |
| 71 | + pybind11_protobuf/check_unknown_fields.h) |
| 72 | + |
| 73 | +target_link_libraries( |
| 74 | + pybind11_native_proto_caster |
| 75 | + absl::flat_hash_map |
| 76 | + absl::flat_hash_set |
| 77 | + absl::hash |
| 78 | + absl::strings |
| 79 | + absl::optional |
| 80 | + protobuf::libprotobuf |
| 81 | + pybind11::pybind11 |
| 82 | + ${Python_LIBRARIES}) |
| 83 | + |
| 84 | +target_include_directories( |
| 85 | + pybind11_native_proto_caster |
| 86 | + PRIVATE ${PROJECT_SOURCE_DIR} ${protobuf_INCLUDE_DIRS} ${protobuf_SOURCE_DIR} |
| 87 | + ${pybind11_INCLUDE_DIRS}) |
| 88 | + |
| 89 | +# ============================================================================ |
| 90 | +# pybind11_wrapped_proto_caster shared library |
| 91 | +add_library( |
| 92 | + pybind11_wrapped_proto_caster SHARED |
| 93 | + # bazel: pybind_library: wrapped_proto_caster |
| 94 | + pybind11_protobuf/wrapped_proto_caster.h |
| 95 | + # bazel: pybind_library: proto_cast_util |
| 96 | + pybind11_protobuf/proto_cast_util.cc |
| 97 | + pybind11_protobuf/proto_cast_util.h |
| 98 | + pybind11_protobuf/proto_caster_impl.h |
| 99 | + # bazel: cc_library: check_unknown_fields |
| 100 | + pybind11_protobuf/check_unknown_fields.cc |
| 101 | + pybind11_protobuf/check_unknown_fields.h) |
| 102 | + |
| 103 | +target_link_libraries( |
| 104 | + pybind11_wrapped_proto_caster |
| 105 | + absl::flat_hash_map |
| 106 | + absl::flat_hash_set |
| 107 | + absl::hash |
| 108 | + absl::strings |
| 109 | + absl::optional |
| 110 | + protobuf::libprotobuf |
| 111 | + pybind11::pybind11 |
| 112 | + ${Python_LIBRARIES}) |
| 113 | + |
| 114 | +target_include_directories( |
| 115 | + pybind11_wrapped_proto_caster |
| 116 | + PRIVATE ${PROJECT_SOURCE_DIR} ${protobuf_INCLUDE_DIRS} ${protobuf_SOURCE_DIR} |
| 117 | + ${pybind11_INCLUDE_DIRS}) |
| 118 | + |
| 119 | +# TODO set defines PYBIND11_PROTOBUF_ENABLE_PYPROTO_API see: bazel: |
| 120 | +# pybind_library: proto_cast_util |
| 121 | + |
| 122 | +# bazel equivs. checklist |
| 123 | +# |
| 124 | +# bazel: pybind_library: enum_type_caster - enum_type_caster.h |
| 125 | +# |
| 126 | +# bazel: pybind_library: native_proto_caster - native_proto_caster.h |
| 127 | +# |
| 128 | +# check_unknown_fields enum_type_caster proto_cast_util |
| 129 | +# |
| 130 | +# bazel: pybind_library: proto_cast_util - proto_cast_util.cc - |
| 131 | +# proto_cast_util.h - proto_caster_impl.h |
| 132 | +# |
| 133 | +# check_unknown_fields |
| 134 | +# |
| 135 | +# bazel: pybind_library: wrapped_proto_caster - wrapped_proto_caster.h |
| 136 | +# |
| 137 | +# proto_cast_util |
| 138 | +# |
0 commit comments