Skip to content

Commit 23791db

Browse files
committed
CMakeLists.txt updates, includling "uninstall" target.
1 parent 3831dca commit 23791db

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

CMakeLists.txt

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ SET(BUILD_VERSION ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_PATCH})
3737

3838

3939
#############################################################################
40-
# INSTALLATION_DIRECTORIES
40+
#### INSTALLATION_DIRECTORIES ####
4141
#############################################################################
4242

4343
# See: https://cmake.org/cmake/help/v3.0/module/GNUInstallDirs.html
4444
INCLUDE(GNUInstallDirs)
4545

4646

4747
#############################################################################
48-
# PACKAGING
48+
#### PACKAGING ####
4949
#############################################################################
5050

5151
SET(CPACK_SOURCE_GENERATOR "TXZ")
@@ -69,7 +69,22 @@ INCLUDE(CheckStructHasMember)
6969

7070

7171
#############################################################################
72-
# OS DEPENDENT
72+
#### UNINSTALL ####
73+
#############################################################################
74+
75+
IF(NOT TARGET uninstall)
76+
CONFIGURE_FILE(
77+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
78+
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
79+
IMMEDIATE @ONLY)
80+
81+
ADD_CUSTOM_TARGET(uninstall
82+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
83+
ENDIF()
84+
85+
86+
#############################################################################
87+
#### OS DEPENDENT ####
7388
#############################################################################
7489

7590
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
@@ -100,7 +115,7 @@ ENDIF()
100115

101116

102117
#############################################################################
103-
# CHECK STRUCT MEMBERS
118+
#### CHECK STRUCT MEMBERS ####
104119
#############################################################################
105120

106121
CHECK_STRUCT_HAS_MEMBER("struct sockaddr" "sa_len" "sys/types.h;sys/socket.h" HAVE_SA_LEN)
@@ -129,7 +144,7 @@ ENDIF()
129144

130145

131146
#############################################################################
132-
# REQUIREMENTS
147+
#### REQUIREMENTS ####
133148
#############################################################################
134149

135150
INCLUDE(FindPackageHandleStandardArgs)
@@ -165,7 +180,7 @@ FIND_PROGRAM(MSGFMT msgfmt REQUIRED)
165180

166181

167182
#############################################################################
168-
# SUBDIRECTORIES
183+
#### SUBDIRECTORIES ####
169184
#############################################################################
170185

171186
ADD_SUBDIRECTORY(src)

cmake_uninstall.cmake.in

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Based on:
2+
# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
3+
4+
IF(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
5+
MESSAGE(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
6+
ENDIF()
7+
8+
FILE(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
9+
STRING(REGEX REPLACE "\n" ";" files "${files}")
10+
FOREACH(file ${files})
11+
MESSAGE(STATUS "Uninstalling $ENV{DESTDIR}${file}")
12+
IF(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
13+
EXECUTE_PROCESS(
14+
COMMAND "@CMAKE_COMMAND@" -E remove "$ENV{DESTDIR}${file}"
15+
OUTPUT_VARIABLE rm_out
16+
RESULT_VARIABLE rm_retval
17+
)
18+
IF(NOT "${rm_retval}" STREQUAL 0)
19+
MESSAGE(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
20+
ENDIF()
21+
ELSE(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
22+
MESSAGE(STATUS "File $ENV{DESTDIR}${file} does not exist.")
23+
ENDIF()
24+
ENDFOREACH()

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
4040

4141

4242
#############################################################################
43-
# PROGRAMS
43+
#### PROGRAMS ####
4444
#############################################################################
4545

4646
ADD_EXECUTABLE(subnetcalc subnetcalc.cc tools.cc)

0 commit comments

Comments
 (0)