mirror of
https://github.com/latentPrion/cppbessot.git
synced 2026-04-17 18:44:23 +00:00
openai_gen_model now depends on db_gen_cpp_headers
This commit is contained in:
@@ -76,21 +76,19 @@ function(cppbessot_add_generated_libraries)
|
|||||||
cppbessot_get_schema_dir_path(_version_dir "${CPPB_SCHEMA_DIR}")
|
cppbessot_get_schema_dir_path(_version_dir "${CPPB_SCHEMA_DIR}")
|
||||||
|
|
||||||
set(_cpp_include_dir "${_version_dir}/generated-cpp-source/include")
|
set(_cpp_include_dir "${_version_dir}/generated-cpp-source/include")
|
||||||
|
cppbessot_get_expected_cpp_model_outputs(_expected_model_headers _expected_model_sources "${CPPB_SCHEMA_DIR}")
|
||||||
file(GLOB _model_include_dirs LIST_DIRECTORIES true "${_cpp_include_dir}/*/model")
|
file(GLOB _model_include_dirs LIST_DIRECTORIES true "${_cpp_include_dir}/*/model")
|
||||||
|
|
||||||
file(GLOB _model_sources CONFIGURE_DEPENDS
|
set_source_files_properties(${_expected_model_headers} ${_expected_model_sources}
|
||||||
"${_version_dir}/generated-cpp-source/src/model/*.cpp")
|
PROPERTIES GENERATED TRUE)
|
||||||
if(_model_sources)
|
add_library(cppBeSsotOpenAiModelGen STATIC ${_expected_model_sources})
|
||||||
add_library(cppBeSsotOpenAiModelGen STATIC ${_model_sources})
|
add_dependencies(cppBeSsotOpenAiModelGen db_gen_cpp_headers)
|
||||||
set_target_properties(cppBeSsotOpenAiModelGen PROPERTIES
|
set_target_properties(cppBeSsotOpenAiModelGen PROPERTIES
|
||||||
OUTPUT_NAME "cppBeSsotOpenAiModelGen"
|
OUTPUT_NAME "cppBeSsotOpenAiModelGen"
|
||||||
POSITION_INDEPENDENT_CODE ON)
|
POSITION_INDEPENDENT_CODE ON)
|
||||||
target_include_directories(cppBeSsotOpenAiModelGen PUBLIC "${_cpp_include_dir}")
|
target_include_directories(cppBeSsotOpenAiModelGen PUBLIC "${_cpp_include_dir}")
|
||||||
_cppbessot_try_link_nlohmann(cppBeSsotOpenAiModelGen)
|
_cppbessot_try_link_nlohmann(cppBeSsotOpenAiModelGen)
|
||||||
add_library(cppbessot::openai_model_gen ALIAS cppBeSsotOpenAiModelGen)
|
add_library(cppbessot::openai_model_gen ALIAS cppBeSsotOpenAiModelGen)
|
||||||
else()
|
|
||||||
message(WARNING "No generated C++ model sources found for ${CPPB_SCHEMA_DIR}; skipping libcppBeSsotOpenAiModelGen.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
file(GLOB _sqlite_odb_sources CONFIGURE_DEPENDS
|
file(GLOB _sqlite_odb_sources CONFIGURE_DEPENDS
|
||||||
"${_version_dir}/generated-odb-source/sqlite/*-odb.cxx")
|
"${_version_dir}/generated-odb-source/sqlite/*-odb.cxx")
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ function(cppbessot_add_db_gen_cpp_target schema_dir)
|
|||||||
set(_template_dir "${_module_root}/openapi/templates/cpp-odb-json")
|
set(_template_dir "${_module_root}/openapi/templates/cpp-odb-json")
|
||||||
set(_template_config "${_template_dir}/config.yaml")
|
set(_template_config "${_template_dir}/config.yaml")
|
||||||
set(_output_dir "${_version_dir}/generated-cpp-source")
|
set(_output_dir "${_version_dir}/generated-cpp-source")
|
||||||
|
file(GLOB_RECURSE _template_inputs CONFIGURE_DEPENDS "${_template_dir}/*")
|
||||||
|
|
||||||
add_custom_target(db_gen_cpp_headers
|
add_custom_target(db_gen_cpp_headers
|
||||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${_output_dir}"
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${_output_dir}"
|
||||||
@@ -33,6 +34,7 @@ function(cppbessot_add_db_gen_cpp_target schema_dir)
|
|||||||
-c "${_template_config}"
|
-c "${_template_config}"
|
||||||
-o "${_output_dir}"
|
-o "${_output_dir}"
|
||||||
--global-property models
|
--global-property models
|
||||||
|
DEPENDS "${_openapi_file}" ${_template_inputs}
|
||||||
COMMENT "Generating C++ model headers/sources for ${schema_dir}"
|
COMMENT "Generating C++ model headers/sources for ${schema_dir}"
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -102,3 +102,76 @@ function(cppbessot_get_model_headers_glob out_var schema_dir)
|
|||||||
cppbessot_get_schema_dir_path(_schema_dir_path "${schema_dir}")
|
cppbessot_get_schema_dir_path(_schema_dir_path "${schema_dir}")
|
||||||
set(${out_var} "${_schema_dir_path}/generated-cpp-source/include/*/model/*.h" PARENT_SCOPE)
|
set(${out_var} "${_schema_dir_path}/generated-cpp-source/include/*/model/*.h" PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(cppbessot_get_openapi_schema_names out_var schema_dir)
|
||||||
|
# Purpose: Parse top-level component schema names from a schema directory's OpenAPI file.
|
||||||
|
# Inputs:
|
||||||
|
# - out_var: Parent-scope variable name to receive the schema names.
|
||||||
|
# - schema_dir: Schema directory basename.
|
||||||
|
# Outputs:
|
||||||
|
# - <out_var> (PARENT_SCOPE): List of top-level component schema names.
|
||||||
|
cppbessot_get_schema_dir_path(_schema_dir_path "${schema_dir}")
|
||||||
|
set(_openapi_file "${_schema_dir_path}/openapi/openapi.yaml")
|
||||||
|
if(NOT EXISTS "${_openapi_file}")
|
||||||
|
message(FATAL_ERROR "OpenAPI file does not exist: ${_openapi_file}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
file(STRINGS "${_openapi_file}" _openapi_lines)
|
||||||
|
set(_schema_names)
|
||||||
|
set(_in_components FALSE)
|
||||||
|
set(_in_schemas FALSE)
|
||||||
|
|
||||||
|
foreach(_line IN LISTS _openapi_lines)
|
||||||
|
if(_in_schemas)
|
||||||
|
if(_line MATCHES "^[^ ]" OR _line MATCHES "^ [^ ]")
|
||||||
|
set(_in_schemas FALSE)
|
||||||
|
elseif(_line MATCHES "^ ([A-Za-z_][A-Za-z0-9_]*)[ \t]*:[ \t]*$")
|
||||||
|
list(APPEND _schema_names "${CMAKE_MATCH_1}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(_in_components AND NOT _in_schemas)
|
||||||
|
if(_line MATCHES "^[^ ]")
|
||||||
|
set(_in_components FALSE)
|
||||||
|
elseif(_line MATCHES "^ schemas:[ \t]*$")
|
||||||
|
set(_in_schemas TRUE)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(_line MATCHES "^components:[ \t]*$")
|
||||||
|
set(_in_components TRUE)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
if(NOT _schema_names)
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"No component schema names were found in ${_openapi_file}.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(${out_var} "${_schema_names}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(cppbessot_get_expected_cpp_model_outputs out_headers_var out_sources_var schema_dir)
|
||||||
|
# Purpose: Infer generated C++ model headers and sources from OpenAPI schema names.
|
||||||
|
# Inputs:
|
||||||
|
# - out_headers_var: Parent-scope variable name to receive expected headers.
|
||||||
|
# - out_sources_var: Parent-scope variable name to receive expected sources.
|
||||||
|
# - schema_dir: Schema directory basename.
|
||||||
|
# Outputs:
|
||||||
|
# - <out_headers_var> (PARENT_SCOPE): Expected generated model headers.
|
||||||
|
# - <out_sources_var> (PARENT_SCOPE): Expected generated model sources.
|
||||||
|
cppbessot_get_schema_dir_path(_schema_dir_path "${schema_dir}")
|
||||||
|
cppbessot_get_openapi_schema_names(_schema_names "${schema_dir}")
|
||||||
|
|
||||||
|
set(_headers)
|
||||||
|
set(_sources)
|
||||||
|
foreach(_schema_name IN LISTS _schema_names)
|
||||||
|
list(APPEND _headers
|
||||||
|
"${_schema_dir_path}/generated-cpp-source/include/cppbessot/model/${_schema_name}.h")
|
||||||
|
list(APPEND _sources
|
||||||
|
"${_schema_dir_path}/generated-cpp-source/src/model/${_schema_name}.cpp")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set(${out_headers_var} "${_headers}" PARENT_SCOPE)
|
||||||
|
set(${out_sources_var} "${_sources}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|||||||
Reference in New Issue
Block a user