include_guard(GLOBAL) set(ECHOION_COMPONENT_LOCK "${CMAKE_CURRENT_LIST_DIR}/../components.lock.json" CACHE FILEPATH "Echoion component repository lock file") if(NOT EXISTS "${ECHOION_COMPONENT_LOCK}") message(FATAL_ERROR "Echoion component lock does not exist: ${ECHOION_COMPONENT_LOCK}") endif() file(READ "${ECHOION_COMPONENT_LOCK}" _echoionComponentLockJson) string(JSON _echoionComponentLockSchema ERROR_VARIABLE _echoionLockError GET "${_echoionComponentLockJson}" schemaVersion) if(_echoionLockError OR NOT _echoionComponentLockSchema EQUAL 1) message(FATAL_ERROR "Unsupported Echoion component lock: ${ECHOION_COMPONENT_LOCK}") endif() function(echoion_add_component component) string(JSON repository ERROR_VARIABLE repositoryError GET "${_echoionComponentLockJson}" components "${component}" url) string(JSON revision ERROR_VARIABLE revisionError GET "${_echoionComponentLockJson}" components "${component}" revision) if(repositoryError OR revisionError OR repository STREQUAL "" OR revision STREQUAL "") message(FATAL_ERROR "Component ${component} is incomplete in " "${ECHOION_COMPONENT_LOCK}") endif() # A workspace created by scripts/sync-components.py or by the Gitea # workflow wins over network fetching. This keeps private credentials out # of Docker while a clean public checkout can still resolve through CPM. set(localSource "${CMAKE_SOURCE_DIR}/${component}") if(EXISTS "${localSource}/CMakeLists.txt") set("CPM_${component}_SOURCE" "${localSource}" CACHE PATH "Local ${component} source directory") endif() CPMAddPackage( NAME "${component}" GIT_REPOSITORY "${repository}" GIT_TAG "${revision}" ) endfunction()