diff --git a/CMakeLists.txt b/CMakeLists.txt index 05fb30a8f..6d4e7928f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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) @@ -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 () diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in new file mode 100644 index 000000000..e925304f8 --- /dev/null +++ b/cmake/cmake_uninstall.cmake.in @@ -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()