From 912b9603b98bb3cf55cbe981b5149a532a585b5f Mon Sep 17 00:00:00 2001 From: Ramtin Gharleghi Date: Sat, 22 Jan 2022 12:50:11 +1100 Subject: [PATCH] Add CMake option to not treat test data as a repository --- CMakeLists.txt | 5 ++++- tests/CMakeLists.txt | 38 +++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index deacc7a77..7e95a9152 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,8 +85,11 @@ endif() option( VMTK_USE_SUPERBUILD "Build VMTK and the projects it depends on via SuperBuild.cmake." ON ) +option( VMTK_TEST_SUBMODULE + "Check and update VMTK Test data repository" ON ) + # Git setup -if (VMTK_USE_SUPERBUILD OR VMTK_BUILD_TESTING) +if (VMTK_USE_SUPERBUILD OR VMTK_TEST_SUBMODULE) if( NOT GIT_EXECUTABLE ) find_package( Git REQUIRED ) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index aa099a9ce..553ff2f90 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,26 +12,30 @@ foreach (SCRIPT_FILE ${VMTK_TESTING_INIT_SRC}) configure_file(${VMTK_TESTING_SOURCE_DIR}/${SCRIPT_FILE} ${VMTK_TESTING_INSTALL_LIB_DIR}/${SCRIPT_FILE} COPYONLY) endforeach () -# Check if submodule is clean -execute_process( - COMMAND ${GIT_EXECUTABLE} status --porcelain ${VMTK_TESTING_SOURCE_DIR}/vmtk-test-data - WORKING_DIRECTORY ${VMTK_TESTING_SOURCE_DIR} - RESULT_VARIABLE error_code - OUTPUT_VARIABLE repo_status -) -if(error_code) - message(FATAL_ERROR "Failed to get the status") +if (VMTK_TEST_SUBMODULE) + # Check if submodule is clean + execute_process( + COMMAND ${GIT_EXECUTABLE} status --porcelain ${VMTK_TESTING_SOURCE_DIR}/vmtk-test-data + WORKING_DIRECTORY ${VMTK_TESTING_SOURCE_DIR} + RESULT_VARIABLE error_code + OUTPUT_VARIABLE repo_status + ) + if(error_code) + message(FATAL_ERROR "Failed to get the status") + endif() + + string(LENGTH "${repo_status}" unclean_status) + + # If not in clean state do not overwrite + if(unclean_status) + message(WARNING "Test data repo in unclean state, will not overwrite test data") + else() + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init -- ${VMTK_TESTING_SOURCE_DIR}/vmtk-test-data + WORKING_DIRECTORY ${VMTK_TESTING_SOURCE_DIR}) + endif() endif() -string(LENGTH "${repo_status}" unclean_status) -# If not in clean state do not overwrite -if(unclean_status) - message(WARNING "Test data repo in unclean state, will not overwrite test data") -else() - execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init -- ${VMTK_TESTING_SOURCE_DIR}/vmtk-test-data - WORKING_DIRECTORY ${VMTK_TESTING_SOURCE_DIR}) -endif() if(NOT VMTK_TESTING_DATA_INSTALL_LIB_DIR) set(VMTK_TESTING_DATA_INSTALL_LIB_DIR ${CMAKE_BINARY_DIR}/tests)