4 message(WARNING "Git executable was not found. Git submodule checks will not be executed. "
5 "If you have any build issues at all, start by adding git executable to the PATH and "
6 "rerun cmake to not see this warning again.")
8 function(git_submodule_check root_path)
13 function(git_submodule_check root_path)
16 COMMAND ${GIT_EXECUTABLE} submodule status
17 WORKING_DIRECTORY ${root_path}
18 OUTPUT_VARIABLE submodule_status
21 # git submodule status output not guaranteed to be stable,
22 # may need to check GIT_VERSION_STRING and do some fiddling in the
25 lines2list(submodule_status)
27 foreach(line ${submodule_status})
28 string(REGEX MATCH "(.)[0-9a-f]+ ([^\( ]+) ?" _ignored "${line}")
29 set(status "${CMAKE_MATCH_1}")
30 set(submodule_path "${CMAKE_MATCH_2}")
32 if("${status}" STREQUAL "-") # missing submodule
33 message(STATUS "Initialising new submodule ${submodule_path}...")
35 COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive ${submodule_path}
36 WORKING_DIRECTORY ${root_path}
37 RESULT_VARIABLE git_result
40 message(FATAL_ERROR "Git submodule init failed for ${submodule_path}")
43 elseif(NOT "${status}" STREQUAL " ")
44 message(WARNING "Git submodule ${submodule_path} is out of date. "
45 "Run 'git submodule update --init --recursive' to fix.")
48 # Force a re-run of cmake if the submodule's .git file changes or is changed (ie accidental deinit)
49 get_filename_component(submodule_abs_path ${submodule_path} ABSOLUTE BASE_DIR ${root_path})
50 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${submodule_abs_path}/.git)
51 # same if the HEAD file in the submodule's directory changes (ie commit changes).
52 # This will at least print the 'out of date' warning
53 set(submodule_head "${root_path}/.git/modules/${submodule_path}/HEAD")
54 if(EXISTS "${submodule_head}")
55 set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${submodule_head})