@@ -638,3 +638,62 @@ endmacro()
638638macro (write_source_definitions NBL_FILE NBL_WRAPPER_CODE_TO_WRITE)
639639 file (WRITE "${NBL_FILE} " "${NBL_WRAPPER_CODE_TO_WRITE} " )
640640endmacro ()
641+
642+ function (NBL_UPDATE_SUBMODULES)
643+ macro (NBL_WRAPPER_COMMAND GIT_RELATIVE_ENTRY GIT_SUBMODULE_PATH SHOULD_RECURSIVE)
644+ set (SHOULD_RECURSIVE ${SHOULD_RECURSIVE} )
645+
646+ if (SHOULD_RECURSIVE)
647+ string (APPEND _NBL_UPDATE_SUBMODULES_COMMANDS_ "\" ${GIT_EXECUTABLE} \" -C \" ${NBL_ROOT_PATH} /${GIT_RELATIVE_ENTRY} \" submodule update --init --recursive ${GIT_SUBMODULE_PATH} \n " )
648+ else ()
649+ string (APPEND _NBL_UPDATE_SUBMODULES_COMMANDS_ "\" ${GIT_EXECUTABLE} \" -C \" ${NBL_ROOT_PATH} /${GIT_RELATIVE_ENTRY} \" submodule update --init ${GIT_SUBMODULE_PATH} \n " )
650+ endif ()
651+ endmacro ()
652+
653+ if (NBL_UPDATE_GIT_SUBMODULE)
654+ execute_process (COMMAND ${CMAKE_COMMAND} -E echo "All submodules are about to get updated and initialized in repository because NBL_UPDATE_GIT_SUBMODULE is turned ON!" )
655+ set (_NBL_UPDATE_SUBMODULES_CMD_NAME_ "nbl-update-submodules" )
656+ set (_NBL_UPDATE_SUBMODULES_CMD_FILE_ "${NBL_ROOT_PATH_BINARY} /${_NBL_UPDATE_SUBMODULES_CMD_NAME_} .cmd" )
657+ message (STATUS "test" )
658+ if (NBL_UPDATE_GIT_SUBMODULE_INCLUDE_PRIVATE)
659+ NBL_WRAPPER_COMMAND("" "" TRUE )
660+ else ()
661+ NBL_WRAPPER_COMMAND("" ./3rdparty TRUE )
662+ #NBL_WRAPPER_COMMAND("" ./ci TRUE) TODO: enable it once we merge Ditt, etc
663+ NBL_WRAPPER_COMMAND("" ./examples_tests FALSE )
664+ NBL_WRAPPER_COMMAND(examples_tests ./media FALSE )
665+ endif ()
666+
667+ file (WRITE "${_NBL_UPDATE_SUBMODULES_CMD_FILE_} " "${_NBL_UPDATE_SUBMODULES_COMMANDS_} " )
668+
669+ if (WIN32 )
670+ find_package (GitBash REQUIRED)
671+
672+ execute_process (COMMAND "${GIT_BASH_EXECUTABLE} " "-c"
673+ [=[
674+ >&2 echo ""
675+ clear
676+ ./nbl-update-submodules.cmd 2>&1 | tee nbl-update-submodules.log
677+ sleep 1
678+ clear
679+ tput setaf 2; echo -e "Submodules have been updated!
680+ Created nbl-update-submodules.log in your build directory.
681+ This window will be closed in 5 seconds..."
682+ sleep 5
683+ ]=]
684+ WORKING_DIRECTORY ${NBL_ROOT_PATH_BINARY}
685+ OUTPUT_VARIABLE _NBL_TMP_OUTPUT_
686+ RESULT_VARIABLE _NBL_TMP_RET_CODE_
687+ OUTPUT_STRIP_TRAILING_WHITESPACE
688+ ERROR_STRIP_TRAILING_WHITESPACE
689+ )
690+
691+ unset (_NBL_TMP_OUTPUT_)
692+ unset (_NBL_TMP_RET_CODE_)
693+ else ()
694+ execute_process (COMMAND "${_NBL_UPDATE_SUBMODULES_CMD_FILE_} " )
695+ endif ()
696+ else ()
697+ execute_process (COMMAND ${CMAKE_COMMAND} -E echo "NBL_UPDATE_GIT_SUBMODULE is turned OFF therefore submodules won't get updated." )
698+ endif ()
699+ endfunction ()
0 commit comments