@@ -16,7 +16,13 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1616# ============================================================================
1717# Options
1818
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)
2026
2127# ============================================================================
2228# Find Python
@@ -26,22 +32,53 @@ find_package(Python COMPONENTS Interpreter Development)
2632# ============================================================================
2733# Build dependencies
2834
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 ()
4351
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)
4582
4683# ============================================================================
4784# pybind11_proto_utils pybind11 extension module
@@ -60,7 +97,7 @@ target_include_directories(
6097# ============================================================================
6198# pybind11_native_proto_caster shared library
6299add_library (
63- pybind11_native_proto_caster SHARED
100+ pybind11_native_proto_caster STATIC
64101 # bazel: pybind_library: native_proto_caster
65102 pybind11_protobuf/native_proto_caster.h
66103 # bazel: pybind_library: enum_type_caster
@@ -89,7 +126,7 @@ target_include_directories(
89126# ============================================================================
90127# pybind11_wrapped_proto_caster shared library
91128add_library (
92- pybind11_wrapped_proto_caster SHARED
129+ pybind11_wrapped_proto_caster STATIC
93130 # bazel: pybind_library: wrapped_proto_caster
94131 pybind11_protobuf/wrapped_proto_caster.h
95132 # bazel: pybind_library: proto_cast_util
@@ -113,6 +150,10 @@ target_include_directories(
113150 PRIVATE ${PROJECT_SOURCE_DIR} ${protobuf_INCLUDE_DIRS} ${protobuf_SOURCE_DIR}
114151 ${pybind11_INCLUDE_DIRS} )
115152
153+ if (BUILD_TESTING)
154+ add_subdirectory (pybind11_protobuf/tests)
155+ endif ()
156+
116157# bazel equivs. checklist
117158#
118159# bazel: pybind_library: enum_type_caster - enum_type_caster.h
0 commit comments