From: Guy Harris Date: Mon, 22 Jan 2018 23:49:06 +0000 (-0800) Subject: Add install and uninstall support for CMake. X-Git-Tag: tcpdump-4.99-bp~1406 X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/5632b98204c3aaddb87e7e6c6842e92fd86ddbbc Add install and uninstall support for CMake. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 191d8a9e..745db692 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/Makefile.in b/Makefile.in index 749f24eb..baa2c240 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 index 00000000..2037e365 --- /dev/null +++ b/cmake_uninstall.cmake.in @@ -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)