Skip to content

Commit 25e1bcb

Browse files
committed
build(orm): make standalone builds fetch vix core/db
- Auto-detect monorepo vs standalone layout - Fetch vix deps when ../core or ../db are missing - Fail fast with clear error if deps are unavailable - Enable dependency fetching in CI
1 parent 90068b6 commit 25e1bcb

2 files changed

Lines changed: 73 additions & 6 deletions

File tree

.github/workflows/build.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,22 @@ jobs:
3636
3737
sudo apt-get install -y libspdlog-dev libmysqlcppconn-dev
3838
39+
- name: Cache CMake/FetchContent
40+
uses: actions/cache@v4
41+
with:
42+
path: |
43+
build
44+
~/.cache/cmake
45+
~/.cache/CMake
46+
key: ${{ runner.os }}-${{ matrix.compiler }}-cmake-${{ hashFiles('CMakeLists.txt') }}
47+
restore-keys: |
48+
${{ runner.os }}-${{ matrix.compiler }}-cmake-
49+
3950
- name: Configure (Release)
4051
run: |
4152
cmake -S . -B build -G Ninja \
4253
-DCMAKE_BUILD_TYPE=Release \
54+
-DVIX_ORM_FETCH_VIX_DEPS=ON \
4355
-DVIX_ORM_BUILD_EXAMPLES=ON \
4456
-DVIX_ORM_BUILD_TESTS=ON
4557

CMakeLists.txt

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ cmake_minimum_required(VERSION 3.20)
1212
project(vix_orm VERSION 1.3.0 LANGUAGES CXX)
1313

1414
include(GNUInstallDirs)
15+
include(FetchContent)
1516

1617
# ------------------------------------------------------------------------------
1718
# Options
1819
# ------------------------------------------------------------------------------
19-
option(VIX_ORM_BUILD_TESTS "Build unit tests for Vix ORM" OFF)
20-
option(VIX_ORM_BUILD_EXAMPLES "Build examples for Vix ORM" OFF)
20+
option(VIX_ORM_BUILD_TESTS "Build unit tests for Vix ORM" OFF)
21+
option(VIX_ORM_BUILD_EXAMPLES "Build examples for Vix ORM" OFF)
22+
23+
# Standalone support:
24+
# - Monorepo layout (vix/modules/orm): uses ../core and ../db
25+
# - Standalone repo (orm only): fetches Vix (core+db) with FetchContent
26+
option(VIX_ORM_FETCH_VIX_DEPS "Fetch vix core/db when building standalone" ON)
2127

2228
# language / PIC
2329
set(CMAKE_CXX_STANDARD 20)
@@ -54,12 +60,50 @@ set(VIX_ORM_SOURCES
5460
# ------------------------------------------------------------------------------
5561
# Bring required modules when building standalone
5662
# ------------------------------------------------------------------------------
57-
if (NOT TARGET vix::core)
58-
add_subdirectory(../core core_build)
63+
set(_VIX_ORM_HAS_MONOREPO_DEPS OFF)
64+
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/../core/CMakeLists.txt" AND
65+
EXISTS "${CMAKE_CURRENT_LIST_DIR}/../db/CMakeLists.txt")
66+
set(_VIX_ORM_HAS_MONOREPO_DEPS ON)
67+
endif()
68+
69+
# If core/db targets are missing, try to provide them via:
70+
# 1) monorepo add_subdirectory(../core, ../db)
71+
# 2) FetchContent vix + add_subdirectory(modules/core, modules/db)
72+
if (NOT TARGET vix::core OR NOT TARGET vix::db)
73+
if (_VIX_ORM_HAS_MONOREPO_DEPS)
74+
if (NOT TARGET vix::core)
75+
add_subdirectory(../core core_build)
76+
endif()
77+
78+
if (NOT TARGET vix::db)
79+
add_subdirectory(../db db_build)
80+
endif()
81+
else()
82+
if (VIX_ORM_FETCH_VIX_DEPS)
83+
# NOTE: pin this to a tag or commit for reproducible builds if desired.
84+
FetchContent_Declare(vix
85+
GIT_REPOSITORY https://github.com/vixcpp/vix.git
86+
GIT_TAG main
87+
)
88+
FetchContent_MakeAvailable(vix)
89+
90+
# Some upstream layouts may not add module targets automatically.
91+
if (NOT TARGET vix::core AND EXISTS "${vix_SOURCE_DIR}/modules/core/CMakeLists.txt")
92+
add_subdirectory("${vix_SOURCE_DIR}/modules/core" vix_core_build)
93+
endif()
94+
95+
if (NOT TARGET vix::db AND EXISTS "${vix_SOURCE_DIR}/modules/db/CMakeLists.txt")
96+
add_subdirectory("${vix_SOURCE_DIR}/modules/db" vix_db_build)
97+
endif()
98+
endif()
99+
endif()
59100
endif()
60101

61-
if (NOT TARGET vix::db)
62-
add_subdirectory(../db db_build)
102+
if (NOT TARGET vix::core OR NOT TARGET vix::db)
103+
message(FATAL_ERROR
104+
"vix_orm requires vix::core and vix::db.\n"
105+
"Build in the vix monorepo (vix/modules/orm) so ../core and ../db exist,\n"
106+
"or enable VIX_ORM_FETCH_VIX_DEPS=ON to fetch dependencies.")
63107
endif()
64108

65109
# ------------------------------------------------------------------------------
@@ -124,6 +168,8 @@ if (VIX_ORM_BUILD_EXAMPLES)
124168
${CMAKE_CURRENT_SOURCE_DIR}/examples/querybuilder_update.cpp)
125169
vix_add_orm_example(tx_unit_of_work
126170
${CMAKE_CURRENT_SOURCE_DIR}/examples/tx_unit_of_work.cpp)
171+
vix_add_orm_example(tx_unit_of_work
172+
${CMAKE_CURRENT_SOURCE_DIR}/examples/tx_unit_of_work.cpp)
127173
vix_add_orm_example(error_handling
128174
${CMAKE_CURRENT_SOURCE_DIR}/examples/error_handling.cpp)
129175
endif()
@@ -156,4 +202,13 @@ install(DIRECTORY include/
156202
message(STATUS "------------------------------------------------------")
157203
message(STATUS "[vix_orm] configured (${PROJECT_VERSION})")
158204
message(STATUS "[vix_orm] depends on: vix::db (drivers) + vix::core (base)")
205+
if (_VIX_ORM_HAS_MONOREPO_DEPS)
206+
message(STATUS "[vix_orm] deps mode : monorepo (../core, ../db)")
207+
else()
208+
if (VIX_ORM_FETCH_VIX_DEPS)
209+
message(STATUS "[vix_orm] deps mode : standalone (FetchContent vix)")
210+
else()
211+
message(STATUS "[vix_orm] deps mode : standalone (no fetch)")
212+
endif()
213+
endif()
159214
message(STATUS "------------------------------------------------------")

0 commit comments

Comments
 (0)