Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buildscripts/cmake uninstall target #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/cmake-install-uninstall.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CMake Install & Uninstall

on:
push:
pull_request:
branches: [ "master" ]

jobs:
build:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 5

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3

- name: Configure CMake
run: |
cmake -S . -B .build -DCMAKE_BUILD_TYPE=Release

- name: Build CMake
run: |
cmake --build .build --config Release

- name: Install
run: |
cmake --install .build --prefix .install

- name: Uninstall
run: |
cmake --build .build --target uninstall
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ install(TARGETS h264bitstream h264_analyze svc_split
FILE_SET headers
)

# Support for pkg-config in consuming projects
if(UNIX)
# Support for pkg-config in consuming projects
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "${CMAKE_INSTALL_PREFIX}")
set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
Expand All @@ -73,4 +73,16 @@ if(UNIX)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libh264bitstream.pc"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
)
endif(UNIX)
endif(UNIX)

# uninstall target
if(NOT TARGET uninstall)
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
)
endif()
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ All commands below should be run from the project root directory.
└── libh264bitstream.pc
```

CMake doesn't support `make uninstall` by default. But the project has the `uninstall` target, which deletes all files listed in `install_manifest.txt` file. To use it, run:

```sh
cmake --build .builddir --target uninstall
```

## Compile and Install with Autotools

1. Install pre-requisites (Debian, Ubuntu)
Expand Down
20 changes: 20 additions & 0 deletions cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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 rm "$ENV{DESTDIR}${file}"
RESULT_VARIABLE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
endif()
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
endif()
endforeach()
Loading