Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions cmake/FindGRPC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#
# CMake Find gRPC by Parra Studios
# CMake script to find gRPC and Protobuf libraries.
#
# Copyright (C) 2016 - 2026 Vicente Eduardo Ferrer Garcia <vic798@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# The following variables are set:
#
# GRPC_FOUND - TRUE if gRPC and Protobuf were found.
# GRPC_INCLUDE_DIRS - Protobuf include directories (contains google/protobuf/struct.pb.h).
# GRPC_LIBRARIES - Libraries to link against (protobuf + grpc++).

# Prevent verbosity if already included
if(GRPC_FOUND)
set(GRPC_FIND_QUIETLY TRUE)
endif()

# Try CMake config first (works with Homebrew, vcpkg, system installs)
find_package(gRPC QUIET CONFIG)

if(gRPC_FOUND)
set(GRPC_FOUND TRUE)
set(GRPC_LIBRARIES gRPC::grpc++ protobuf::libprotobuf)

get_target_property(GRPC_INCLUDE_DIRS protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)

if(NOT GRPC_FIND_QUIETLY)
message(STATUS "Found gRPC via CMake config")
endif()

return()
endif()

# Fallback: pkg-config
find_package(PkgConfig QUIET)

if(PKG_CONFIG_FOUND)
pkg_check_modules(GRPC QUIET grpc++ protobuf)
endif()

# Fallback: manual search
if(NOT GRPC_FOUND)
find_path(GRPC_INCLUDE_DIRS
NAMES google/protobuf/struct.pb.h
PATHS
/usr/local/include
/usr/include
/opt/homebrew/include
DOC "Include directory for Protobuf (required by grpc_serial)"
)

find_library(GRPC_GRPCPP_LIBRARY
NAMES grpc++ grpc++_unsecure
PATHS /usr/local/lib /usr/lib /opt/homebrew/lib
)

find_library(GRPC_PROTOBUF_LIBRARY
NAMES protobuf
PATHS /usr/local/lib /usr/lib /opt/homebrew/lib
)

if(GRPC_INCLUDE_DIRS AND GRPC_GRPCPP_LIBRARY AND GRPC_PROTOBUF_LIBRARY)
set(GRPC_FOUND TRUE)
set(GRPC_LIBRARIES ${GRPC_GRPCPP_LIBRARY} ${GRPC_PROTOBUF_LIBRARY})
endif()
endif()

mark_as_advanced(GRPC_FOUND GRPC_INCLUDE_DIRS GRPC_LIBRARIES)

if(GRPC_FOUND)
if(NOT GRPC_FIND_QUIETLY)
message(STATUS "Found gRPC/Protobuf headers in ${GRPC_INCLUDE_DIRS}")
endif()
elseif(GRPC_FIND_REQUIRED)
message(FATAL_ERROR "Could not find gRPC/Protobuf")
endif()
67 changes: 67 additions & 0 deletions cmake/InstallGRPC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#
# CMake Install gRPC by Parra Studios
# CMake script to install gRPC and Protobuf via FetchContent.
#
# Copyright (C) 2016 - 2026 Vicente Eduardo Ferrer Garcia <vic798@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# The following variables are set:
#
# GRPC_FOUND - TRUE if gRPC was installed successfully.
# GRPC_INCLUDE_DIRS - Include directories for Protobuf headers.
# GRPC_LIBRARIES - Libraries to link against.

if(NOT GRPC_FOUND OR USE_BUNDLED_GRPC)
include(FetchContent)

# Pin to a specific release tag for reproducibility
if(NOT GRPC_VERSION OR USE_BUNDLED_GRPC)
set(GRPC_VERSION v1.60.0)
endif()

message(STATUS "Installing gRPC ${GRPC_VERSION} via FetchContent (this may take a while)")

