]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add install and uninstall support for CMake.
authorGuy Harris <[email protected]>
Mon, 22 Jan 2018 23:49:06 +0000 (15:49 -0800)
committerGuy Harris <[email protected]>
Mon, 22 Jan 2018 23:49:06 +0000 (15:49 -0800)
CMakeLists.txt
Makefile.in
cmake_uninstall.cmake.in [new file with mode: 0644]

index 191d8a9eb837fb382dd45c52908ced92036be901..745db692df81ae2700d49addb1cfaf5ba38e2c7e 100644 (file)
@@ -697,3 +697,40 @@ target_link_libraries(tcpdump netdissect ${PCAP_LIBRARY} ${SMI_LIBRARY})
 ######################################
 
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmakeconfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+
+######################################
+# Install tcpdump and man pages
+######################################
+
+#
+# "Define GNU standard installation directories", which actually
+# are also defined, to some degree, by autotools, and at least
+# some of which are general UN*X conventions.
+#
+include(GNUInstallDirs)
+
+set(MAN1 tcpdump.1)
+
+if(WIN32)
+    # XXX TODO where to install on Windows?
+else(WIN32)
+    install(TARGETS tcpdump DESTINATION sbin)
+endif(WIN32)
+
+# On UN*X, and on Windows when not using MSVC, process man pages and
+# arrange that they be installed.
+if(NOT MSVC)
+    #
+    # Man pages.
+    #
+    install(FILES ${MAN1} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
+endif(NOT MSVC)
+
+# uninstall target
+configure_file(
+    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
+    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
+    IMMEDIATE @ONLY)
+
+add_custom_target(uninstall
+    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
index 749f24eba00e60cd5b1e760d1e5c8d4b515db520..baa2c240e7bff7615ba901ca004e7b671830d792 100644 (file)
@@ -330,6 +330,7 @@ EXTRA_DIST = \
        aclocal.m4 \
        atime.awk \
        bpf_dump.c \
+       cmake_uninstall.cmake.in \
        cmakeconfig.h.in \
        cmake/Modules/FindPCAP.cmake \
        cmake/Modules/FindSMI.cmake \
diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in
new file mode 100644 (file)
index 0000000..2037e36
--- /dev/null
@@ -0,0 +1,21 @@
+if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
+  message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
+endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
+
+file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
+string(REGEX REPLACE "\n" ";" files "${files}")
+foreach(file ${files})
+  message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
+  if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    exec_program(
+      "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
+      OUTPUT_VARIABLE rm_out
+      RETURN_VALUE rm_retval
+      )
+    if(NOT "${rm_retval}" STREQUAL 0)
+      message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
+    endif(NOT "${rm_retval}" STREQUAL 0)
+  else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
+  endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+endforeach(file)