Skip to content

Commit 235305b

Browse files
jcfrNicole Aucoin
and
Nicole Aucoin
committed
ENH: Update GenerateCLP tests to build/install its own GenerateCLP. See Slicer#44
This will ensure running the tests will not delete files associated with the current CMAKE_INSTALL_PREFIX. Co-authored-by: Nicole Aucoin <[email protected]>
1 parent fccd779 commit 235305b

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed

GenerateCLP/Testing/CMake/GenerateCLP-Install.cmake

+53-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
# --------------------------------------------------------------------------
33
# Sanity checks
44

5-
foreach(varname TEST_CMAKE_DIR TEST_BINARY_DIR TEST_INSTALL_DIR)
5+
foreach(varname
6+
CMAKE_BUILD_TYPE
7+
CMAKE_GENERATOR
8+
ModuleDescriptionParser_DIR
9+
TCLAP_DIR
10+
TEST_CMAKE_DIR
11+
TEST_SOURCE_DIR
12+
TEST_BINARY_DIR
13+
TEST_INSTALL_DIR
14+
)
615
if(NOT DEFINED ${varname})
716
message(FATAL_ERROR "Variable ${varname} is not DEFINED")
817
endif()
@@ -11,28 +20,68 @@ endforeach()
1120
include(${TEST_CMAKE_DIR}/GenerateCLPTestMacros.cmake)
1221

1322
# --------------------------------------------------------------------------
14-
# Delete install directory if it exists
23+
# Delete build and install directory if they exists
1524
execute_process(
25+
COMMAND ${CMAKE_COMMAND} -E remove_directory ${TEST_BINARY_DIR}
1626
COMMAND ${CMAKE_COMMAND} -E remove_directory ${TEST_INSTALL_DIR}
1727
)
1828

1929
# --------------------------------------------------------------------------
20-
# Create install directory
30+
# Create build and install directories
2131
execute_process(
32+
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_BINARY_DIR}
2233
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_INSTALL_DIR}
2334
)
2435

2536
# --------------------------------------------------------------------------
2637
# Debug flags - Set to True to display the command as string
2738
set(PRINT_COMMAND 0)
2839

40+
# --------------------------------------------------------------------------
41+
# Configure
42+
set(command ${CMAKE_COMMAND}
43+
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
44+
-DCMAKE_INSTALL_PREFIX:PATH=${TEST_INSTALL_DIR}
45+
-DModuleDescriptionParser_DIR:PATH=${ModuleDescriptionParser_DIR}
46+
-DTCLAP_DIR:PATH=${TCLAP_DIR}
47+
-G ${CMAKE_GENERATOR} ${TEST_SOURCE_DIR})
48+
execute_process(
49+
COMMAND ${command}
50+
WORKING_DIRECTORY ${TEST_BINARY_DIR}
51+
OUTPUT_VARIABLE ov
52+
RESULT_VARIABLE rv
53+
)
54+
55+
print_command_as_string("${command}")
56+
57+
if(rv)
58+
message(FATAL_ERROR "Failed to configure Test:\n${ov}")
59+
endif()
60+
61+
# --------------------------------------------------------------------------
62+
# Build
63+
64+
set(command ${CMAKE_COMMAND} --build ${TEST_BINARY_DIR} --config ${CMAKE_BUILD_TYPE})
65+
execute_process(
66+
COMMAND ${command}
67+
WORKING_DIRECTORY ${TEST_BINARY_DIR}
68+
OUTPUT_VARIABLE ov
69+
RESULT_VARIABLE rv
70+
)
71+
72+
print_command_as_string("${command}")
73+
74+
if(rv)
75+
message(FATAL_ERROR "Failed to build Test:\n${ov}")
76+
endif()
77+
2978
# --------------------------------------------------------------------------
3079
# Install
3180
set(install_target install)
3281
if(WIN32)
3382
set(install_target INSTALL)
3483
endif()
35-
set(command ${CMAKE_COMMAND} --build ${TEST_BINARY_DIR} --config Release --target ${install_target})
84+
set(command ${CMAKE_COMMAND} --build ${TEST_BINARY_DIR} --config ${CMAKE_BUILD_TYPE} --target ${install_target})
3685
execute_process(
3786
COMMAND ${command}
3887
WORKING_DIRECTORY ${TEST_BINARY_DIR}

GenerateCLP/Testing/CMakeLists.txt

+17-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,25 @@ configure_file(
1111
#
1212
# Add test installing GenerateCLP
1313
#
14+
15+
set(GenerateCLPTest_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/GenerateCLP-install)
16+
17+
if(CMAKE_CONFIGURATION_TYPES)
18+
set(_build_type ${CMAKE_CFG_INTDIR})
19+
else()
20+
set(_build_type ${CMAKE_BUILD_TYPE})
21+
endif()
1422
add_test(NAME GenerateCLP-Install
1523
COMMAND ${CMAKE_COMMAND}
24+
-DBUILD_TESTING:BOOL=OFF
25+
-DCMAKE_BUILD_TYPE:STRING=${_build_type}
26+
-DCMAKE_GENERATOR:STRING=${CMAKE_GENERATOR}
27+
-DModuleDescriptionParser_DIR:PATH=${ModuleDescriptionParser_BINARY_DIR}
28+
-DTCLAP_DIR:PATH=${TCLAP_BINARY_DIR}
1629
-DTEST_CMAKE_DIR:PATH=${GenerateCLP_SOURCE_DIR}/Testing/CMake
17-
-DTEST_BINARY_DIR:PATH=${GenerateCLP_BINARY_DIR}
18-
-DTEST_INSTALL_DIR:PATH=${CMAKE_INSTALL_PREFIX}
30+
-DTEST_BINARY_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/GenerateCLP-build
31+
-DTEST_INSTALL_DIR:PATH=${GenerateCLPTest_INSTALL_PREFIX}
32+
-DTEST_SOURCE_DIR:PATH=${GenerateCLP_SOURCE_DIR}
1933
-P ${CMAKE_CURRENT_SOURCE_DIR}/CMake/GenerateCLP-Install.cmake)
2034
set_property(TEST GenerateCLP-Install PROPERTY LABELS ${PROJECT_NAME})
2135

@@ -35,7 +49,7 @@ macro(generateclp_add_test cliname stepname)
3549
)
3650
if("${treetype}" STREQUAL "InstallTree" AND "${stepname}" STREQUAL "Configure")
3751
list(APPEND _test_args
38-
-DGenerateCLP_DIR:PATH=${CMAKE_INSTALL_PREFIX}/lib/GenerateCLP/
52+
-DGenerateCLP_DIR:PATH=${GenerateCLPTest_INSTALL_PREFIX}/lib/GenerateCLP/
3953
)
4054
endif()
4155

0 commit comments

Comments
 (0)