mirror of
https://github.com/latentPrion/cppbessot.git
synced 2026-06-23 15:18:37 +00:00
Split db-gen targets; eradicate SCHEMA_DIR shorthand var
This commit is contained in:
+70
-29
@@ -1,6 +1,5 @@
|
|||||||
include_guard(GLOBAL)
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
include(CMakeParseArguments)
|
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/dbGenerationCommon.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/dbGenerationCommon.cmake")
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/dbDependencyCheck.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/dbDependencyCheck.cmake")
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/dbSchemaCheck.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/dbSchemaCheck.cmake")
|
||||||
@@ -48,6 +47,20 @@ function(_cppbessot_try_link_nlohmann target_name)
|
|||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(_cppbessot_assert_generation_targets_registered consumer_name)
|
||||||
|
# Purpose: Ensure split public library registration functions are only used
|
||||||
|
# after generation targets are registered (typically via cppbessot_enable()).
|
||||||
|
# Inputs:
|
||||||
|
# - consumer_name: Human-readable function name for diagnostics.
|
||||||
|
# Outputs:
|
||||||
|
# - No return value; raises FATAL_ERROR when prerequisites are missing.
|
||||||
|
if(NOT TARGET db_gen_cpp_headers OR NOT TARGET db_gen_odb_logic OR NOT TARGET db_gen_sql_ddl)
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"${consumer_name} requires generation targets to be registered first. "
|
||||||
|
"Call cppbessot_enable() before invoking split generated-library registration functions.")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
function(_cppbessot_add_generated_model_library cpp_include_dir expected_model_headers expected_model_sources)
|
function(_cppbessot_add_generated_model_library cpp_include_dir expected_model_headers expected_model_sources)
|
||||||
set_source_files_properties(${expected_model_headers} ${expected_model_sources}
|
set_source_files_properties(${expected_model_headers} ${expected_model_sources}
|
||||||
PROPERTIES GENERATED TRUE)
|
PROPERTIES GENERATED TRUE)
|
||||||
@@ -111,42 +124,52 @@ function(_cppbessot_add_generated_pgsql_library
|
|||||||
add_library(cppbessot::odb_pgsql ALIAS cppBeSsotOdbPgSql)
|
add_library(cppbessot::odb_pgsql ALIAS cppBeSsotOdbPgSql)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(cppbessot_add_generated_libraries)
|
function(cppbessot_add_generated_cpp_model_libraries)
|
||||||
# Purpose: Create consumable libraries from generated model and ODB sources.
|
# Purpose: Create consumable C++ model library from generated model sources.
|
||||||
# Inputs:
|
# Inputs:
|
||||||
# - SCHEMA_DIR (optional named arg): Schema directory basename to consume.
|
# - DB_SCHEMA_DIR_TO_GENERATE: Schema directory basename under CPPBESSOT_WORKDIR.
|
||||||
# - DB_SCHEMA_DIR_TO_GENERATE (fallback): Default schema directory basename.
|
|
||||||
# Outputs:
|
# Outputs:
|
||||||
# - Library targets (when sources exist):
|
# - Library target:
|
||||||
# - cppBeSsotOpenAiModelGen
|
# - cppBeSsotOpenAiModelGen
|
||||||
# - cppBeSsotOdbSqlite
|
# - Alias target:
|
||||||
# - cppBeSsotOdbPgSql
|
|
||||||
# - Alias targets:
|
|
||||||
# - cppbessot::openai_model_gen
|
# - cppbessot::openai_model_gen
|
||||||
# - cppbessot::odb_sqlite
|
_cppbessot_assert_generation_targets_registered("cppbessot_add_generated_cpp_model_libraries")
|
||||||
# - cppbessot::odb_pgsql
|
cppbessot_validate_schema_dir_name("${DB_SCHEMA_DIR_TO_GENERATE}")
|
||||||
# - Emits warnings if expected source sets are missing.
|
cppbessot_get_schema_dir_path(_version_dir "${DB_SCHEMA_DIR_TO_GENERATE}")
|
||||||
set(options)
|
|
||||||
set(one_value_args SCHEMA_DIR)
|
|
||||||
set(multi_value_args)
|
|
||||||
cmake_parse_arguments(CPPB "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
|
|
||||||
|
|
||||||
if(NOT CPPB_SCHEMA_DIR)
|
|
||||||
set(CPPB_SCHEMA_DIR "${DB_SCHEMA_DIR_TO_GENERATE}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
cppbessot_validate_schema_dir_name("${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")
|
||||||
set(_model_leaf_include_dir "${_cpp_include_dir}/cppbessot/model")
|
cppbessot_get_expected_cpp_model_outputs(
|
||||||
cppbessot_get_expected_cpp_model_outputs(_expected_model_headers _expected_model_sources "${CPPB_SCHEMA_DIR}")
|
_expected_model_headers
|
||||||
cppbessot_get_expected_odb_outputs(_expected_sqlite_odb_sources _expected_pgsql_odb_sources "${CPPB_SCHEMA_DIR}")
|
_expected_model_sources
|
||||||
|
"${DB_SCHEMA_DIR_TO_GENERATE}")
|
||||||
|
|
||||||
_cppbessot_add_generated_model_library(
|
_cppbessot_add_generated_model_library(
|
||||||
"${_cpp_include_dir}"
|
"${_cpp_include_dir}"
|
||||||
"${_expected_model_headers}"
|
"${_expected_model_headers}"
|
||||||
"${_expected_model_sources}")
|
"${_expected_model_sources}")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(cppbessot_add_generated_odb_libraries)
|
||||||
|
# Purpose: Create consumable ODB libraries from generated ODB sources.
|
||||||
|
# Inputs:
|
||||||
|
# - DB_SCHEMA_DIR_TO_GENERATE: Schema directory basename under CPPBESSOT_WORKDIR.
|
||||||
|
# Outputs:
|
||||||
|
# - Library targets:
|
||||||
|
# - cppBeSsotOdbSqlite
|
||||||
|
# - cppBeSsotOdbPgSql
|
||||||
|
# - Alias targets:
|
||||||
|
# - cppbessot::odb_sqlite
|
||||||
|
# - cppbessot::odb_pgsql
|
||||||
|
_cppbessot_assert_generation_targets_registered("cppbessot_add_generated_odb_libraries")
|
||||||
|
cppbessot_validate_schema_dir_name("${DB_SCHEMA_DIR_TO_GENERATE}")
|
||||||
|
cppbessot_get_schema_dir_path(_version_dir "${DB_SCHEMA_DIR_TO_GENERATE}")
|
||||||
|
|
||||||
|
set(_cpp_include_dir "${_version_dir}/generated-cpp-source/include")
|
||||||
|
set(_model_leaf_include_dir "${_cpp_include_dir}/cppbessot/model")
|
||||||
|
cppbessot_get_expected_odb_outputs(
|
||||||
|
_expected_sqlite_odb_sources
|
||||||
|
_expected_pgsql_odb_sources
|
||||||
|
"${DB_SCHEMA_DIR_TO_GENERATE}")
|
||||||
|
|
||||||
_cppbessot_add_generated_sqlite_library(
|
_cppbessot_add_generated_sqlite_library(
|
||||||
"${_cpp_include_dir}"
|
"${_cpp_include_dir}"
|
||||||
"${_model_leaf_include_dir}"
|
"${_model_leaf_include_dir}"
|
||||||
@@ -159,6 +182,23 @@ function(cppbessot_add_generated_libraries)
|
|||||||
"${_expected_pgsql_odb_sources}")
|
"${_expected_pgsql_odb_sources}")
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(cppbessot_add_generated_libraries)
|
||||||
|
# Purpose: Create consumable libraries from generated model and ODB sources.
|
||||||
|
# Inputs:
|
||||||
|
# - DB_SCHEMA_DIR_TO_GENERATE: Schema directory basename under CPPBESSOT_WORKDIR.
|
||||||
|
# Outputs:
|
||||||
|
# - Library targets (when sources exist):
|
||||||
|
# - cppBeSsotOpenAiModelGen
|
||||||
|
# - cppBeSsotOdbSqlite
|
||||||
|
# - cppBeSsotOdbPgSql
|
||||||
|
# - Alias targets:
|
||||||
|
# - cppbessot::openai_model_gen
|
||||||
|
# - cppbessot::odb_sqlite
|
||||||
|
# - cppbessot::odb_pgsql
|
||||||
|
cppbessot_add_generated_cpp_model_libraries()
|
||||||
|
cppbessot_add_generated_odb_libraries()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
function(cppbessot_enable)
|
function(cppbessot_enable)
|
||||||
# Purpose: Entry-point orchestration for dependency checks, custom generation
|
# Purpose: Entry-point orchestration for dependency checks, custom generation
|
||||||
# targets, aggregate targets, and generated library registration.
|
# targets, aggregate targets, and generated library registration.
|
||||||
@@ -183,6 +223,7 @@ function(cppbessot_enable)
|
|||||||
|
|
||||||
cppbessot_validate_schema_dir_name("${DB_SCHEMA_DIR_TO_GENERATE}")
|
cppbessot_validate_schema_dir_name("${DB_SCHEMA_DIR_TO_GENERATE}")
|
||||||
cppbessot_assert_schema_dir_exists("${DB_SCHEMA_DIR_TO_GENERATE}")
|
cppbessot_assert_schema_dir_exists("${DB_SCHEMA_DIR_TO_GENERATE}")
|
||||||
|
cppbessot_assert_openapi_exists("${DB_SCHEMA_DIR_TO_GENERATE}")
|
||||||
|
|
||||||
cppbessot_check_dependencies()
|
cppbessot_check_dependencies()
|
||||||
|
|
||||||
@@ -206,7 +247,7 @@ function(cppbessot_enable)
|
|||||||
COMMAND "${CMAKE_COMMAND}" -E echo
|
COMMAND "${CMAKE_COMMAND}" -E echo
|
||||||
"Set DB_SCHEMA_DIR_MIGRATION_FROM and DB_SCHEMA_DIR_MIGRATION_TO to enable migration generation."
|
"Set DB_SCHEMA_DIR_MIGRATION_FROM and DB_SCHEMA_DIR_MIGRATION_TO to enable migration generation."
|
||||||
COMMAND "${CMAKE_COMMAND}" -E false
|
COMMAND "${CMAKE_COMMAND}" -E false
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
set_target_properties(db_gen_migrations PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
set_target_properties(db_gen_migrations PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
||||||
endif()
|
endif()
|
||||||
@@ -220,7 +261,7 @@ function(cppbessot_enable)
|
|||||||
db_gen_sql_ddl)
|
db_gen_sql_ddl)
|
||||||
set_target_properties(db_gen_orm_serdes_and_zod PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
set_target_properties(db_gen_orm_serdes_and_zod PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
||||||
|
|
||||||
cppbessot_add_generated_libraries(SCHEMA_DIR "${DB_SCHEMA_DIR_TO_GENERATE}")
|
cppbessot_add_generated_libraries()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
if(CPPBESSOT_AUTO_ENABLE)
|
if(CPPBESSOT_AUTO_ENABLE)
|
||||||
|
|||||||
@@ -92,6 +92,19 @@ function(cppbessot_assert_schema_dir_exists schema_dir)
|
|||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(cppbessot_assert_openapi_exists schema_dir)
|
||||||
|
# Purpose: Assert that a schema directory's SSOT OpenAPI file exists on disk.
|
||||||
|
# Inputs:
|
||||||
|
# - schema_dir: Schema directory basename.
|
||||||
|
# Outputs:
|
||||||
|
# - No return value; raises FATAL_ERROR if file is missing.
|
||||||
|
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()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
function(cppbessot_get_model_headers_glob out_var schema_dir)
|
function(cppbessot_get_model_headers_glob out_var schema_dir)
|
||||||
# Purpose: Build a model-header glob expression for a schema directory.
|
# Purpose: Build a model-header glob expression for a schema directory.
|
||||||
# Inputs:
|
# Inputs:
|
||||||
@@ -111,10 +124,8 @@ function(cppbessot_get_openapi_schema_names out_var schema_dir)
|
|||||||
# Outputs:
|
# Outputs:
|
||||||
# - <out_var> (PARENT_SCOPE): List of top-level component schema names.
|
# - <out_var> (PARENT_SCOPE): List of top-level component schema names.
|
||||||
cppbessot_get_schema_dir_path(_schema_dir_path "${schema_dir}")
|
cppbessot_get_schema_dir_path(_schema_dir_path "${schema_dir}")
|
||||||
|
cppbessot_assert_openapi_exists("${schema_dir}")
|
||||||
set(_openapi_file "${_schema_dir_path}/openapi/openapi.yaml")
|
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)
|
file(STRINGS "${_openapi_file}" _openapi_lines)
|
||||||
set(_schema_names)
|
set(_schema_names)
|
||||||
|
|||||||
Reference in New Issue
Block a user