Files
Echoion/cmake/EchoionComponents.cmake
faumaray 458dde05a6
Modular container CI / release-build (push) Has been cancelled
Release: cut over Echoion 2.0 components
2026-07-29 20:35:27 +03:00

137 lines
5.3 KiB
CMake

include_guard(GLOBAL)
set(ECHOION_COMPONENT_REGISTRY
"${CMAKE_CURRENT_LIST_DIR}/../components.json"
CACHE FILEPATH "Echoion component repository registry")
set(ECHOION_COMPONENT_LOCK
"${CMAKE_CURRENT_LIST_DIR}/../components.lock.json"
CACHE FILEPATH "Echoion component release lock")
option(ECHOION_RELEASE_BUILD
"Resolve Echoion components at exact revisions from components.lock.json"
OFF)
foreach(_echoionComponentFile IN ITEMS
"${ECHOION_COMPONENT_REGISTRY}" "${ECHOION_COMPONENT_LOCK}")
if(NOT EXISTS "${_echoionComponentFile}")
message(FATAL_ERROR
"Echoion component metadata does not exist: "
"${_echoionComponentFile}")
endif()
endforeach()
file(READ "${ECHOION_COMPONENT_REGISTRY}" _echoionComponentRegistryJson)
file(READ "${ECHOION_COMPONENT_LOCK}" _echoionComponentLockJson)
string(JSON _echoionRegistrySchema ERROR_VARIABLE _echoionRegistryError
GET "${_echoionComponentRegistryJson}" schemaVersion)
string(JSON _echoionLockSchema ERROR_VARIABLE _echoionLockError
GET "${_echoionComponentLockJson}" schemaVersion)
if(_echoionRegistryError OR NOT _echoionRegistrySchema EQUAL 1)
message(FATAL_ERROR
"Unsupported Echoion component registry: "
"${ECHOION_COMPONENT_REGISTRY}")
endif()
if(_echoionLockError OR NOT _echoionLockSchema EQUAL 2)
message(FATAL_ERROR
"Unsupported Echoion component lock: ${ECHOION_COMPONENT_LOCK}")
endif()
string(JSON _echoionLockedProductVersion
GET "${_echoionComponentLockJson}" productVersion)
if(ECHOION_RELEASE_BUILD AND
NOT _echoionLockedProductVersion STREQUAL ECHOION_PRODUCT_VERSION)
message(FATAL_ERROR
"components.lock.json productVersion "
"${_echoionLockedProductVersion} does not match root version "
"${ECHOION_PRODUCT_VERSION}")
endif()
function(echoion_add_component component)
string(JSON repository ERROR_VARIABLE repositoryError
GET "${_echoionComponentRegistryJson}"
components "${component}" url)
string(JSON branch ERROR_VARIABLE branchError
GET "${_echoionComponentRegistryJson}"
components "${component}" branch)
if(repositoryError OR branchError OR repository STREQUAL "" OR
branch STREQUAL "")
message(FATAL_ERROR
"Component ${component} is incomplete in "
"${ECHOION_COMPONENT_REGISTRY}")
endif()
set(sourceVariable "CPM_${component}_SOURCE")
if(DEFINED ${sourceVariable} AND
NOT "${${sourceVariable}}" STREQUAL "")
set(revision "${branch}")
message(STATUS
"Echoion component ${component}: local override "
"${${sourceVariable}}")
elseif(ECHOION_RELEASE_BUILD)
string(JSON revision ERROR_VARIABLE revisionError
GET "${_echoionComponentLockJson}"
components "${component}" revision)
if(revisionError OR revision STREQUAL "")
message(FATAL_ERROR
"Component ${component} has no locked release revision")
endif()
message(STATUS
"Echoion component ${component}: locked ${revision}")
else()
set(revision "${branch}")
message(STATUS
"Echoion component ${component}: development ${branch}")
endif()
if(ECHOION_RELEASE_BUILD)
string(JSON componentVersion ERROR_VARIABLE componentVersionError
GET "${_echoionComponentLockJson}"
components "${component}" componentVersion)
if(componentVersionError OR componentVersion STREQUAL "")
message(FATAL_ERROR
"Component ${component} has no locked component version")
endif()
# Component projects intentionally accept ECHOION_PRODUCT_VERSION when
# embedded. Scope the independently derived version to this CPM call;
# the root product version remains unchanged for the next component.
set(ECHOION_PRODUCT_VERSION "${componentVersion}")
set(ECHOION_COMPONENT_VERSION "${componentVersion}")
message(STATUS
"Echoion component ${component}: version ${componentVersion}")
endif()
set(componentOptions "")
string(JSON optionCount ERROR_VARIABLE optionsError
LENGTH "${_echoionComponentRegistryJson}"
components "${component}" buildOptions)
if(NOT optionsError AND optionCount GREATER 0)
math(EXPR optionLast "${optionCount} - 1")
foreach(optionIndex RANGE 0 ${optionLast})
string(JSON optionName MEMBER
"${_echoionComponentRegistryJson}"
components "${component}" buildOptions ${optionIndex})
string(JSON optionValue GET
"${_echoionComponentRegistryJson}"
components "${component}" buildOptions "${optionName}")
list(APPEND componentOptions "${optionName} ${optionValue}")
endforeach()
endif()
if(componentOptions)
CPMAddPackage(
NAME "${component}"
GIT_REPOSITORY "${repository}"
GIT_TAG "${revision}"
OPTIONS ${componentOptions})
else()
CPMAddPackage(
NAME "${component}"
GIT_REPOSITORY "${repository}"
GIT_TAG "${revision}")
endif()
if(DEFINED ${component}_SOURCE_DIR)
set(${component}_SOURCE_DIR "${${component}_SOURCE_DIR}" PARENT_SCOPE)
endif()
endfunction()