From 2b240d280d7fef0c34f6b9e9fc23177f07fd31c2 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Sat, 23 Nov 2024 23:34:09 +0100 Subject: [PATCH] CheckSubmodules: Run `git submodule sync` This is required in case the URL of a submodule changes. Without this, if you use CheckSubmodules.cmake, submodule URL changes will cause warnings when you update, e.g. "ref ... could not be found on remote". --- cmake/modules/CheckSubmodules.cmake | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmake/modules/CheckSubmodules.cmake b/cmake/modules/CheckSubmodules.cmake index b9ea2077874..37300801ca2 100644 --- a/cmake/modules/CheckSubmodules.cmake +++ b/cmake/modules/CheckSubmodules.cmake @@ -139,7 +139,15 @@ MACRO(GIT_SUBMODULE SUBMODULE_PATH FORCE_DEINIT FORCE_REMOTE NO_DEPTH) SET(DEPTH_CMD "--depth") SET(DEPTH_VAL "${DEPTH_VALUE}") ENDIF() - + # Sync submodules - required in case a submodule URL changed + EXECUTE_PROCESS( + COMMAND "${GIT_EXECUTABLE}" submodule sync --recursive ${DEPTH_CMD} ${DEPTH_VAL} "${CMAKE_SOURCE_DIR}/${SUBMODULE_PATH}" + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE GIT_RESULT_SYNC + OUTPUT_VARIABLE GIT_STDOUT_SYNC + ERROR_VARIABLE GIT_STDERR_SYNC + ) + # Update and init submodules EXECUTE_PROCESS( COMMAND "${GIT_EXECUTABLE}" submodule update --init --recursive ${DEPTH_CMD} ${DEPTH_VAL} "${CMAKE_SOURCE_DIR}/${SUBMODULE_PATH}" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" @@ -148,7 +156,11 @@ MACRO(GIT_SUBMODULE SUBMODULE_PATH FORCE_DEINIT FORCE_REMOTE NO_DEPTH) ERROR_VARIABLE GIT_STDERR ) - SET(GIT_MESSAGE "${GIT_STDOUT}${GIT_STDERR}") + IF(NOT GIT_RESULT_SYNC EQUAL 0) + SET(GIT_RESULT 1) + ENDIF() + + SET(GIT_MESSAGE "${GIT_STDOUT_SYNC}${GIT_STDERR_SYNC}${GIT_STDOUT}${GIT_STDERR}") MESSAGE("${GIT_MESSAGE}") ENDIF() ENDMACRO()