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
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ option(TRITON_COMMON_ENABLE_JSON "Build json-related libs" ON)

if(TRITON_COMMON_ENABLE_JSON)
find_package(RapidJSON CONFIG REQUIRED)
# Conan-generated config uses a target (rapidjson) rather than the
# RAPIDJSON_INCLUDE_DIRS variable. Populate the variable if empty.
if(NOT RAPIDJSON_INCLUDE_DIRS)
foreach(_rj_target rapidjson RapidJSON::RapidJSON)
if(TARGET ${_rj_target})
get_target_property(RAPIDJSON_INCLUDE_DIRS ${_rj_target} INTERFACE_INCLUDE_DIRECTORIES)
break()
endif()
endforeach()
endif()
message(STATUS "RapidJSON found. Headers: ${RAPIDJSON_INCLUDE_DIRS}")
endif()

Expand Down
4 changes: 4 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": 6,
"include": ["cmake/CMakePresets.json"]
}
53 changes: 53 additions & 0 deletions cmake/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"version": 6,
"cmakeMinimumRequired": { "major": 3, "minor": 31, "patch": 8 },
"$comment": "Standalone build presets for triton-common. For integrated server builds use server/cmake/CMakePresets.json — it includes common via add_subdirectory and its variables take precedence.",
"configurePresets": [
{
"name": "conan-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"toolchainFile": "${sourceDir}/build/${presetName}/conan/conan_toolchain.cmake",
"cacheVariables": { "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" }
},
{
"name": "release",
"inherits": "conan-base",
"displayName": "Release (gRPC + Metrics)",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"TRITON_COMMON_ENABLE_GRPC": "ON",
"TRITON_COMMON_ENABLE_PROTOBUF": "ON",
"TRITON_COMMON_ENABLE_JSON": "ON"
}
},
{
"name": "debug",
"inherits": "conan-base",
"displayName": "Debug (gRPC + Metrics)",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"TRITON_COMMON_ENABLE_GRPC": "ON",
"TRITON_COMMON_ENABLE_PROTOBUF": "ON",
"TRITON_COMMON_ENABLE_JSON": "ON"
}
},
{
"name": "json-only",
"inherits": "conan-base",
"displayName": "Release JSON-only (no gRPC)",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"TRITON_COMMON_ENABLE_GRPC": "OFF",
"TRITON_COMMON_ENABLE_PROTOBUF": "OFF",
"TRITON_COMMON_ENABLE_JSON": "ON"
}
}
],
"buildPresets": [
{ "name": "release", "configurePreset": "release" },
{ "name": "debug", "configurePreset": "debug" },
{ "name": "json-only", "configurePreset": "json-only" }
]
}
49 changes: 49 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, cmake_layout
from conan.errors import ConanInvalidConfiguration


class TritonCommonConan(ConanFile):
name = "triton-common"
version = "2.68.0"
settings = "os", "compiler", "build_type", "arch"
options = {
"enable_grpc": [True, False],
"enable_metrics": [True, False],
}
default_options = {
"enable_grpc": True,
"enable_metrics": True,
}

def validate(self):
if self.settings.os != "Linux":
raise ConanInvalidConfiguration("triton-common only supports Linux")

def requirements(self):
self.requires("rapidjson/cci.20230929")
self.requires("protobuf/3.21.12")
if self.options.enable_grpc:
self.requires("grpc/1.54.3")
if self.options.enable_metrics:
self.requires("prometheus-cpp/1.2.4")

def configure(self):
if self.options.enable_grpc:
self.options["grpc"].shared = False
self.options["grpc"].cpp_plugin = True
if self.options.enable_metrics:
self.options["prometheus-cpp"].shared = False
self.options["prometheus-cpp"].with_pull = False
self.options["prometheus-cpp"].with_push = False

def layout(self):
cmake_layout(self)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["TRITON_COMMON_ENABLE_GRPC"] = self.options.enable_grpc
tc.variables["TRITON_COMMON_ENABLE_PROTOBUF"] = True
tc.variables["TRITON_COMMON_ENABLE_JSON"] = True
tc.generate()
CMakeDeps(self).generate()
13 changes: 13 additions & 0 deletions profiles/linux-gcc13-debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.version=13
compiler.libcxx=libstdc++11
compiler.cppstd=17
build_type=Debug

[buildenv]
CC=/usr/bin/gcc-13
CXX=/usr/bin/g++-13
PATH=+/home/user/.venv/bin
13 changes: 13 additions & 0 deletions profiles/linux-gcc13-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.version=13
compiler.libcxx=libstdc++11
compiler.cppstd=17
build_type=Release

[buildenv]
CC=/usr/bin/gcc-13
CXX=/usr/bin/g++-13
PATH=+/home/user/.venv/bin
18 changes: 17 additions & 1 deletion protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ cmake_minimum_required (VERSION 3.31.8)
set(protobuf_MODULE_COMPATIBLE TRUE CACHE BOOL "protobuf_MODULE_COMPATIBLE" FORCE)
find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")
include_directories(${Protobuf_INCLUDE_DIRS})
# Prefer target-based includes; fall back to variable for non-Conan builds.
if(TARGET protobuf::libprotobuf)
get_target_property(_proto_incs protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
if(_proto_incs)
include_directories(${_proto_incs})
endif()
elseif(Protobuf_INCLUDE_DIRS)
include_directories(${Protobuf_INCLUDE_DIRS})
endif()

if(${TRITON_COMMON_ENABLE_GRPC})
find_package(gRPC CONFIG REQUIRED)
Expand Down Expand Up @@ -65,6 +73,8 @@ if(${TRITON_COMMON_ENABLE_PROTOBUF})

target_link_libraries(
proto-library
PUBLIC
protobuf::libprotobuf
PRIVATE
common-compile-settings
)
Expand Down Expand Up @@ -137,6 +147,9 @@ if(${TRITON_COMMON_ENABLE_GRPC})

target_link_libraries(
grpc-service-library
PUBLIC
protobuf::libprotobuf
gRPC::grpc++
PRIVATE
common-compile-settings
)
Expand Down Expand Up @@ -193,6 +206,9 @@ if(${TRITON_COMMON_ENABLE_GRPC})

target_link_libraries(
grpc-health-library
PUBLIC
protobuf::libprotobuf
gRPC::grpc++
PRIVATE
common-compile-settings
)
Expand Down
14 changes: 9 additions & 5 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ cmake_minimum_required (VERSION 3.31.8)
#
include(FetchContent)

FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/9406a60c7839052e4944ea4dbc8344762a89f9bd.zip
)
FetchContent_MakeAvailable(googletest)
# Prefer GTest from Conan / system; fall back to FetchContent for standalone builds.
find_package(GTest QUIET)
if(NOT GTest_FOUND)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/9406a60c7839052e4944ea4dbc8344762a89f9bd.zip
)
FetchContent_MakeAvailable(googletest)
endif()

if (TRITON_COMMON_ENABLE_JSON)
add_subdirectory(triton_json triton_json)
Expand Down
Loading