]> granicus.if.org Git - esp-idf/commitdiff
cmake: Detect missing or out of date submodules during cmake pass
authorAngus Gratton <angus@espressif.com>
Mon, 15 Jan 2018 02:20:38 +0000 (13:20 +1100)
committerAngus Gratton <gus@projectgus.com>
Sun, 29 Apr 2018 23:59:20 +0000 (09:59 +1000)
components/aws_iot/CMakeLists.txt
components/coap/CMakeLists.txt
components/libsodium/CMakeLists.txt
components/micro-ecc/CMakeLists.txt
components/nghttp/CMakeLists.txt
components/spiffs/CMakeLists.txt
idf.cmake
tools/cmake/git_submodules.cmake [new file with mode: 0644]
tools/cmake/utilities.cmake

index 29909bd1407cb6147fb9382969c2dbb80dcca0be..50219ab090d1bc33a4fc1bf2e57a2373fac99b7a 100644 (file)
@@ -2,7 +2,6 @@ if(CONFIG_AWS_IOT_SDK)
 
 set(COMPONENT_ADD_INCLUDEDIRS "include aws-iot-device-sdk-embedded-C/include")
 set(COMPONENT_SRCDIRS "aws-iot-device-sdk-embedded-C/src port")
-set(COMPONENT_SUBMODULES aws-iot-device-sdk-embedded-C)
 
 register_component()
 
index 9a9b65ccbb9549c509f1f24dd6c26f3c33368a46..2f51d6c0a2f2442d8a66978ea16edf8fef2d5069 100644 (file)
@@ -19,8 +19,6 @@ set(COMPONENT_SRCS
   port/coap_io_socket.c
   )
 
-set(COMPONENT_SUBMODULES libcoap)
-
 register_component()
 
 # Needed for coap headers in public builds, also.
index 78ab23c6465f7b9275785f9dd49ac0475105ec66..f4502508457d55ed54352f927747e64cf5f99699 100644 (file)
@@ -1,7 +1,5 @@
 set(SRC libsodium/src/libsodium)
 
