From 42c83bd2340ce49154fb97190056e9ce2ba28584 Mon Sep 17 00:00:00 2001 From: Kevin Lannen Date: Mon, 22 May 2023 14:35:32 -0600 Subject: [PATCH 1/2] Create a conan recipe to generate and build the protobuf code --- CMakeLists.txt | 23 +++++++++++++++++++++++ conanfile.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 conanfile.py diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..400f329 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.15) +project(Foxglove-Schemas CXX) + +find_package(Protobuf 3 REQUIRED) + +FILE(GLOB all_protos "schemas/proto/foxglove/*.proto") + +FOREACH(f ${all_protos}) + file(RELATIVE_PATH f ${CMAKE_CURRENT_SOURCE_DIR}/schemas/proto ${f}) + STRING(REGEX REPLACE "\\.proto$" "" f ${f}) + LIST(APPEND proto_sources "autogenerated/${f}.pb.h") + LIST(APPEND proto_sources "autogenerated/${f}.pb.cc") +ENDFOREACH(f) + +add_custom_command( + OUTPUT ${proto_sources} + COMMAND ${CMAKE_COMMAND} -E make_directory autogenerated + COMMAND ${Protobuf_PROTOC_EXECUTABLE} --proto_path=${CMAKE_CURRENT_SOURCE_DIR}/schemas/proto --cpp_out=autogenerated ${all_protos} +) + +add_library(foxglove-schemas ${proto_sources}) +target_include_directories(foxglove-schemas PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/autogenerated) +target_link_libraries(foxglove-schemas protobuf::libprotobuf) \ No newline at end of file diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..df912e4 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,34 @@ +import os + +from conans import ConanFile, tools, CMake + + +class FoxgloveSchemasConan(ConanFile): + name = "foxglove-schemas" + version = "1.0.0" + license = "" + author = " " + url = "" + description = "" + topics = ("", "", "") + settings = "os", "compiler", "build_type", "arch" + options = {"shared": [True, False]} + default_options = {"shared": False} + exports_sources = "*" + generators = "cmake_find_package" + + def requirements(self): + self.requires("protobuf/3.17.1") + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + self.copy("*.proto", src="schemas/proto", dst="include/foxglove", keep_path=False) + self.copy("*.pb.h", src="autogenerated", dst="include/foxglove", keep_path=False) + self.copy("*.a", dst="lib", keep_path=False) + + def package_info(self): + self.cpp_info.libs = ["foxglove-schemas"] From 0a2710e92e2288606ee73c0f82742b414fb3f2a1 Mon Sep 17 00:00:00 2001 From: Kevin Lannen Date: Mon, 22 May 2023 15:45:08 -0600 Subject: [PATCH 2/2] Create installation target in cmake --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 400f329..c5ba3e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,4 +20,6 @@ add_custom_command( add_library(foxglove-schemas ${proto_sources}) target_include_directories(foxglove-schemas PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/autogenerated) -target_link_libraries(foxglove-schemas protobuf::libprotobuf) \ No newline at end of file +target_link_libraries(foxglove-schemas protobuf::libprotobuf) + +install(TARGETS foxglove-schemas DESTINATION lib) \ No newline at end of file