diff --git a/CMakeLists.txt b/CMakeLists.txt index ae27ad4..363ba1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,3 +62,21 @@ if(WITH_LUA) endif(WITH_LUA) ENABLE_TESTING() + +# uninstall target +configure_file( + "${CMAKE_MODULE_PATH}/cmake_uninstall.cmake.in" + "${CMAKE_MODULE_PATH}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_MODULE_PATH}/cmake_uninstall.cmake) + +# purge target +configure_file( + "${CMAKE_MODULE_PATH}/cmake_purge.cmake.in" + "${CMAKE_MODULE_PATH}/cmake_purge.cmake" + IMMEDIATE @ONLY) + +add_custom_target(purge + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_MODULE_PATH}/cmake_purge.cmake) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 3c2571f..9327f0e 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -25,9 +25,9 @@ set(MANDIR ${MAN_INSTALL_DIR}) # set default hardcoded config paths if(WIN32) - set(BNETD_DEFAULT_CONF_FILE "conf/bnetd.conf") - set(D2CS_DEFAULT_CONF_FILE "conf/d2cs.conf") - set(D2DBS_DEFAULT_CONF_FILE "conf/d2dbs.conf") + set(BNETD_DEFAULT_CONF_FILE "../conf/bnetd.conf") + set(D2CS_DEFAULT_CONF_FILE "../conf/d2cs.conf") + set(D2DBS_DEFAULT_CONF_FILE "../conf/d2dbs.conf") else(WIN32) set(BNETD_DEFAULT_CONF_FILE "${SYSCONFDIR}/bnetd.conf") set(D2CS_DEFAULT_CONF_FILE "${SYSCONFDIR}/d2cs.conf") diff --git a/cmake/Modules/DefineInstallationPaths.cmake b/cmake/Modules/DefineInstallationPaths.cmake index 29efefa..7a15bf7 100644 --- a/cmake/Modules/DefineInstallationPaths.cmake +++ b/cmake/Modules/DefineInstallationPaths.cmake @@ -83,7 +83,7 @@ SET(LOCALE_INSTALL_DIR if(WIN32) SET(SYSCONF_INSTALL_DIR - "${EXEC_INSTALL_PREFIX}conf" + "${EXEC_INSTALL_PREFIX}/conf" CACHE PATH "The ${APPLICATION_NAME} sysconfig install dir (default conf)" FORCE ) @@ -106,8 +106,17 @@ SET(INFO_INSTALL_DIR FORCE ) -SET(LOCALSTATE_INSTALL_DIR - "${CMAKE_INSTALL_PREFIX}/var/${APPLICATION_NAME}" - CACHE PATH "The ${APPLICATION_NAME} local state install dir (default prefix/var)" - FORCE -) +if(WIN32) + SET(LOCALSTATE_INSTALL_DIR + "${EXEC_INSTALL_PREFIX}/var" + CACHE PATH "The ${APPLICATION_NAME} local state install dir (default prefix/var)" + FORCE + ) +else(WIN32) + SET(LOCALSTATE_INSTALL_DIR + "${EXEC_INSTALL_PREFIX}/var/${APPLICATION_NAME}" + CACHE PATH "The ${APPLICATION_NAME} local state install dir (default prefix/var)" + FORCE + ) +endif(WIN32) + diff --git a/cmake/Modules/cmake_purge.cmake.in b/cmake/Modules/cmake_purge.cmake.in new file mode 100644 index 0000000..66fb2e4 --- /dev/null +++ b/cmake/Modules/cmake_purge.cmake.in @@ -0,0 +1,53 @@ +if(WIN32) + message(STATUS "Uninstalling \"@EXEC_INSTALL_PREFIX@\"") + exec_program( + "@CMAKE_COMMAND@" ARGS "-E remove_directory \"@EXEC_INSTALL_PREFIX@\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing \"@EXEC_INSTALL_PREFIX@\"") + endif(NOT "${rm_retval}" STREQUAL 0) +else(WIN32) + 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) + + #remove directories + message(STATUS "Uninstalling \"@SYSCONF_INSTALL_DIR@\"") + exec_program( + "@CMAKE_COMMAND@" ARGS "-E remove_directory \"@SYSCONF_INSTALL_DIR@\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing \"@SYSCONF_INSTALL_DIR@\"") + endif(NOT "${rm_retval}" STREQUAL 0) + message(STATUS "Uninstalling \"@LOCALSTATE_INSTALL_DIR@\"") + exec_program( + "@CMAKE_COMMAND@" ARGS "-E remove_directory \"@LOCALSTATE_INSTALL_DIR@\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing \"@LOCALSTATE_INSTALL_DIR@\"") + endif(NOT "${rm_retval}" STREQUAL 0) +endif(WIN32) \ No newline at end of file diff --git a/cmake/Modules/cmake_uninstall.cmake.in b/cmake/Modules/cmake_uninstall.cmake.in new file mode 100644 index 0000000..2c34c81 --- /dev/null +++ b/cmake/Modules/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) \ No newline at end of file