From 235305ba9ce958e8fefec477ad9636e5ac8b339c Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Tue, 12 Apr 2016 18:32:31 -0400 Subject: [PATCH] ENH: Update GenerateCLP tests to build/install its own GenerateCLP. See #44 This will ensure running the tests will not delete files associated with the current CMAKE_INSTALL_PREFIX. Co-authored-by: Nicole Aucoin --- .../Testing/CMake/GenerateCLP-Install.cmake | 57 +++++++++++++++++-- GenerateCLP/Testing/CMakeLists.txt | 20 ++++++- 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/GenerateCLP/Testing/CMake/GenerateCLP-Install.cmake b/GenerateCLP/Testing/CMake/GenerateCLP-Install.cmake index 00171de..4752ecd 100644 --- a/GenerateCLP/Testing/CMake/GenerateCLP-Install.cmake +++ b/GenerateCLP/Testing/CMake/GenerateCLP-Install.cmake @@ -2,7 +2,16 @@ # -------------------------------------------------------------------------- # Sanity checks -foreach(varname TEST_CMAKE_DIR TEST_BINARY_DIR TEST_INSTALL_DIR) +foreach(varname + CMAKE_BUILD_TYPE + CMAKE_GENERATOR + ModuleDescriptionParser_DIR + TCLAP_DIR + TEST_CMAKE_DIR + TEST_SOURCE_DIR + TEST_BINARY_DIR + TEST_INSTALL_DIR + ) if(NOT DEFINED ${varname}) message(FATAL_ERROR "Variable ${varname} is not DEFINED") endif() @@ -11,14 +20,16 @@ endforeach() include(${TEST_CMAKE_DIR}/GenerateCLPTestMacros.cmake) # -------------------------------------------------------------------------- -# Delete install directory if it exists +# Delete build and install directory if they exists execute_process( + COMMAND ${CMAKE_COMMAND} -E remove_directory ${TEST_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E remove_directory ${TEST_INSTALL_DIR} ) # -------------------------------------------------------------------------- -# Create install directory +# Create build and install directories execute_process( + COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_INSTALL_DIR} ) @@ -26,13 +37,51 @@ execute_process( # Debug flags - Set to True to display the command as string set(PRINT_COMMAND 0) +# -------------------------------------------------------------------------- +# Configure +set(command ${CMAKE_COMMAND} + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_PREFIX:PATH=${TEST_INSTALL_DIR} + -DModuleDescriptionParser_DIR:PATH=${ModuleDescriptionParser_DIR} + -DTCLAP_DIR:PATH=${TCLAP_DIR} + -G ${CMAKE_GENERATOR} ${TEST_SOURCE_DIR}) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${TEST_BINARY_DIR} + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +print_command_as_string("${command}") + +if(rv) + message(FATAL_ERROR "Failed to configure Test:\n${ov}") +endif() + +# -------------------------------------------------------------------------- +# Build + +set(command ${CMAKE_COMMAND} --build ${TEST_BINARY_DIR} --config ${CMAKE_BUILD_TYPE}) +execute_process( + COMMAND ${command} + WORKING_DIRECTORY ${TEST_BINARY_DIR} + OUTPUT_VARIABLE ov + RESULT_VARIABLE rv + ) + +print_command_as_string("${command}") + +if(rv) + message(FATAL_ERROR "Failed to build Test:\n${ov}") +endif() + # -------------------------------------------------------------------------- # Install set(install_target install) if(WIN32) set(install_target INSTALL) endif() -set(command ${CMAKE_COMMAND} --build ${TEST_BINARY_DIR} --config Release --target ${install_target}) +set(command ${CMAKE_COMMAND} --build ${TEST_BINARY_DIR} --config ${CMAKE_BUILD_TYPE} --target ${install_target}) execute_process( COMMAND ${command} WORKING_DIRECTORY ${TEST_BINARY_DIR} diff --git a/GenerateCLP/Testing/CMakeLists.txt b/GenerateCLP/Testing/CMakeLists.txt index 8fa5291..c804fc2 100644 --- a/GenerateCLP/Testing/CMakeLists.txt +++ b/GenerateCLP/Testing/CMakeLists.txt @@ -11,11 +11,25 @@ configure_file( # # Add test installing GenerateCLP # + +set(GenerateCLPTest_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/GenerateCLP-install) + +if(CMAKE_CONFIGURATION_TYPES) + set(_build_type ${CMAKE_CFG_INTDIR}) +else() + set(_build_type ${CMAKE_BUILD_TYPE}) +endif() add_test(NAME GenerateCLP-Install COMMAND ${CMAKE_COMMAND} + -DBUILD_TESTING:BOOL=OFF + -DCMAKE_BUILD_TYPE:STRING=${_build_type} + -DCMAKE_GENERATOR:STRING=${CMAKE_GENERATOR} + -DModuleDescriptionParser_DIR:PATH=${ModuleDescriptionParser_BINARY_DIR} + -DTCLAP_DIR:PATH=${TCLAP_BINARY_DIR} -DTEST_CMAKE_DIR:PATH=${GenerateCLP_SOURCE_DIR}/Testing/CMake - -DTEST_BINARY_DIR:PATH=${GenerateCLP_BINARY_DIR} - -DTEST_INSTALL_DIR:PATH=${CMAKE_INSTALL_PREFIX} + -DTEST_BINARY_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/GenerateCLP-build + -DTEST_INSTALL_DIR:PATH=${GenerateCLPTest_INSTALL_PREFIX} + -DTEST_SOURCE_DIR:PATH=${GenerateCLP_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/CMake/GenerateCLP-Install.cmake) set_property(TEST GenerateCLP-Install PROPERTY LABELS ${PROJECT_NAME}) @@ -35,7 +49,7 @@ macro(generateclp_add_test cliname stepname) ) if("${treetype}" STREQUAL "InstallTree" AND "${stepname}" STREQUAL "Configure") list(APPEND _test_args - -DGenerateCLP_DIR:PATH=${CMAKE_INSTALL_PREFIX}/lib/GenerateCLP/ + -DGenerateCLP_DIR:PATH=${GenerateCLPTest_INSTALL_PREFIX}/lib/GenerateCLP/ ) endif()