-set(COMPONENT_SUBMODULES libsodium)
-
 set(COMPONENT_SRCDIRS
   port
 
index 6ae9c8ae3983776483caf21b89c6e90308847245..13bc9cfb64946c37b841db87ace334197397f0bb 100644 (file)
@@ -3,6 +3,4 @@ set(COMPONENT_SRCS micro-ecc/uECC.c)
 
 set(COMPONENT_ADD_INCLUDEDIRS micro-ecc)
 
-set(COMPONENT_SUBMODULES micro-ecc)
-
 register_component()
index 1a549b075118ce98efa1fd098cb23648a89b729e..c7e4b754b87f7f89795a9868e6e10c51fb4884f4 100644 (file)
@@ -1,5 +1,4 @@
 set(COMPONENT_ADD_INCLUDEDIRS port/include nghttp2/lib/includes)
 set(COMPONENT_SRCDIRS nghttp2/lib port)
-set(COMPONENT_SUBMODULES nghttp2)
 
 register_component()
index 0435a38b6942502d51dbfdbac7b8a69915105bb5..5e0027f52da90bb1fc2e03fb78e0adcf9bf91777 100644 (file)
@@ -1,6 +1,5 @@
 set(COMPONENT_ADD_INCLUDEDIRS "include")
 set(COMPONENT_PRIV_INCLUDEDIRS "spiffs/src")
 set(COMPONENT_SRCDIRS ". spiffs/src")
-set(COMPONENT_SUBMODULES "spiffs")
 register_component()
 
index d1623f2757460ed2cffe0a4aed94b83c3b18711a..800f32a0fc3881d93ca625bb812c6ebc3bd0ffb4 100644 (file)
--- a/idf.cmake
+++ b/idf.cmake
@@ -33,6 +33,7 @@ include(utilities)
 include(components)
 include(kconfig)
 include(crosstool_version_check)
+include(git_submodules)
 
 #
 # Warn if the toolchain version doesn't match
@@ -50,8 +51,8 @@ set_default(EXTRA_COMPONENT_DIRS "")
 set_default(COMPONENT_DIRS "${PROJECT_PATH}/components ${EXTRA_COMPONENT_DIRS} ${IDF_PATH}/components")
 spaces2list(COMPONENT_DIRS)
 
-# expand COMPONENT_DIRS variable into full paths to all components and their names
 spaces2list(COMPONENTS)
+# Search COMPONENT_DIRS for COMPONENTS, make a list of full paths to each component in COMPONENT_PATHS
 find_all_components("${COMPONENT_DIRS}" "${COMPONENTS}" COMPONENT_PATHS COMPONENTS)
 build_component_config()
 
@@ -66,6 +67,7 @@ add_definitions(-DHAVE_CONFIG_H)
 
 git_describe(GIT_REVISION)
 add_definitions(-DIDF_VER=\"${GIT_REVISION}\")
+git_submodule_check("${IDF_PATH}")
 
 add_compile_options("-I${CMAKE_BINARY_DIR}") # for sdkconfig.h
 
diff --git a/tools/cmake/git_submodules.cmake b/tools/cmake/git_submodules.cmake
new file mode 100644 (file)
index 0000000..be71f41
--- /dev/null
@@ -0,0 +1,51 @@
+find_package(Git)
+
+if(NOT GIT_FOUND)
+  message(WARNING "Git executable was not found. Git submodule checks will not be executed. If you have any build issues at all, start by adding git executable to the PATH and rerun cmake to not see this warning again.")
+
+  function(git_submodule_check root_path)
+    # no-op
+  endfunction()
+else(NOT GIT_FOUND)
+
+  function(git_submodule_check root_path)
+
+    execute_process(
+      COMMAND ${GIT_EXECUTABLE} submodule status
+      WORKING_DIRECTORY ${root_path}
+      OUTPUT_VARIABLE submodule_status
+      )
+
+    # git submodule status output not guaranteed to be stable,
+    # may need to check GIT_VERSION_STRING and do some fiddling in the
+    # future...
+
+    lines2list(submodule_status)
+
+    foreach(line ${submodule_status})
+      string(REGEX MATCH "(.)[0-9a-f]+ ([^\( ]+) ?" _ignored "${line}")
+      set(status "${CMAKE_MATCH_1}")
+      set(submodule_path "${CMAKE_MATCH_2}")
+
+      if("${status}" STREQUAL "-")  # missing submodule
+        message(STATUS "Initialising new submodule ${submodule_path}...")
+        execute_process(
+          COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive ${submodule_path}
+          WORKING_DIRECTORY ${root_path}
+          RESULT_VARIABLE git_result
+          )
+        if(git_result)
+          message(FATAL_ERROR "Git submodule init failed for ${submodule_path}")
+        endif(git_result)
+
+      elseif(NOT "${status}" STREQUAL " ")
+        message(WARNING "Git submodule ${submodule_path} is out of date. Run 'git submodule update --init --recursive' to fix.")
+      endif()
+    endforeach()
+  endfunction(git_submodule_check)
+
+endif(NOT GIT_FOUND)
+
+
+
+
index 29eb78aad09c1a004ca521488565dae0c8508ba1..962d46c25a4836601853f3f0e5cb5096ac8b757e 100644 (file)
@@ -24,11 +24,25 @@ endfunction()
 #
 # Note: if using this for directories, keeps the issue in place that
 # directories can't contain spaces...
+#
+# TODO: look at cmake separate_arguments, which is quote-aware
 function(spaces2list variable_name)
   string(REPLACE " " ";" tmp "${${variable_name}}")
   set("${variable_name}" "${tmp}" PARENT_SCOPE)
 endfunction()
 
+
+# lines2list
+#
+# Take a variable with multiple lines of output in it, convert it
+# to a cmake list (semicolon-delimited), one line per item
+#
+function(lines2list variable_name)
+  string(REGEX REPLACE "\r?\n" ";" tmp "${${variable_name}}")
+  set("${variable_name}" "${tmp}" PARENT_SCOPE)
+endfunction()
+
+
 # move_if_different
 #
 # If 'source' has different md5sum to 'destination' (or destination