1# SPDX-License-Identifier: BSD-3-Clause 2 3find_package(Git) 4set(RIMAGE_CMAKE "${SOF_ROOT_SOURCE_DIRECTORY}/rimage/CMakeLists.txt") 5 6if(GIT_FOUND AND EXISTS "${SOF_ROOT_SOURCE_DIRECTORY}/.git") 7 8 if(EXISTS "${RIMAGE_CMAKE}") 9 10 # As incredible as it sounds, some people run neither 11 # "git status" nor "git diff" every few minutes and not 12 # even when their build fails. There has been reports 13 # that they're puzzled when they miss a required 14 # submodule update. This is an attempt to draw their 15 # attention based on the assumption that they pay more 16 # attention to the CMake logs. The warning can be 17 # silenced with I_KNOW_SUBMODULES, see below. 18 execute_process(COMMAND ${GIT_EXECUTABLE} submodule status --recursive 19 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 20 OUTPUT_VARIABLE stdout 21 RESULT_VARIABLE status) 22 23 if(NOT "${status}" EQUAL "0") 24 # stderr was passed-through 25 message(FATAL_ERROR 26"git submodule status --recursive failed, returned: ${status}\n${stdout}") 27 endif() 28 29 if(NOT "$ENV{I_KNOW_SUBMODULES}" AND 30 ("${stdout}" MATCHES "^[^ ]" OR "${stdout}" MATCHES "\n[^ ]")) 31 message(WARNING 32"There are submodule changes, check git status and git diff\n${stdout}") 33 endif() 34 35 else() 36 # Automated initialization for convenience. You can defeat it by 37 # manually initializing rimage and _not_ some other 38 # submodule. In that case you get the warning above. 39 40 # TODO: get rid of this CMake configuration time 41 # hack. Downloading, configuring and building should always be 42 # kept separate; that's CI 101. 43 44 message(STATUS "Git submodules update HACK") 45 execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --merge --recursive 46 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 47 RESULT_VARIABLE GIT_SUBMOD_RESULT) 48 49 if(NOT GIT_SUBMOD_RESULT EQUAL "0") 50 message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") 51 endif() 52 53 endif() # rimage/CMakeLists.txt 54 55endif() # .git/ 56