Add install and uninstall target
This commit is contained in:
parent
2f19f82116
commit
50a450e7c3
2 changed files with 41 additions and 1 deletions
|
|
@ -6,18 +6,37 @@ set(CMAKE_C_STANDARD_REQUIRED YES)
|
||||||
set(CMAKE_C_EXTENSIONS NO)
|
set(CMAKE_C_EXTENSIONS NO)
|
||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
file(GLOB HTD_SOURCES
|
file(GLOB HTD_SOURCES
|
||||||
src/data_structure/*.c
|
src/data_structure/*.c
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(htd STATIC ${HTD_SOURCES})
|
add_library(htd STATIC ${HTD_SOURCES})
|
||||||
|
|
||||||
target_include_directories(htd PUBLIC
|
target_include_directories(htd PUBLIC
|
||||||
${PROJECT_SOURCE_DIR}/include
|
${PROJECT_SOURCE_DIR}/include
|
||||||
)
|
)
|
||||||
target_compile_options(htd PRIVATE -Wall -Wextra -Werror)
|
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)
|
set(CMAKE_CTEST_VERBOSE TRUE)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
|
|
|
||||||
21
cmake_uninstall.cmake.in
Normal file
21
cmake_uninstall.cmake.in
Normal file
|
|
@ -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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue