Skip to content

Commit 08f5e69

Browse files
authored
Add uninstall target (#1624)
* Add uninstall target Satisfy the OpenSSF Best Practices Badge requirement for an insta/uninstall process: https://www.bestpractices.dev/en/criteria/1#1.installation_common CMake does not support a standard "uninstall" target, but the community recommends implementing an "uninstal" target that remove files named in the `install_manifest.txt`: https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake However, our existing process of installing the symlink to the "bare" library, i.e. the symlink from libImath-3_2.so to libImath.so, fails to add the symlink to the manifest, so "make uninstall" misses the symlink. The existing mechanism use "install(CODE execute_process(cmake -E create_symlink))". This changes that to use a simpler "file(CREATE_LINK)" and "install(FILES)" to accomplish the same thing while also registering the symlink the the manifest. Also, this fixes an issue where `OpenEXRConfig.h` was passed to `install()` twice, producing two entries in `install_manifest.txt`. Signed-off-by: Cary Phillips <[email protected]> * mention uninstall in install instructions Signed-off-by: Cary Phillips <[email protected]> * poke Signed-off-by: Cary Phillips <[email protected]> * COPY_ON_ERROR Signed-off-by: Cary Phillips <[email protected]> * clarify the uninstall instructions Signed-off-by: Cary Phillips <[email protected]> --------- Signed-off-by: Cary Phillips <[email protected]>
1 parent a3fe0eb commit 08f5e69

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ if(OPENEXR_INSTALL_TOOLS AND NOT OPENEXR_INSTALL)
5252
message(SEND_ERROR "OPENEXR_INSTALL_TOOLS requires OPENEXR_INSTALL")
5353
endif()
5454

55+
# uninstall target
56+
if(NOT TARGET uninstall)
57+
configure_file(
58+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
59+
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
60+
IMMEDIATE @ONLY)
61+
add_custom_target(uninstall
62+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
63+
endif()
64+
5565
include(cmake/LibraryDefine.cmake)
5666
include(cmake/OpenEXRSetup.cmake)
5767
add_subdirectory(cmake)

cmake/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ configure_file(OpenEXRConfigInternal.h.in ${CMAKE_CURRENT_BINARY_DIR}/OpenEXRCon
7474
# make a temp copy in the binary dir for OpenEXRConfig.h to include
7575
configure_file(../src/lib/OpenEXRCore/openexr_version.h ${CMAKE_CURRENT_BINARY_DIR}/OpenEXRCore/openexr_version.h COPYONLY)
7676

77-
if(OPENEXR_INSTALL)
78-
install(
79-
FILES
80-
${CMAKE_CURRENT_BINARY_DIR}/OpenEXRConfig.h
81-
DESTINATION
82-
${CMAKE_INSTALL_INCLUDEDIR}/${OPENEXR_OUTPUT_SUBDIR}
83-
)
84-
endif()
85-
8677
###################################################
8778
####### IexConfig.h and IexConfigInternal.h
8879

cmake/LibraryDefine.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ function(OPENEXR_DEFINE_LIBRARY libname)
9393
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
9494
set(verlibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${OPENEXR_LIB_SUFFIX}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX})
9595
set(baselibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX})
96-
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E chdir \"\$ENV\{DESTDIR\}${CMAKE_INSTALL_FULL_LIBDIR}\" ${CMAKE_COMMAND} -E create_symlink ${verlibname} ${baselibname})")
96+
file(CREATE_LINK ${verlibname} ${baselibname} COPY_ON_ERROR SYMBOLIC)
97+
install(FILES ${CMAKE_BINARY_DIR}/${baselibname} DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
9798
install(CODE "message(STATUS \"Creating symlink ${CMAKE_INSTALL_FULL_LIBDIR}/${baselibname} -> ${verlibname}\")")
9899
set(verlibname)
99100
set(baselibname)

cmake/cmake_uninstall.cmake.in

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

website/install.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,29 @@ You can customize these options three ways:
277277
2. Use the UI ``cmake-gui`` or ``ccmake``.
278278
3. Specify them as command-line arguments when you invoke cmake.
279279

280+
Uninstall
281+
~~~~~~~~~
282+
283+
If you did a binary instal of OpenEXR via a package manager
284+
(`apt-get`, `yum`, `port`, `brew`, etc), use the package manager to
285+
uninstall.
286+
287+
If you have installed from source, *and you still have the build
288+
tree from which you installed*, you can uninstall via:
289+
290+
.. code-block::
291+
292+
% cmake --build $builddir --target uninstall
293+
294+
or if using ``make``:
295+
296+
.. code-block::
297+
298+
% make uninstall
299+
300+
The `uninstall` relies on CMake's `install_manifest.txt` for the record
301+
of what was installed.
302+
280303
Library Naming Options
281304
~~~~~~~~~~~~~~~~~~~~~~
282305

0 commit comments

Comments
 (0)