]> granicus.if.org Git - esp-idf/blob - tools/cmake/git_submodules.cmake
Merge branch 'bugfix/tcpip_stack_size_default' into 'master'
[esp-idf] / tools / cmake / git_submodules.cmake
1 find_package(Git)
2
3 if(NOT GIT_FOUND)
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.")
7
8     function(git_submodule_check root_path)
9         # no-op
10     endfunction()
11 else()
12
13     function(git_submodule_check root_path)
14
15         execute_process(
16             COMMAND ${GIT_EXECUTABLE} submodule status
17             WORKING_DIRECTORY ${root_path}
18             OUTPUT_VARIABLE submodule_status
19             )
20
21         # git submodule status output not guaranteed to be stable,
22         # may need to check GIT_VERSION_STRING and do some fiddling in the
23         # future...
24
25         lines2list(submodule_status)
26
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}")
31
32             if("${status}" STREQUAL "-")  # missing submodule
33                 message(STATUS "Initialising new submodule ${submodule_path}...")
34                 execute_process(
35                     COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive ${submodule_path}
36                     WORKING_DIRECTORY ${root_path}
37                     RESULT_VARIABLE git_result
38                     )
39                 if(git_result)
40                     message(FATAL_ERROR "Git submodule init failed for ${submodule_path}")
41                 endif()
42
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.")
46             endif()
47
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})
56             endif()
57
58         endforeach()
59     endfunction()
60
61 endif()