Split source gen targets from bin lib targets

This commit is contained in:
2026-03-02 23:21:04 -04:00
parent 3fc7ec72d3
commit c72f93efe1
3 changed files with 111 additions and 31 deletions

View File

@@ -76,8 +76,9 @@ function(cppbessot_add_generated_libraries)
cppbessot_get_schema_dir_path(_version_dir "${CPPB_SCHEMA_DIR}")
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(_expected_model_headers _expected_model_sources "${CPPB_SCHEMA_DIR}")
file(GLOB _model_include_dirs LIST_DIRECTORIES true "${_cpp_include_dir}/*/model")
cppbessot_get_expected_odb_outputs(_expected_sqlite_odb_sources _expected_pgsql_odb_sources "${CPPB_SCHEMA_DIR}")
set_source_files_properties(${_expected_model_headers} ${_expected_model_sources}
PROPERTIES GENERATED TRUE)
@@ -90,37 +91,37 @@ function(cppbessot_add_generated_libraries)
_cppbessot_try_link_nlohmann(cppBeSsotOpenAiModelGen)
add_library(cppbessot::openai_model_gen ALIAS cppBeSsotOpenAiModelGen)
file(GLOB _sqlite_odb_sources CONFIGURE_DEPENDS
"${_version_dir}/generated-odb-source/sqlite/*-odb.cxx")
if(_sqlite_odb_sources)
add_library(cppBeSsotOdbSqlite SHARED ${_sqlite_odb_sources})
set_target_properties(cppBeSsotOdbSqlite PROPERTIES
OUTPUT_NAME "cppBeSsotOdbSqlite"
POSITION_INDEPENDENT_CODE ON)
target_include_directories(cppBeSsotOdbSqlite PUBLIC
"${_cpp_include_dir}"
"${_version_dir}/generated-odb-source/sqlite"
${_model_include_dirs})
add_library(cppbessot::odb_sqlite ALIAS cppBeSsotOdbSqlite)
else()
message(WARNING "No generated sqlite ODB sources found for ${CPPB_SCHEMA_DIR}; skipping libcppBeSsotOdbSqlite.")
endif()
set_source_files_properties(${_expected_sqlite_odb_sources} PROPERTIES GENERATED TRUE)
add_library(cppBeSsotOdbSqlite SHARED ${_expected_sqlite_odb_sources})
add_dependencies(cppBeSsotOdbSqlite db_gen_odb_logic)
set_target_properties(cppBeSsotOdbSqlite PROPERTIES
OUTPUT_NAME "cppBeSsotOdbSqlite"
POSITION_INDEPENDENT_CODE ON)
target_include_directories(cppBeSsotOdbSqlite PUBLIC
"${_cpp_include_dir}"
"${_model_leaf_include_dir}"
"${_version_dir}/generated-odb-source/sqlite"
"${CPPBESSOT_SQLITE_INCLUDE_DIR}")
target_link_libraries(cppBeSsotOdbSqlite PUBLIC
"${CPPBESSOT_ODB_RUNTIME_LIB}"
"${CPPBESSOT_ODB_SQLITE_RUNTIME_LIB}")
add_library(cppbessot::odb_sqlite ALIAS cppBeSsotOdbSqlite)
file(GLOB _pgsql_odb_sources CONFIGURE_DEPENDS
"${_version_dir}/generated-odb-source/postgre/*-odb.cxx")
if(_pgsql_odb_sources)
add_library(cppBeSsotOdbPgSql SHARED ${_pgsql_odb_sources})
set_target_properties(cppBeSsotOdbPgSql PROPERTIES
OUTPUT_NAME "cppBeSsotOdbPgSql"
POSITION_INDEPENDENT_CODE ON)
target_include_directories(cppBeSsotOdbPgSql PUBLIC
"${_cpp_include_dir}"
"${_version_dir}/generated-odb-source/postgre"
${_model_include_dirs})
add_library(cppbessot::odb_pgsql ALIAS cppBeSsotOdbPgSql)
else()
message(WARNING "No generated postgre ODB sources found for ${CPPB_SCHEMA_DIR}; skipping libcppBeSsotOdbPgSql.")
endif()
set_source_files_properties(${_expected_pgsql_odb_sources} PROPERTIES GENERATED TRUE)
add_library(cppBeSsotOdbPgSql SHARED ${_expected_pgsql_odb_sources})
add_dependencies(cppBeSsotOdbPgSql db_gen_odb_logic)
set_target_properties(cppBeSsotOdbPgSql PROPERTIES
OUTPUT_NAME "cppBeSsotOdbPgSql"
POSITION_INDEPENDENT_CODE ON)
target_include_directories(cppBeSsotOdbPgSql PUBLIC
"${_cpp_include_dir}"
"${_model_leaf_include_dir}"
"${_version_dir}/generated-odb-source/postgre"
"${CPPBESSOT_PGSQL_INCLUDE_DIR}")
target_link_libraries(cppBeSsotOdbPgSql PUBLIC
"${CPPBESSOT_ODB_RUNTIME_LIB}"
"${CPPBESSOT_ODB_PGSQL_RUNTIME_LIB}")
add_library(cppbessot::odb_pgsql ALIAS cppBeSsotOdbPgSql)
endfunction()
function(cppbessot_enable)

