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

Adding uninstall target and proper handling of pcm files #397

Merged
merged 15 commits into from
May 23, 2023
Merged
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
49 changes: 31 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,25 @@ include(Testing)
# Start compile
include(MacroRootDict)

# uninstall target
if (NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/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 ()

# Clear the install dir
if (NOT DEFINED INSTALL_CLEARDIR)
set(INSTALL_CLEARDIR ON)
endif ()
if (${INSTALL_CLEARDIR} MATCHES "ON")
install(CODE "execute_process(COMMAND rm -r ${CMAKE_INSTALL_PREFIX})")
install(
CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" -P \"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake\")"
)
endif ()

# Compile and install for each subdir
Expand Down Expand Up @@ -286,20 +299,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows") # we must call library install here in
ARCHIVE DESTINATION lib)
endforeach ()

# Copy pcm files to bin
install(
CODE "
file(GLOB PCMFiles \"\${CMAKE_CURRENT_SOURCE_DIR}/rootdict/*.pcm\")
file(COPY \${PCMFiles} DESTINATION \${CMAKE_INSTALL_PREFIX}/bin)
")

else ()
# Copy pcm files to lib
install(
CODE "
file(GLOB PCMFiles \"\${CMAKE_CURRENT_SOURCE_DIR}/rootdict/*.pcm\")
file(COPY \${PCMFiles} DESTINATION \${CMAKE_INSTALL_PREFIX}/lib)
")

add_subdirectory(python-bindings)

Expand Down Expand Up @@ -332,11 +332,24 @@ if (CMAKE_SYSTEM_NAME MATCHES "Darwin") # we must call library install here in
ARCHIVE DESTINATION lib)
endforeach ()

endif ()

# Copy pcm files
if (CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "Windows")

# Copy pcm files to bin
install(
CODE "
file(GLOB PCMFiles \"\${CMAKE_CURRENT_SOURCE_DIR}/rootdict/*.pcm\")
file(COPY \${PCMFiles} DESTINATION \${CMAKE_INSTALL_PREFIX}/bin)
")
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/rootdict/
DESTINATION bin
FILES_MATCHING
PATTERN "*.pcm")
else ()

# Copy pcm files to lib
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/rootdict/
DESTINATION lib
FILES_MATCHING
PATTERN "*.pcm")

endif ()
22 changes: 22 additions & 0 deletions cmake/cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if(NOT EXISTS "${CMAKE_BINARY_DIR}/install_manifest.txt")
message(WARNING "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
return()
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}")
exec_program(
"${CMAKE_COMMAND}" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE 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()