# This file initializes the required submodules
SET(OGS_ADDITIONAL_SUBMODULES_TO_CHECKOUT "" CACHE STRING
	"User given submodules which should be checked out by CMake.")
IF(NOT OGS_ADDITIONAL_SUBMODULES_TO_CHECKOUT)
	SET(OGS_ADDITIONAL_SUBMODULES_TO_CHECKOUT "")
ENDIF()
SET(REQUIRED_SUBMODULES
	ThirdParty/quickcheck
	${OGS_ADDITIONAL_SUBMODULES_TO_CHECKOUT}
)

FOREACH(SUBMODULE ${REQUIRED_SUBMODULES})
	IF(WIN32)
		SET(SUBMODULE_STATE 1)
	ELSE()
		# Check if submodule is already initialized
		EXECUTE_PROCESS(
			COMMAND ${BASH_TOOL_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/SubmoduleCheck.sh ${SUBMODULE}
			WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
			RESULT_VARIABLE SUBMODULE_STATE
		)
	ENDIF()

	IF(SUBMODULE_STATE EQUAL 1)
		MESSAGE(STATUS "Initializing submodule ${SUBMODULE}")
		EXECUTE_PROCESS(
			COMMAND ${GIT_TOOL_PATH} submodule update --init ${SUBMODULE}
			WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
		)
	ELSEIF(SUBMODULE_STATE EQUAL 2)
		MESSAGE(STATUS "Updating submodule ${SUBMODULE}")
		EXECUTE_PROCESS(
			COMMAND git submodule update ${SUBMODULE}
			WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
		)
	ENDIF()
ENDFOREACH()