Skip to content

Commit

Permalink
ENH: Update GenerateCLP tests to build/install its own GenerateCLP. See
Browse files Browse the repository at this point in the history
#44

This will ensure running the tests will not delete files associated
with the current CMAKE_INSTALL_PREFIX.

Co-authored-by: Nicole Aucoin <nicole@bwh.harvard.edu>
  • Loading branch information
jcfr and Nicole Aucoin committed Apr 12, 2016
1 parent fccd779 commit 235305b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 7 deletions.
57 changes: 53 additions & 4 deletions GenerateCLP/Testing/CMake/GenerateCLP-Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -11,28 +20,68 @@ 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}
)

# --------------------------------------------------------------------------
# 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}
Expand Down
20 changes: 17 additions & 3 deletions GenerateCLP/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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()

Expand Down

0 comments on commit 235305b

Please sign in to comment.