From cb8bef942386bae77bde8d72e4db21cfdafd3aff Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 20 Jan 2017 10:16:48 +0100 Subject: [PATCH] Force rebuild of Netgen subproject when building the Superbuild CMake is using stamp files to check if the external projects are out of date. There is an option 'BUILD_ALWAYS 1' of ExternalProject_Add, but it is not available prior to CMake 3.1. To work around it, this commit solves two problems at once: - Add a new step 'check_submodules' between configure and build to check if all submodules are up to date. This step has the option 'ALWAYS 1', which means it is always considered outdated. - Since 'build' depends on the above step, it will always be started --- cmake_modules/SuperBuild.cmake | 18 ++++++++++++++++++ cmake_modules/check_submodules.cmake | 13 +++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 cmake_modules/check_submodules.cmake diff --git a/cmake_modules/SuperBuild.cmake b/cmake_modules/SuperBuild.cmake index 1d753cc3..fbecd086 100644 --- a/cmake_modules/SuperBuild.cmake +++ b/cmake_modules/SuperBuild.cmake @@ -79,6 +79,7 @@ endif(NOT WIN32) if (USE_PYTHON) find_path(PYBIND_INCLUDE_DIR pybind11/pybind11.h PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies/pybind11/include NO_DEFAULT_PATH) if( NOT PYBIND_INCLUDE_DIR ) + # if the pybind submodule is missing, try to initialize and update all submodules execute_process(COMMAND git submodule update --init --recursive WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) find_path(PYBIND_INCLUDE_DIR pybind11/pybind11.h ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies/pybind11/include) endif( NOT PYBIND_INCLUDE_DIR ) @@ -151,6 +152,23 @@ ExternalProject_Add (netgen STEP_TARGETS build ) +# Check if the git submodules (i.e. pybind11) are up to date +# in case, something is wrong, emit a warning but continue + ExternalProject_Add_Step(netgen check_submodules + COMMAND cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/check_submodules.cmake + DEPENDERS install # Steps on which this step depends + ) + +# Due to 'ALWAYS 1', this step is always run which also forces a build of +# the Netgen subproject + ExternalProject_Add_Step(netgen check_submodules1 + COMMAND cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/check_submodules.cmake + DEPENDEES configure # Steps on which this step depends + DEPENDERS build # Steps that depend on this step + ALWAYS 1 # No stamp file, step always runs + ) + + install(CODE "execute_process(COMMAND cmake --build . --target install --config ${CMAKE_BUILD_TYPE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/netgen)") add_custom_target(test_netgen diff --git a/cmake_modules/check_submodules.cmake b/cmake_modules/check_submodules.cmake new file mode 100644 index 00000000..f49923fa --- /dev/null +++ b/cmake_modules/check_submodules.cmake @@ -0,0 +1,13 @@ +execute_process(COMMAND git submodule status --recursive WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../" OUTPUT_VARIABLE git_status_output) +string(REPLACE "\n" ";" git_status_output "${git_status_output}") +foreach( a ${git_status_output}) + if(NOT ${a} MATCHES " [a-f,0-9]* external_dependencies[.]*") + message(WARNING +"***************************************************************** + WARNING: The git submodules are out of sync! Please run + git submodule update --init --recursive + in your source directory +*****************************************************************") + endif() +endforeach() +