@@ -12,12 +12,18 @@ cmake_minimum_required(VERSION 3.20)
1212project (vix_orm VERSION 1.3.0 LANGUAGES CXX )
1313
1414include (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
2329set (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 ()
59100endif ()
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." )
63107endif ()
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 )
129175endif ()
@@ -156,4 +202,13 @@ install(DIRECTORY include/
156202message (STATUS "------------------------------------------------------" )
157203message (STATUS "[vix_orm] configured (${PROJECT_VERSION} )" )
158204message (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 ()
159214message (STATUS "------------------------------------------------------" )
0 commit comments