|
| 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 | +#============================================================================ |
| 15 | +# Options |
| 16 | + |
| 17 | +option(BUILD_absl "Build the abseil-cpp dependency Library" ON) |
| 18 | +message(STATUS "Build abseil-cpp: ${BUILD_absl}") |
| 19 | + |
| 20 | +option(BUILD_protobuf "Build the Protobuf dependency Library" ON) |
| 21 | +message(STATUS "Build protobuf: ${BUILD_protobuf}") |
| 22 | + |
| 23 | +option(BUILD_pybind11 "Build the pybind11 dependency Library" ON) |
| 24 | +message(STATUS "Python: Build pybind11: ${BUILD_pybind11}") |
| 25 | + |
| 26 | +#============================================================================ |
| 27 | +# Find Python |
| 28 | + |
| 29 | +find_package(Python COMPONENTS Interpreter Development) |
| 30 | + |
| 31 | +#============================================================================ |
| 32 | +# Build dependencies |
| 33 | + |
| 34 | +add_subdirectory(cmake/dependencies dependencies) |
| 35 | + |
| 36 | +include(deps) |
| 37 | + |
| 38 | +include(CMakeFindDependencyMacro) |
| 39 | +include(FindProtobuf) |
| 40 | +if (NOT protobuf_FOUND AND NOT PROTOBUF_FOUND AND NOT TARGET protobuf::libprotobuf) |
| 41 | + if (BUILD_protobuf) |
| 42 | + find_dependency(protobuf CONFIG REQUIRED) |
| 43 | + endif() |
| 44 | +endif() |
| 45 | + |
| 46 | +#============================================================================ |
| 47 | +# Debug messages for find_package |
| 48 | + |
| 49 | +# message("pybind11_FOUND: ${pybind11_FOUND}") |
| 50 | +# message("pybind11_VERSION: ${pybind11_VERSION}") |
| 51 | +# message("pybind11_VERSION_TYPE: ${pybind11_VERSION_TYPE}") |
| 52 | +# message("pybind11_INCLUDE_DIRS: ${pybind11_INCLUDE_DIRS}") |
| 53 | +# message("pybind11_INCLUDE_DIR: ${pybind11_INCLUDE_DIR}") |
| 54 | +# message("pybind11_DEFINITIONS: ${pybind11_DEFINITIONS}") |
| 55 | +# message("pybind11_LIBRARIES: ${pybind11_LIBRARIES}") |
| 56 | + |
| 57 | +# message("Python_FOUND: ${Python_FOUND}") |
| 58 | +# message("Python_VERSION: ${Python_VERSION}") |
| 59 | +# message("Python_INCLUDE_DIRS: ${Python_INCLUDE_DIRS}") |
| 60 | +# message("Python_LIBRARIES: ${Python_LIBRARIES}") |
| 61 | + |
| 62 | +# message("protobuf_FOUND: ${protobuf_FOUND}") |
| 63 | +# message("protobuf_VERSION: ${protobuf_VERSION}") |
| 64 | +# message("protobuf_INCLUDE_DIRS: ${protobuf_INCLUDE_DIRS}") |
| 65 | +# message("protobuf_SOURCE_DIR: ${protobuf_SOURCE_DIR}") |
| 66 | +# message("protobuf_LIBRARIES: ${protobuf_LIBRARIES}") |
| 67 | + |
| 68 | +#============================================================================ |
| 69 | +# pybind11_proto_utils pybind11 extension module |
| 70 | +pybind11_add_module(pybind11_proto_utils MODULE |
| 71 | + pybind11_protobuf/proto_utils.cc |
| 72 | + pybind11_protobuf/proto_utils.h |
| 73 | +) |
| 74 | + |
| 75 | +target_link_libraries(pybind11_proto_utils |
| 76 | + PRIVATE |
| 77 | + absl::strings |
| 78 | + protobuf::libprotobuf |
| 79 | + ${Python_LIBRARIES} |
| 80 | +) |
| 81 | + |
| 82 | +target_include_directories(pybind11_proto_utils |
| 83 | + PRIVATE |
| 84 | + ${PROJECT_SOURCE_DIR} |
| 85 | + ${protobuf_INCLUDE_DIRS} |
| 86 | + ${protobuf_SOURCE_DIR} |
| 87 | + ${pybind11_INCLUDE_DIRS} |
| 88 | +) |
| 89 | + |
| 90 | +#============================================================================ |
| 91 | +# pybind11_native_proto_caster shared library |
| 92 | +add_library(pybind11_native_proto_caster SHARED |
| 93 | + # bazel: pybind_library: native_proto_caster |
| 94 | + pybind11_protobuf/native_proto_caster.h |
| 95 | + |
| 96 | + # bazel: pybind_library: enum_type_caster |
| 97 | + pybind11_protobuf/enum_type_caster.h |
| 98 | + |
| 99 | + # bazel: pybind_library: proto_cast_util |
| 100 | + pybind11_protobuf/proto_cast_util.cc |
| 101 | + pybind11_protobuf/proto_cast_util.h |
| 102 | + pybind11_protobuf/proto_caster_impl.h |
| 103 | + |
| 104 | + # bazel: cc_library::check_unknown_fields |
| 105 | + pybind11_protobuf/check_unknown_fields.cc |
| 106 | + pybind11_protobuf/check_unknown_fields.h |
| 107 | +) |
| 108 | + |
| 109 | +target_link_libraries(pybind11_native_proto_caster |
| 110 | + absl::flat_hash_map |
| 111 | + absl::flat_hash_set |
| 112 | + absl::hash |
| 113 | + absl::strings |
| 114 | + absl::optional |
| 115 | + protobuf::libprotobuf |
| 116 | + pybind11::pybind11 |
| 117 | + ${Python_LIBRARIES} |
| 118 | +) |
| 119 | + |
| 120 | +target_include_directories(pybind11_native_proto_caster |
| 121 | + PRIVATE |
| 122 | + ${PROJECT_SOURCE_DIR} |
| 123 | + ${protobuf_INCLUDE_DIRS} |
| 124 | + ${protobuf_SOURCE_DIR} |
| 125 | + ${pybind11_INCLUDE_DIRS} |
| 126 | +) |
| 127 | + |
| 128 | +#============================================================================ |
| 129 | +# pybind11_wrapped_proto_caster shared library |
| 130 | +add_library(pybind11_wrapped_proto_caster SHARED |
| 131 | + # bazel: pybind_library: wrapped_proto_caster |
| 132 | + pybind11_protobuf/wrapped_proto_caster.h |
| 133 | + |
| 134 | + # bazel: pybind_library: proto_cast_util |
| 135 | + pybind11_protobuf/proto_cast_util.cc |
| 136 | + pybind11_protobuf/proto_cast_util.h |
| 137 | + pybind11_protobuf/proto_caster_impl.h |
| 138 | + |
| 139 | + # bazel: cc_library: check_unknown_fields |
| 140 | + pybind11_protobuf/check_unknown_fields.cc |
| 141 | + pybind11_protobuf/check_unknown_fields.h |
| 142 | +) |
| 143 | + |
| 144 | +target_link_libraries(pybind11_wrapped_proto_caster |
| 145 | + absl::flat_hash_map |
| 146 | + absl::flat_hash_set |
| 147 | + absl::hash |
| 148 | + absl::strings |
| 149 | + absl::optional |
| 150 | + protobuf::libprotobuf |
| 151 | + pybind11::pybind11 |
| 152 | + ${Python_LIBRARIES} |
| 153 | +) |
| 154 | + |
| 155 | +target_include_directories(pybind11_wrapped_proto_caster |
| 156 | + PRIVATE |
| 157 | + ${PROJECT_SOURCE_DIR} |
| 158 | + ${protobuf_INCLUDE_DIRS} |
| 159 | + ${protobuf_SOURCE_DIR} |
| 160 | + ${pybind11_INCLUDE_DIRS} |
| 161 | +) |
| 162 | + |
| 163 | +# TODO set defines |
| 164 | +# PYBIND11_PROTOBUF_ENABLE_PYPROTO_API |
| 165 | +# see: bazel: pybind_library: proto_cast_util |
| 166 | + |
| 167 | +# bazel equivs. checklist |
| 168 | +# |
| 169 | +# bazel: pybind_library: enum_type_caster |
| 170 | +# - enum_type_caster.h |
| 171 | +# |
| 172 | +# bazel: pybind_library: native_proto_caster |
| 173 | +# - native_proto_caster.h |
| 174 | +# |
| 175 | +# check_unknown_fields |
| 176 | +# enum_type_caster |
| 177 | +# proto_cast_util |
| 178 | +# |
| 179 | +# bazel: pybind_library: proto_cast_util |
| 180 | +# - proto_cast_util.cc |
| 181 | +# - proto_cast_util.h |
| 182 | +# - proto_caster_impl.h |
| 183 | +# |
| 184 | +# check_unknown_fields |
| 185 | +# |
| 186 | +# bazel: pybind_library: wrapped_proto_caster |
| 187 | +# - wrapped_proto_caster.h |
| 188 | +# |
| 189 | +# proto_cast_util |
| 190 | +# |
0 commit comments