Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
 
cmake_minimum_required(VERSION 3.18)
 
project(model_package VERSION 1.0.0 LANGUAGES CXX)
 
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
 
# ─────────────────────────────────────────────────────────────────────────────
# Options
# ─────────────────────────────────────────────────────────────────────────────
 
option(MODEL_PACKAGE_BUILD_SHARED "Build as shared library" ON)
option(MODEL_PACKAGE_BUILD_TESTS "Build tests" OFF)
 
# ─────────────────────────────────────────────────────────────────────────────
# Dependencies
# ─────────────────────────────────────────────────────────────────────────────
 
# Allow the user to provide a pre-existing nlohmann_json via NLOHMANN_JSON_DIR
# (pointing to the source tree with include/nlohmann/json.hpp).
# Falls back to FetchContent if not provided.
# When built as a subdirectory (e.g., within ORT), the target may already exist.
if(TARGET nlohmann_json::nlohmann_json)
  # Already available from parent project — nothing to do.
elseif(NLOHMANN_JSON_DIR)
  # Use the provided directory directly.
  add_library(nlohmann_json_header_only INTERFACE)
  target_include_directories(nlohmann_json_header_only INTERFACE
    "${NLOHMANN_JSON_DIR}/include"
    "${NLOHMANN_JSON_DIR}/single_include"
  )
  add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json_header_only)
else()
  find_package(nlohmann_json QUIET)
  if(NOT nlohmann_json_FOUND)
    include(FetchContent)
    FetchContent_Declare(
      nlohmann_json
      URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
      URL_HASH SHA256=d6c65aca6b1ed68e7a182f4757257b107ae403032760ed6ef121c9d55e81757d
    )
    FetchContent_MakeAvailable(nlohmann_json)
  endif()
endif()
 
# ─────────────────────────────────────────────────────────────────────────────
# Library target
# ─────────────────────────────────────────────────────────────────────────────
 
set(MODEL_PACKAGE_SOURCES
  src/asset_hasher.cc
  src/authoring.cc
  src/commit_prune_validate.cc
  src/manifest_parser.cc
  src/model_package_impl.cc
  src/path_resolver.cc
  src/sha256.cc
)
 
if(MODEL_PACKAGE_BUILD_SHARED)
  add_library(model_package SHARED ${MODEL_PACKAGE_SOURCES})
  target_compile_definitions(model_package PRIVATE MODEL_PACKAGE_DLL_EXPORT)
else()
  add_library(model_package STATIC ${MODEL_PACKAGE_SOURCES})
endif()
 
target_include_directories(model_package
  PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>
  PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/src
)
 
target_link_libraries(model_package PRIVATE nlohmann_json::nlohmann_json)
 
set_target_properties(model_package PROPERTIES
  POSITION_INDEPENDENT_CODE ON
  VERSION ${PROJECT_VERSION}
  SOVERSION 1
)
 
# ─────────────────────────────────────────────────────────────────────────────
# Install
# ─────────────────────────────────────────────────────────────────────────────
 
include(GNUInstallDirs)
 
install(TARGETS model_package
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
 
install(FILES include/model_package_api.h include/model_package.h
  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
 
# ─────────────────────────────────────────────────────────────────────────────
# Tests
# ─────────────────────────────────────────────────────────────────────────────
 
if(MODEL_PACKAGE_BUILD_TESTS)
  enable_testing()
  add_executable(test_inspection tests/test_inspection.cc)
  target_link_libraries(test_inspection PRIVATE model_package nlohmann_json::nlohmann_json)
  target_include_directories(test_inspection PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${CMAKE_CURRENT_SOURCE_DIR}/src
  )
  add_test(NAME inspection COMMAND test_inspection)
 
  add_executable(test_asset_hashing tests/test_asset_hashing.cc)
  target_link_libraries(test_asset_hashing PRIVATE model_package nlohmann_json::nlohmann_json)
  target_include_directories(test_asset_hashing PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${CMAKE_CURRENT_SOURCE_DIR}/src
  )
  add_test(NAME asset_hashing COMMAND test_asset_hashing)
 
  add_executable(test_authoring tests/test_authoring.cc)
  target_link_libraries(test_authoring PRIVATE model_package nlohmann_json::nlohmann_json)
  target_include_directories(test_authoring PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${CMAKE_CURRENT_SOURCE_DIR}/src
  )
  add_test(NAME authoring COMMAND test_authoring)
 
  add_executable(test_commit tests/test_commit.cc)
  target_link_libraries(test_commit PRIVATE model_package nlohmann_json::nlohmann_json)
  target_include_directories(test_commit PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${CMAKE_CURRENT_SOURCE_DIR}/src
  )
  add_test(NAME commit COMMAND test_commit)
endif()