@@ -16,7 +16,13 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
16
16
# ============================================================================
17
17
# Options
18
18
19
- option (BUILD_TESTS "Build tests." OFF )
19
+ option (USE_SYSTEM_ABSEIL "Force usage of system provided abseil-cpp" OFF )
20
+ option (USE_SYSTEM_PROTOBUF "Force usage of system provided Protobuf" OFF )
21
+ option (USE_SYSTEM_PYBIND "Force usage of system provided pybind11" OFF )
22
+
23
+ # ============================================================================
24
+ # Testing
25
+ include (CTest )
20
26
21
27
# ============================================================================
22
28
# Find Python
@@ -26,22 +32,53 @@ find_package(Python COMPONENTS Interpreter Development)
26
32
# ============================================================================
27
33
# Build dependencies
28
34
29
- set (_absl_repository "https://github.com/abseil/abseil-cpp.git" )
30
- set (_absl_version 20230125 )
31
- set (_absl_tag 20230125.3 )
32
- find_package (absl ${_absl_version} QUIET )
33
-
34
- set (_protobuf_repository "https://github.com/protocolbuffers/protobuf.git" )
35
- set (_protobuf_version 3.23.3 )
36
- set (_protobuf_tag v23.3 )
37
- find_package (Protobuf ${_protobuf_version} QUIET )
38
-
39
- set (_pybind11_repository "https://github.com/pybind/pybind11.git" )
40
- set (_pybind11_version 2.11.1 )
41
- set (_pybind11_tag v2.11.1 )
42
- find_package (pybind11 ${_pybind11_version} QUIET )
35
+ if (USE_SYSTEM_ABSEIL )
36
+ # Version omitted, as absl only allows EXACT version matches
37
+ set (_absl_package_args REQUIRED )
38
+ else ()
39
+ set (_absl_package_args 20230125 )
40
+ endif ()
41
+ if (USE_SYSTEM_PROTOBUF )
42
+ set (_protobuf_package_args 4.23.3 REQUIRED )
43
+ else ()
44
+ set (_protobuf_package_args 4.23.3 )
45
+ endif ()
46
+ if (USE_SYSTEM_PYBIND )
47
+ set (_pybind11_package_args 2.11.1 REQUIRED )
48
+ else ()
49
+ set (_pybind11_package_args 2.11.1 )
50
+ endif ()
43
51
44
- add_subdirectory (cmake/dependencies dependencies )
52
+ set (ABSL_PROPAGATE_CXX_STD ON )
53
+ set (ABSL_ENABLE_INSTALL ON )
54
+
55
+ include (FetchContent )
56
+ FetchContent_Declare (
57
+ absl
58
+ GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git"
59
+ GIT_TAG 20230125.3
60
+ FIND_PACKAGE_ARGS ${_absl_package_args} NAMES absl )
61
+
62
+ # cmake-format: off
63
+ FetchContent_Declare (
64
+ Protobuf
65
+ GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git"
66
+ GIT_TAG v23.3
67
+ GIT_SUBMODULES ""
68
+ FIND_PACKAGE_ARGS ${_protobuf_package_args} NAMES protobuf )
69
+ set (protobuf_BUILD_TESTS OFF CACHE INTERNAL "" )
70
+ # cmake-format: on
71
+
72
+ FetchContent_Declare (
73
+ pybind11
74
+ GIT_REPOSITORY "https://github.com/pybind/pybind11.git"
75
+ GIT_TAG v2.11.1
76
+ FIND_PACKAGE_ARGS ${_pybind11_package_args} NAMES pybind11 )
77
+
78
+ message (CHECK_START "Checking for external dependencies" )
79
+ list (APPEND CMAKE_MESSAGE_INDENT " " )
80
+ FetchContent_MakeAvailable (absl Protobuf pybind11 )
81
+ list (POP_BACK CMAKE_MESSAGE_INDENT )
45
82
46
83
# ============================================================================
47
84
# pybind11_proto_utils pybind11 extension module
@@ -60,7 +97,7 @@ target_include_directories(
60
97
# ============================================================================
61
98
# pybind11_native_proto_caster shared library
62
99
add_library (
63
- pybind11_native_proto_caster SHARED
100
+ pybind11_native_proto_caster STATIC
64
101
# bazel: pybind_library: native_proto_caster
65
102
pybind11_protobuf/native_proto_caster.h
66
103
# bazel: pybind_library: enum_type_caster
@@ -89,7 +126,7 @@ target_include_directories(
89
126
# ============================================================================
90
127
# pybind11_wrapped_proto_caster shared library
91
128
add_library (
92
- pybind11_wrapped_proto_caster SHARED
129
+ pybind11_wrapped_proto_caster STATIC
93
130
# bazel: pybind_library: wrapped_proto_caster
94
131
pybind11_protobuf/wrapped_proto_caster.h
95
132
# bazel: pybind_library: proto_cast_util
@@ -113,6 +150,10 @@ target_include_directories(
113
150
PRIVATE ${PROJECT_SOURCE_DIR} ${protobuf_INCLUDE_DIRS} ${protobuf_SOURCE_DIR}
114
151
${pybind11_INCLUDE_DIRS} )
115
152
153
+ if (BUILD_TESTING )
154
+ add_subdirectory (pybind11_protobuf/tests )
155
+ endif ()
156
+
116
157
# bazel equivs. checklist
117
158
#
118
159
# bazel: pybind_library: enum_type_caster - enum_type_caster.h
0 commit comments