View File

@@ -2,6 +2,7 @@ include_guard(GLOBAL)
include("${CMAKE_CURRENT_LIST_DIR}/dbGenerationCommon.cmake")
include(CheckIncludeFileCXX)
include(CMakePushCheckState)
function(_cppbessot_require_program var_name program_name hint)
# Purpose: Locate an executable and fail with a clear install hint if missing.
@@ -126,10 +127,63 @@ function(cppbessot_check_dependencies)
endif()
endif()
find_library(CPPBESSOT_ODB_RUNTIME_LIB NAMES odb libodb)
if(NOT CPPBESSOT_ODB_RUNTIME_LIB)
message(FATAL_ERROR
"ODB runtime library was not found. On Ubuntu/Debian install package `libodb-dev`.")
endif()
find_library(CPPBESSOT_ODB_SQLITE_RUNTIME_LIB NAMES odb-sqlite libodb-sqlite)
if(NOT CPPBESSOT_ODB_SQLITE_RUNTIME_LIB)
message(FATAL_ERROR
"ODB SQLite runtime library was not found. On Ubuntu/Debian install package `libodb-sqlite-dev`.")
endif()
find_library(CPPBESSOT_ODB_PGSQL_RUNTIME_LIB NAMES odb-pgsql libodb-pgsql)
if(NOT CPPBESSOT_ODB_PGSQL_RUNTIME_LIB)
message(FATAL_ERROR
"ODB PostgreSQL runtime library was not found. On Ubuntu/Debian install package `libodb-pgsql-dev`.")
endif()
find_path(CPPBESSOT_SQLITE_INCLUDE_DIR sqlite3.h)
if(NOT CPPBESSOT_SQLITE_INCLUDE_DIR)
message(FATAL_ERROR
"SQLite development headers were not found. On Ubuntu/Debian install package `libsqlite3-dev`.")
endif()
find_path(CPPBESSOT_PGSQL_INCLUDE_DIR libpq-fe.h PATH_SUFFIXES postgresql)
if(NOT CPPBESSOT_PGSQL_INCLUDE_DIR)
message(FATAL_ERROR
"PostgreSQL client development headers were not found. On Ubuntu/Debian install package `libpq-dev`.")
endif()
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES "${CPPBESSOT_SQLITE_INCLUDE_DIR}")
check_include_file_cxx("sqlite3.h" CPPBESSOT_HAS_SQLITE3_HEADER)
cmake_pop_check_state()
if(NOT CPPBESSOT_HAS_SQLITE3_HEADER)
message(FATAL_ERROR
"SQLite development headers are not usable. Expected to compile with include path `${CPPBESSOT_SQLITE_INCLUDE_DIR}`.")
endif()
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES "${CPPBESSOT_PGSQL_INCLUDE_DIR}")
check_include_file_cxx("libpq-fe.h" CPPBESSOT_HAS_LIBPQ_HEADER)
cmake_pop_check_state()
if(NOT CPPBESSOT_HAS_LIBPQ_HEADER)
message(FATAL_ERROR
"PostgreSQL development headers are not usable. Expected to compile with include path `${CPPBESSOT_PGSQL_INCLUDE_DIR}`.")
endif()
set(CPPBESSOT_ODB_EXECUTABLE "${CPPBESSOT_ODB_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_NPX_EXECUTABLE "${CPPBESSOT_NPX_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_NPM_EXECUTABLE "${CPPBESSOT_NPM_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_JAVA_EXECUTABLE "${CPPBESSOT_JAVA_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_GIT_EXECUTABLE "${CPPBESSOT_GIT_EXECUTABLE}" PARENT_SCOPE)
set(CPPBESSOT_ODB_RUNTIME_LIB "${CPPBESSOT_ODB_RUNTIME_LIB}" PARENT_SCOPE)
set(CPPBESSOT_ODB_SQLITE_RUNTIME_LIB "${CPPBESSOT_ODB_SQLITE_RUNTIME_LIB}" PARENT_SCOPE)
set(CPPBESSOT_ODB_PGSQL_RUNTIME_LIB "${CPPBESSOT_ODB_PGSQL_RUNTIME_LIB}" PARENT_SCOPE)
set(CPPBESSOT_SQLITE_INCLUDE_DIR "${CPPBESSOT_SQLITE_INCLUDE_DIR}" PARENT_SCOPE)
set(CPPBESSOT_PGSQL_INCLUDE_DIR "${CPPBESSOT_PGSQL_INCLUDE_DIR}" PARENT_SCOPE)
set(CPPBESSOT_OPENAPI_ZOD_AVAILABLE TRUE PARENT_SCOPE)
endfunction()

View File

@@ -175,3 +175,28 @@ function(cppbessot_get_expected_cpp_model_outputs out_headers_var out_sources_va
set(${out_headers_var} "${_headers}" PARENT_SCOPE)
set(${out_sources_var} "${_sources}" PARENT_SCOPE)
endfunction()
function(cppbessot_get_expected_odb_outputs out_sqlite_sources_var out_pgsql_sources_var schema_dir)
# Purpose: Infer generated ODB backend source files from OpenAPI schema names.
# Inputs:
# - out_sqlite_sources_var: Parent-scope variable for sqlite `*-odb.cxx`.
# - out_pgsql_sources_var: Parent-scope variable for postgre `*-odb.cxx`.
# - schema_dir: Schema directory basename.
# Outputs:
# - <out_sqlite_sources_var> (PARENT_SCOPE): Expected sqlite ODB sources.
# - <out_pgsql_sources_var> (PARENT_SCOPE): Expected postgre ODB sources.
cppbessot_get_schema_dir_path(_schema_dir_path "${schema_dir}")
cppbessot_get_openapi_schema_names(_schema_names "${schema_dir}")
set(_sqlite_sources)
set(_pgsql_sources)
foreach(_schema_name IN LISTS _schema_names)
list(APPEND _sqlite_sources
"${_schema_dir_path}/generated-odb-source/sqlite/${_schema_name}-odb.cxx")
list(APPEND _pgsql_sources
"${_schema_dir_path}/generated-odb-source/postgre/${_schema_name}-odb.cxx")
endforeach()
set(${out_sqlite_sources_var} "${_sqlite_sources}" PARENT_SCOPE)
set(${out_pgsql_sources_var} "${_pgsql_sources}" PARENT_SCOPE)
endfunction()