Skip to content

Commit

Permalink
cmake: fixes and added uninstall target
Browse files Browse the repository at this point in the history
  • Loading branch information
3cky committed Nov 30, 2017
1 parent 14fa5a4 commit bed0a84
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ cmake_install.cmake
*~
.project
.cproject
build
28 changes: 20 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,33 @@ set(mbusd_SOURCES
src/sock.c
)
add_executable(mbusd ${mbusd_SOURCES})
install(TARGETS mbusd DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}/)
install(TARGETS mbusd DESTINATION ${CMAKE_INSTALL_BINDIR})

# aggregate the man page template
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/mbusd.8.in mbusd.8)
install(FILES mbusd.8 DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man8/)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mbusd.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8)

# aggregate mbusd@.service from its template
find_program(HAVE_SYSTEMD NAMES systemd)
if(HAVE_SYSTEMD)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/systemd-units/mbusd@.service.in mbusd@.service)
# install example configuration file
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/mbusd.conf.example
DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/${CMAKE_PROJECT_NAME}
)

install(FILES mbusd@.service DESTINATION /lib/systemd/system/)
#TODO install a default ${CMAKE_CURRENT_SOURCE_DIR}/conf/mbusd.conf ??
# aggregate mbusd@.service from its template
if(IS_DIRECTORY /usr/lib/systemd/system)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/systemd-units/mbusd@.service.in mbusd@.service)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mbusd@.service DESTINATION /usr/lib/systemd/system)
endif()

# uninstall target
configure_file(
${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
@ONLY)
add_custom_target(uninstall
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)

# unittest target
option(TESTS "Enable unittests" OFF)
if(TESTS)
Expand Down
32 changes: 32 additions & 0 deletions cmake/cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# http://www.vtk.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F

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(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)
ELSEIF(IS_SYMLINK "$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(EXISTS "$ENV{DESTDIR}${file}")
MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
ENDIF(EXISTS "$ENV{DESTDIR}${file}")
ENDFOREACH(file)

0 comments on commit bed0a84

Please sign in to comment.