Skip to content

Commit 1819767

Browse files
mohe2015kuba--
authored andcommitted
Possibility to install the library (#80)
1 parent 11746b4 commit 1819767

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,20 @@ if (NOT CMAKE_DISABLE_TESTING)
2727
add_sanitizers(${PROJECT_NAME} test.exe)
2828
add_sanitizers(${PROJECT_NAME} test_miniz.exe)
2929
endif()
30+
31+
install(TARGETS ${PROJECT_NAME}
32+
ARCHIVE DESTINATION lib
33+
LIBRARY DESTINATION lib
34+
COMPONENT library)
35+
install(FILES ${PROJECT_SOURCE_DIR}/src/zip.h DESTINATION include)
36+
37+
# uninstall target (https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake)
38+
if(NOT TARGET uninstall)
39+
configure_file(
40+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
41+
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
42+
IMMEDIATE @ONLY)
43+
44+
add_custom_target(uninstall
45+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake)
46+
endif()

cmake/cmake_uninstall.cmake.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# copied from https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake
2+
if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
3+
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
4+
endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
5+
6+
file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
7+
string(REGEX REPLACE "\n" ";" files "${files}")
8+
foreach(file ${files})
9+
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
10+
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
11+
exec_program(
12+
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
13+
OUTPUT_VARIABLE rm_out
14+
RETURN_VALUE rm_retval
15+
)
16+
if(NOT "${rm_retval}" STREQUAL 0)
17+
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
18+
endif(NOT "${rm_retval}" STREQUAL 0)
19+
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
20+
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
21+
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
22+
endforeach(file)
23+

0 commit comments

Comments
 (0)