diff --git a/components/aws_iot/CMakeLists.txt b/components/aws_iot/CMakeLists.txt index 29909bd140..50219ab090 100644 --- a/components/aws_iot/CMakeLists.txt +++ b/components/aws_iot/CMakeLists.txt @@ -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() diff --git a/components/coap/CMakeLists.txt b/components/coap/CMakeLists.txt index 9a9b65ccbb..2f51d6c0a2 100644 --- a/components/coap/CMakeLists.txt +++ b/components/coap/CMakeLists.txt @@ -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. diff --git a/components/libsodium/CMakeLists.txt b/components/libsodium/CMakeLists.txt index 78ab23c646..f450250845 100644 --- a/components/libsodium/CMakeLists.txt +++ b/components/libsodium/CMakeLists.txt @@ -1,7 +1,5 @@ set(SRC libsodium/src/libsodium) -set(COMPONENT_SUBMODULES libsodium) - set(COMPONENT_SRCDIRS port diff --git a/components/micro-ecc/CMakeLists.txt b/components/micro-ecc/CMakeLists.txt index 6ae9c8ae39..13bc9cfb64 100644 --- a/components/micro-ecc/CMakeLists.txt +++ b/components/micro-ecc/CMakeLists.txt @@ -3,6 +3,4 @@ set(COMPONENT_SRCS micro-ecc/uECC.c) set(COMPONENT_ADD_INCLUDEDIRS micro-ecc) -set(COMPONENT_SUBMODULES micro-ecc) - register_component() diff --git a/components/nghttp/CMakeLists.txt b/components/nghttp/CMakeLists.txt index 1a549b0751..c7e4b754b8 100644 --- a/components/nghttp/CMakeLists.txt +++ b/components/nghttp/CMakeLists.txt @@ -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() diff --git a/components/spiffs/CMakeLists.txt b/components/spiffs/CMakeLists.txt index 0435a38b69..5e0027f52d 100644 --- a/components/spiffs/CMakeLists.txt +++ b/components/spiffs/CMakeLists.txt @@ -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() diff --git a/idf.cmake b/idf.cmake index d1623f2757..800f32a0fc 100644 --- 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 index 0000000000..be71f41f6c --- /dev/null +++ b/tools/cmake/git_submodules.cmake @@ -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) + + + + diff --git a/tools/cmake/utilities.cmake b/tools/cmake/utilities.cmake index 29eb78aad0..962d46c25a 100644 --- a/tools/cmake/utilities.cmake +++ b/tools/cmake/utilities.cmake @@ -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