diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b9a5f2..11d011a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,18 +6,37 @@ set(CMAKE_C_STANDARD_REQUIRED YES) set(CMAKE_C_EXTENSIONS NO) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +include(GNUInstallDirs) file(GLOB HTD_SOURCES src/data_structure/*.c ) add_library(htd STATIC ${HTD_SOURCES}) - target_include_directories(htd PUBLIC ${PROJECT_SOURCE_DIR}/include ) target_compile_options(htd PRIVATE -Wall -Wextra -Werror) +install(TARGETS htd + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) +install(DIRECTORY include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/htd + FILES_MATCHING PATTERN "*.h" +) + +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 +) + set(CMAKE_CTEST_VERBOSE TRUE) enable_testing() diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in new file mode 100644 index 0000000..e2a36cd --- /dev/null +++ b/cmake_uninstall.cmake.in @@ -0,0 +1,21 @@ +if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") +endif() + +file(READ "@CMAKE_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}") + execute_process( + COMMAND ${CMAKE_COMMAND} -E remove "$ENV{DESTDIR}${file}" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif() + else() + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif() +endforeach()