Changes CMake duplicate install targets (bunzip, etc) to symlinks instead of file copies.

This commit is contained in:
Micah Snyder 2019-09-14 22:58:37 -04:00
parent 1de04548d0
commit bae2dfa931
2 changed files with 38 additions and 26 deletions

View File

@ -13,6 +13,10 @@ set(LT_CURRENT 1)
set(LT_REVISION 7)
set(LT_AGE 0)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
include(Version)
include(SymLink)
if(WIN32)
add_definitions(-DBZ_LCCWIN32)
add_definitions(-DBZ_UNIX=0)
@ -21,9 +25,6 @@ else()
add_definitions(-DBZ_LCCWIN32=0)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
include(Version)
set(BZ_VERSION ${PROJECT_VERSION})
configure_file (
${PROJECT_SOURCE_DIR}/bz_version.h.in
@ -288,17 +289,8 @@ if(ENABLE_APP)
# Create bzip2 copies bzcat and bunzip.
# The default behavior is altered in bzip2.c code by checking the program name.
if(WIN32)
ADD_CUSTOM_COMMAND(TARGET bzip2 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/$<CONFIGURATION>/bzip2.exe ${CMAKE_BINARY_DIR}/$<CONFIGURATION>/bzcat.exe)
install(PROGRAMS ${CMAKE_BINARY_DIR}/$<CONFIGURATION>/bzcat.exe DESTINATION ${CMAKE_INSTALL_BINDIR})
ADD_CUSTOM_COMMAND(TARGET bzip2 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/$<CONFIGURATION>/bzip2.exe ${CMAKE_BINARY_DIR}/$<CONFIGURATION>/bunzip.exe)
install(PROGRAMS ${CMAKE_BINARY_DIR}/$<CONFIGURATION>/bunzip.exe DESTINATION ${CMAKE_INSTALL_BINDIR})
else()
install(PROGRAMS ${CMAKE_BINARY_DIR}/bzip2 DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME bzcat)
install(PROGRAMS ${CMAKE_BINARY_DIR}/bzip2 DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME bunzip)
endif()
install_target_symlink(bzip2 bzcat)
install_target_symlink(bzip2 bunzip)
# The bzip2recover executable.
add_executable(bzip2recover)
@ -324,20 +316,12 @@ if(ENABLE_APP)
install(PROGRAMS bzdiff bzgrep bzmore
DESTINATION ${CMAKE_INSTALL_BINDIR})
install(PROGRAMS bzdiff
DESTINATION ${CMAKE_INSTALL_BINDIR}
RENAME bzcmp)
install_script_symlink(bzdiff bzcmp)
install(PROGRAMS bzgrep
DESTINATION ${CMAKE_INSTALL_BINDIR}
RENAME bzegrep)
install(PROGRAMS bzgrep
DESTINATION ${CMAKE_INSTALL_BINDIR}
RENAME bzfgrep)
install_script_symlink(bzgrep bzegrep)
install_script_symlink(bzgrep bzfgrep)
install(PROGRAMS bzmore
DESTINATION ${CMAKE_INSTALL_BINDIR}
RENAME bzless)
install_script_symlink(bzmore bzless)
endif()
endif()

28
cmake/SymLink.cmake Normal file
View File

@ -0,0 +1,28 @@
# Install a symlink of script to the "bin" directory.
# Not intended for use on Windows.
function(install_script_symlink original symlink)
add_custom_command(OUTPUT ${symlink}
COMMAND ${CMAKE_COMMAND} -E create_symlink ${original} ${symlink}
DEPENDS ${original}
COMMENT "Generating symbolic link ${symlink} of ${original}")
add_custom_target(${symlink}_tgt ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${symlink})
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${symlink} DESTINATION ${CMAKE_INSTALL_BINDIR})
endfunction()
# Install a symlink of binary target to the "bin" directory.
# On Windows, it will be a copy instead of a symlink.
function(install_target_symlink original symlink)
if(WIN32)
set(op copy)
set(symlink "${symlink}.exe")
else()
set(op create_symlink)
endif()
add_custom_command(OUTPUT ${symlink}
COMMAND ${CMAKE_COMMAND} -E ${op} $<TARGET_FILE_NAME:${original}> ${CMAKE_CURRENT_BINARY_DIR}/${symlink}
DEPENDS ${original}
WORKING_DIRECTORY $<TARGET_FILE_DIR:${original}>
COMMENT "Generating symbolic link (or copy) ${symlink} of ${original}")
add_custom_target(${symlink}_tgt ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${symlink})
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${symlink} DESTINATION ${CMAKE_INSTALL_BINDIR})
endfunction()