Skip to content
This repository was archived by the owner on Sep 28, 2021. It is now read-only.

Commit 225ea20

Browse files
committed
cmake: add install/uninstall and simple test
1 parent 123d285 commit 225ea20

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,25 @@ project(xtp-tutorials)
44

55
set(PROJECT_VERSION "1.7-dev")
66

7+
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules)
8+
include(GNUInstallDirs)
9+
10+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${CMAKE_INSTALL_DATADIR}/votca/xtp-tutorials
11+
PATTERN ".git*" EXCLUDE
12+
PATTERN "CMake*" EXCLUDE PATTERN "cmake_install.cmake" EXCLUDE
13+
PATTERN "install_manifest.txt" EXCLUDE PATTERN "*~" EXCLUDE)
14+
15+
configure_file(${CMAKE_MODULE_PATH}/cmake_uninstall.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY)
16+
option(ENABLE_TESTING "Test if cmake worked" OFF)
17+
if(ENABLE_TESTING)
18+
enable_testing()
19+
add_test(regression_xtp-tutorial_UninstallExists ${CMAKE_COMMAND} -DFileToCheck=${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
20+
-P ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/FileExists.cmake)
21+
22+
set_tests_properties(regression_xtp-tutorial_UninstallExists PROPERTIES LABELS "xtp-tutorials")
23+
endif(ENABLE_TESTING)
24+
add_custom_target(uninstall-xtp-tutorials COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
25+
if(NOT TARGET uninstall)
26+
add_custom_target(uninstall)
27+
endif()
28+
add_dependencies(uninstall uninstall-xtp-tutorials)

CMakeModules/FileExists.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if(EXISTS ${FileToCheck})
2+
message("${FileToCheck} exists.")
3+
else()
4+
message(FATAL_ERROR "${FileToCheck} doesn't exist.")
5+
endif()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
2+
MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
3+
ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
4+
5+
FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
6+
STRING(REGEX REPLACE "\n" ";" files "${files}")
7+
FOREACH(file ${files})
8+
MESSAGE(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
9+
IF(EXISTS "$ENV{DESTDIR}${file}")
10+
EXEC_PROGRAM(
11+
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
12+
OUTPUT_VARIABLE rm_out
13+
RETURN_VALUE rm_retval
14+
)
15+
IF(NOT "${rm_retval}" STREQUAL 0)
16+
MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
17+
ENDIF(NOT "${rm_retval}" STREQUAL 0)
18+
ELSE(EXISTS "$ENV{DESTDIR}${file}")
19+
MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
20+
ENDIF(EXISTS "$ENV{DESTDIR}${file}")
21+
ENDFOREACH(file)
22+

0 commit comments

Comments
 (0)