Skip to content

Commit 98bde9e

Browse files
authored
Merge pull request #362 from gmou3/main
Add CMake uninstall target
2 parents 39336f0 + 92a0400 commit 98bde9e

File tree

3 files changed

+76
-20
lines changed

3 files changed

+76
-20
lines changed

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,14 @@ if (MAXMINDDB_INSTALL)
155155
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libmaxminddb.pc
156156
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
157157
endif()
158+
159+
# uninstall target
160+
if(NOT TARGET uninstall)
161+
configure_file(
162+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
163+
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
164+
IMMEDIATE @ONLY)
165+
166+
add_custom_target(uninstall
167+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
168+
endif()

README.md

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ structure.
3030

3131
To install this code, run the following commands:
3232

33-
$ ./configure
34-
$ make
35-
$ make check
36-
$ sudo make install
37-
$ sudo ldconfig
33+
```bash
34+
./configure
35+
make
36+
make check
37+
sudo make install
38+
sudo ldconfig
39+
```
3840

3941
You can skip the `make check` step but it's always good to know that tests are
4042
passing on your platform.
@@ -47,8 +49,10 @@ you may need to add the `lib` directory in your `prefix` to your library path.
4749
On most Linux distributions when using the default prefix (`/usr/local`), you
4850
can do this by running the following commands:
4951

50-
$ sudo sh -c "echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf"
51-
$ ldconfig
52+
```bash
53+
sudo sh -c "echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf"
54+
ldconfig
55+
```
5256

5357
## From a GitHub "Source Code" Archive / Git Repo Clone (Achtung!)
5458

@@ -65,7 +69,9 @@ in addition to `make` and a compiler.
6569

6670
You can clone this repository and build it by running:
6771

68-
$ git clone --recursive https://github.com/maxmind/libmaxminddb
72+
```bash
73+
git clone --recursive https://github.com/maxmind/libmaxminddb
74+
```
6975

7076
After cloning, run `./bootstrap` from the `libmaxminddb` directory and then
7177
follow the instructions for installing from a named release tarball as
@@ -76,39 +82,57 @@ described above.
7682
We provide a CMake build script. This is primarily targeted at Windows users,
7783
but it can be used in other circumstances where the Autotools script does not
7884
work.
79-
80-
$ mkdir build && cd build
81-
$ cmake ..
82-
$ cmake --build .
83-
$ ctest -V .
84-
$ cmake --build . --target install
85+
86+
```bash
87+
cmake -B build
88+
cd build/
89+
cmake --build .
90+
ctest -V .
91+
cmake --build . --target install
92+
```
8593

8694
When building with Visual Studio, you may build a multithreaded (MT/MTd)
8795
runtime library, using the `MSVC_STATIC_RUNTIME` setting:
8896

89-
$ cmake -DMSVC_STATIC_RUNTIME=ON -DBUILD_SHARED_LIBS=OFF ..
97+
```bash
98+
cmake -DMSVC_STATIC_RUNTIME=ON -DBUILD_SHARED_LIBS=OFF ..
99+
```
100+
101+
We also include a CMake `uninstall` target:
102+
103+
```bash
104+
cmake --build . --target uninstall
105+
```
90106

91107
## On Ubuntu via PPA
92108

93109
MaxMind provides a PPA for recent version of Ubuntu. To add the PPA to your
94110
APT sources, run:
95111

96-
$ sudo add-apt-repository ppa:maxmind/ppa
112+
```bash
113+
sudo add-apt-repository ppa:maxmind/ppa
114+
```
97115

98116
Then install the packages by running:
99117

100-
$ sudo apt update
101-
$ sudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin
118+
```bash
119+
sudo apt update
120+
sudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin
121+
```
102122

103123
## On macOS via Homebrew or MacPorts
104124

105125
You can install libmaxminddb on macOS using [Homebrew](https://brew.sh):
106126

107-
$ brew install libmaxminddb
127+
```bash
128+
brew install libmaxminddb
129+
```
108130

109131
Or with [MacPorts](https://ports.macports.org/port/libmaxminddb):
110132

111-
$ sudo port install libmaxminddb
133+
```bash
134+
sudo port install libmaxminddb
135+
```
112136

113137
# Requirements
114138

cmake_uninstall.cmake.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
2+
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
3+
endif()
4+
5+
file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
6+
string(REGEX REPLACE "\n" ";" files "${files}")
7+
foreach(file ${files})
8+
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
9+
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
10+
execute_process(
11+
COMMAND "@CMAKE_COMMAND@" -E remove "$ENV{DESTDIR}${file}"
12+
OUTPUT_VARIABLE rm_out
13+
RESULT_VARIABLE rm_retval
14+
)
15+
if(NOT "${rm_retval}" STREQUAL 0)
16+
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
17+
endif()
18+
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
19+
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
20+
endif()
21+
endforeach()

0 commit comments

Comments
 (0)