# Disable building unnecessary gRPC components to keep build times reasonable
set(FETCHCONTENT_QUIET OFF)
set(gRPC_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(gRPC_BUILD_CODEGEN OFF CACHE BOOL "" FORCE)
set(gRPC_BUILD_GRPC_CPP_PLUGIN OFF CACHE BOOL "" FORCE)
set(gRPC_BUILD_GRPC_CSHARP_PLUGIN OFF CACHE BOOL "" FORCE)
set(gRPC_BUILD_GRPC_NODE_PLUGIN OFF CACHE BOOL "" FORCE)
set(gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN OFF CACHE BOOL "" FORCE)
set(gRPC_BUILD_GRPC_PHP_PLUGIN OFF CACHE BOOL "" FORCE)
set(gRPC_BUILD_GRPC_PYTHON_PLUGIN OFF CACHE BOOL "" FORCE)
set(gRPC_BUILD_GRPC_RUBY_PLUGIN OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(protobuf_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(ABSL_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)

FetchContent_Declare(gRPC
GIT_REPOSITORY https://github.com/grpc/grpc.git
GIT_TAG ${GRPC_VERSION}
GIT_SUBMODULES_RECURSE ON
)

FetchContent_MakeAvailable(gRPC)

set(GRPC_FOUND TRUE)
set(GRPC_LIBRARIES gRPC::grpc++ protobuf::libprotobuf)

get_target_property(GRPC_INCLUDE_DIRS protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)

mark_as_advanced(GRPC_INCLUDE_DIRS GRPC_LIBRARIES)

message(STATUS "Installed gRPC ${GRPC_VERSION}")
endif()
26 changes: 14 additions & 12 deletions source/serials/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Check if serials are enabled
if(NOT OPTION_BUILD_SERIALS)
return()
endif()

# Serial options
option(OPTION_BUILD_SERIALS_METACALL "MetaCall Native Format library serial." ON)
option(OPTION_BUILD_SERIALS_RAPID_JSON "RapidJSON library serial." ON)

# Serial packages
add_subdirectory(metacall_serial) # MetaCall Native Format library
add_subdirectory(rapid_json_serial) # RapidJSON library
# Check if serials are enabled
if(NOT OPTION_BUILD_SERIALS)
return()
endif()

# Serial options
option(OPTION_BUILD_SERIALS_METACALL "MetaCall Native Format library serial." ON)
option(OPTION_BUILD_SERIALS_RAPID_JSON "RapidJSON library serial." ON)
option(OPTION_BUILD_SERIALS_GRPC "gRPC library serial." ON)

# Serial packages
add_subdirectory(metacall_serial) # MetaCall Native Format library
add_subdirectory(rapid_json_serial) # RapidJSON library
add_subdirectory(grpc_serial) # gRPC and Protobuf library
131 changes: 131 additions & 0 deletions source/serials/grpc_serial/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Check if this serial is enabled
if(NOT OPTION_BUILD_SERIALS OR NOT OPTION_BUILD_SERIALS_GRPC)
return()
endif()

#
# External dependencies
#

find_package(GRPC)

if(NOT GRPC_FOUND)
include(InstallGRPC)

if(NOT GRPC_FOUND)
message(SEND_ERROR "gRPC libraries not found")
return()
endif()

set(GRPC_INSTALL TRUE)
endif()

#
# Library name and options
#

set(target grpc_serial)

message(STATUS "Serial ${target}")

string(TOUPPER ${target} target_upper)
set(export_file "include/${target}/${target}_api.h")
set(export_macro "${target_upper}_API")

include(Warnings)
include(SecurityFlags)

set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}")
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")

set(headers
${include_path}/grpc_serial.h
${include_path}/grpc_serial_impl.h
)

set(sources
${source_path}/grpc_serial.c
${source_path}/grpc_serial_impl.cpp
)

set(header_group "Header Files (API)")
set(source_group "Source Files")
source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$"
${header_group} ${headers})
source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$"
${source_group} ${sources})

add_library(${target} MODULE
${sources}
${headers}
)

add_library(${META_PROJECT_NAME}::${target} ALIAS ${target})

export(TARGETS ${target} NAMESPACE ${META_PROJECT_NAME}:: FILE ${PROJECT_BINARY_DIR}/cmake/${target}/${target}-export.cmake)

generate_export_header(${target}
EXPORT_FILE_NAME ${export_file}
EXPORT_MACRO_NAME ${export_macro}
)

set_target_properties(${target}
PROPERTIES
${DEFAULT_PROJECT_OPTIONS}
FOLDER "${IDE_FOLDER}"
BUNDLE $<AND:$<PLATFORM_ID:Darwin>,$<VERSION_GREATER:${PROJECT_OS_VERSION},8>>
)

target_include_directories(${target}
PRIVATE
${PROJECT_BINARY_DIR}/source/include
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include
$<TARGET_PROPERTY:${META_PROJECT_NAME}::metacall,INCLUDE_DIRECTORIES>
${GRPC_INCLUDE_DIRS}
PUBLIC
${DEFAULT_INCLUDE_DIRECTORIES}
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(${target}
PRIVATE
$<$<NOT:$<PLATFORM_ID:Darwin>>:${META_PROJECT_NAME}::metacall>
${GRPC_LIBRARIES}
PUBLIC
${DEFAULT_LIBRARIES}
INTERFACE
)

target_compile_definitions(${target}
PRIVATE
PUBLIC
$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:${target_upper}_STATIC_DEFINE>
${DEFAULT_COMPILE_DEFINITIONS}
INTERFACE
)

target_compile_options(${target}
PRIVATE
PUBLIC
${DEFAULT_COMPILE_OPTIONS}
INTERFACE
)

target_link_options(${target}
PRIVATE
$<$<AND:$<PLATFORM_ID:Darwin>,$<CXX_COMPILER_ID:AppleClang,Clang>>:-Wl,-undefined,dynamic_lookup>
PUBLIC
${DEFAULT_LINKER_OPTIONS}
INTERFACE
)

install(TARGETS ${target}
EXPORT "${target}-export" COMPONENT dev
RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT runtime
LIBRARY DESTINATION ${INSTALL_SHARED} COMPONENT runtime
ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT dev
)
60 changes: 60 additions & 0 deletions source/serials/grpc_serial/include/grpc_serial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Serial Library by Parra Studios
* A cross-platform library for managing multiple serialization and deserialization formats.
*
* Copyright (C) 2016 - 2026 Vicente Eduardo Ferrer Garcia <vic798@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef GRPC_SERIAL_H
#define GRPC_SERIAL_H 1

/* -- Headers -- */

#include <grpc_serial/grpc_serial_api.h>

#include <serial/serial_interface.h>

#ifdef __cplusplus
extern "C" {
#endif

/* -- Methods -- */

/**
* @brief
* Instance of interface implementation
*
* @return
* Returns pointer to interface to be used by implementation
*
*/
GRPC_SERIAL_API serial_interface grpc_serial_impl_interface_singleton(void);

/**
* @brief
* Provide the module information
*
* @return
* Static string containing module information
*
*/
GRPC_SERIAL_API const char *grpc_serial_print_info(void);

#ifdef __cplusplus
}
#endif

#endif /* GRPC_SERIAL_H */
Loading
Loading