From adc59b9e7186100022c3f177cc9895872bde59a9 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Wed, 14 Oct 2015 11:05:51 -0400 Subject: [PATCH] cmake improve submodule handling --- Makefile | 23 ++---- Tools/check_submodules.sh | 144 ------------------------------------ cmake/common/px4_base.cmake | 13 ++-- 3 files changed, 14 insertions(+), 166 deletions(-) delete mode 100755 Tools/check_submodules.sh diff --git a/Makefile b/Makefile index 2b9a34553f..e2f1814f0c 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ endif # -------------------------------------------------------------------- # describe how to build a cmake config define cmake-build -+@if [ ! -e $(PWD)/build_$@/CMakeCache.txt ]; then mkdir -p $(PWD)/build_$@ && cd $(PWD)/build_$@ && cmake .. -G$(PX4_CMAKE_GENERATOR) -DCONFIG=$(1); fi ++@if [ ! -e $(PWD)/build_$@/CMakeCache.txt ]; then git submodule update --init --recursive --force && mkdir -p $(PWD)/build_$@ && cd $(PWD)/build_$@ && cmake .. -G$(PX4_CMAKE_GENERATOR) -DCONFIG=$(1); fi +$(PX4_MAKE) -C $(PWD)/build_$@ $(PX4_MAKE_ARGS) $(ARGS) endef @@ -104,13 +104,13 @@ endef # -------------------------------------------------------------------- # Do not put any spaces between function arguments. -px4fmu-v1_default: git-init +px4fmu-v1_default: $(call cmake-build,nuttx_px4fmu-v1_default) -px4fmu-v2_default: git-init +px4fmu-v2_default: $(call cmake-build,nuttx_px4fmu-v2_default) -px4fmu-v2_simple: git-init +px4fmu-v2_simple: $(call cmake-build,nuttx_px4fmu-v2_simple) nuttx_sim_simple: @@ -172,19 +172,8 @@ check_format: clean: @rm -rf build_*/ - -distclean: clean - @cd NuttX - @git clean -d -f -x - @cd .. - @cd src/modules/uavcan/libuavcan - @git clean -d -f -x - @cd ../../../.. - -# XXX this is not the right way to fix it, but we need a temporary solution -# for average joe -git-init: - @git submodule update --init --recursive + @(cd NuttX && git clean -d -f -x) + @(cd src/modules/uavcan/libuavcan && git clean -d -f -x) # targets handled by cmake cmake_targets = test upload package package_source debug debug_tui debug_ddd debug_io debug_io_tui debug_io_ddd check_weak libuavcan diff --git a/Tools/check_submodules.sh b/Tools/check_submodules.sh deleted file mode 100755 index 5fa0831438..0000000000 --- a/Tools/check_submodules.sh +++ /dev/null @@ -1,144 +0,0 @@ -#!/bin/sh - -[ -n "$GIT_SUBMODULES_ARE_EVIL" ] && { - # GIT_SUBMODULES_ARE_EVIL is set, meaning user doesn't want submodules - echo "Skipping submodules. NUTTX_SRC is set to $NUTTX_SRC" - exit 0 -} - -if [ -d NuttX/nuttx ]; - then - STATUSRETVAL=$(git submodule summary | grep -A20 -i "NuttX" | grep "<") - if [ -z "$STATUSRETVAL" ]; then - echo "Checked NuttX submodule, correct version found" - else - echo "" - echo "" - echo "New commits required:" - echo "$(git submodule summary)" - echo "" - echo "" - echo " NuttX sub repo not at correct version. Try 'git submodule update'" - echo " or follow instructions on http://pixhawk.org/dev/git/submodules" - echo "" - echo " DO NOT FORGET TO RUN 'make distclean && make archives' AFTER EACH NUTTX UPDATE!" - exit 1 - fi -else - git submodule update --init --recursive -fi - - -if [ -d mavlink/include/mavlink/v1.0 ]; - then - STATUSRETVAL=$(git submodule summary | grep -A20 -i "mavlink/include/mavlink/v1.0" | grep "<") - if [ -z "$STATUSRETVAL" ]; then - echo "Checked mavlink submodule, correct version found" - else - echo "" - echo "" - echo "New commits required:" - echo "$(git submodule summary)" - echo "" - echo "" - echo "mavlink sub repo not at correct version. Try 'git submodule update'" - echo "or follow instructions on http://pixhawk.org/dev/git/submodules" - exit 1 - fi -else - git submodule update --init --recursive -fi - - -if [ -d uavcan ] -then - STATUSRETVAL=$(git submodule summary | grep -A20 -i uavcan | grep "<") - if [ -z "$STATUSRETVAL" ] - then - echo "Checked uavcan submodule, correct version found" - else - echo "" - echo "" - echo "New commits required:" - echo "$(git submodule summary)" - echo "" - echo "" - echo "uavcan sub repo not at correct version. Try 'git submodule update'" - echo "or follow instructions on http://pixhawk.org/dev/git/submodules" - exit 1 - fi -else - git submodule update --init --recursive -fi - -if [ -d src/lib/eigen ] -then - echo "ARG = $1" - if [ $1 = "qurt" ] - then - # QuRT needs to use Eigen 3.2 because the toolchain doews not support C++11 - STATUSRETVAL=$(true) - else - STATUSRETVAL=$(git submodule summary | grep -A20 -i eigen | grep "<") - if [ -z "$STATUSRETVAL" ] - then - echo "Checked Eigen submodule, correct version found" - else - echo "" - echo "" - echo "New commits required:" - echo "$(git submodule summary)" - echo "" - echo "" - echo "eigen sub repo not at correct version. Try 'git submodule update'" - echo "or follow instructions on http://pixhawk.org/dev/git/submodules" - exit 1 - fi - fi -else - git submodule update --init --recursive -fi - -if [ -d Tools/gencpp ] -then - STATUSRETVAL=$(git submodule summary | grep -A20 -i gencpp | grep "<") - if [ -z "$STATUSRETVAL" ] - then - echo "Checked gencpp submodule, correct version found" - else - echo "" - echo "" - echo "New commits required:" - echo "$(git submodule summary)" - echo "" - echo "" - echo "gencpp sub repo not at correct version. Try 'git submodule update'" - echo "or follow instructions on http://pixhawk.org/dev/git/submodules" - exit 1 - fi -else - git submodule update --init --recursive -fi - -if [ -d Tools/genmsg ] -then - STATUSRETVAL=$(git submodule summary | grep -A20 -i genmsg | grep "<") - if [ -z "$STATUSRETVAL" ] - then - echo "Checked genmsg submodule, correct version found" - else - echo "" - echo "" - echo "New commits required:" - echo "$(git submodule summary)" - echo "" - echo "" - echo "genmsg sub repo not at correct version. Try 'git submodule update'" - echo "or follow instructions on http://pixhawk.org/dev/git/submodules" - exit 1 - fi -else - git submodule update --init --recursive -fi - -exit 0 diff --git a/cmake/common/px4_base.cmake b/cmake/common/px4_base.cmake index 6853b4f161..086f77070f 100644 --- a/cmake/common/px4_base.cmake +++ b/cmake/common/px4_base.cmake @@ -136,14 +136,17 @@ function(px4_add_git_submodule) REQUIRED TARGET PATH ARGN ${ARGN}) string(REPLACE "/" "_" NAME ${PATH}) - add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git_${NAME}.stamp + add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git_init_${NAME}.stamp WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - COMMAND git submodule update --init --recursive -f ${PATH} - COMMAND touch ${CMAKE_BINARY_DIR}/git_${NAME}.stamp + COMMAND git submodule init ${PATH} + COMMAND touch ${CMAKE_BINARY_DIR}/git_init_${NAME}.stamp + DEPENDS ${CMAKE_SOURCE_DIR}/.gitmodules ) add_custom_target(${TARGET} - DEPENDS git_${NAME}.stamp - ) + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND git submodule update --recursive ${PATH} + DEPENDS ${CMAKE_BINARY_DIR}/git_init_${NAME}.stamp + ) endfunction() #=============================================================================