aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2024-02-17 15:35:35 +0200
committerLasse Collin <lasse.collin@tukaani.org>2024-02-19 12:21:37 +0200
commit4808f238a731befcd46c2117c62a1caaf4403989 (patch)
tree26e945fb6b10b7980603ad0397f0e8c3c9f8f77f
parentScripts: Use @PACKAGE_VERSION@ instead of @VERSION@. (diff)
downloadxz-4808f238a731befcd46c2117c62a1caaf4403989.tar.xz
CMake: Install scripts.
Compared to the Autotools-based build, this has simpler handling for the shell (@POSIX_SHELL@) and extra PATH entry for the scripts (configure has --enable-path-for-scripts=PREFIX). The simpler metho should be enough for non-ancient systems and Solaris.
-rw-r--r--CMakeLists.txt83
1 files changed, 82 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 99980bca..57013fa2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,7 +13,6 @@
# highly experimental and meant for testing only.
#
# Other missing things:
-# - No xzgrep or other scripts or their symlinks
# - No xz tests (liblzma tests only)
#
# NOTE: Even if the code compiles without warnings, the end result may be
@@ -1671,6 +1670,88 @@ endif()
#############################################################################
+# Scripts
+#############################################################################
+
+if(UNIX)
+ # NOTE: This isn't as sophisticated as in the Autotools build which
+ # uses posix-shell.m4 but hopefully this doesn't need to be either.
+ # CMake likely won't be used on as many (old) obscure systems as the
+ # Autotools-based builds are.
+ if(CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND EXISTS "/usr/xpg4/bin/sh")
+ set(POSIX_SHELL_DEFAULT "/usr/xpg4/bin/sh")
+ else()
+ set(POSIX_SHELL_DEFAULT "/bin/sh")
+ endif()
+
+ set(POSIX_SHELL "${POSIX_SHELL_DEFAULT}" CACHE STRING
+ "Shell to use for scripts (xzgrep and others)")
+
+ # Guess the extra path to add from POSIX_SHELL. Autotools-based build
+ # has a separate option --enable-path-for-scripts=PREFIX but this is
+ # enough for Solaris.
+ set(enable_path_for_scripts)
+ get_filename_component(POSIX_SHELL_DIR "${POSIX_SHELL}" DIRECTORY)
+
+ if(NOT POSIX_SHELL_DIR STREQUAL "/bin" AND
+ NOT POSIX_SHELL_DIR STREQUAL "/usr/bin")
+ set(enable_path_for_scripts "PATH=${POSIX_SHELL_DIR}:\$PATH")
+ endif()
+
+ set(XZDIFF_LINKS xzcmp)
+ set(XZGREP_LINKS xzegrep xzfgrep)
+ set(XZMORE_LINKS)
+ set(XZLESS_LINKS)
+
+ if(CREATE_LZMA_SYMLINKS)
+ list(APPEND XZDIFF_LINKS lzdiff lzcmp)
+ list(APPEND XZGREP_LINKS lzgrep lzegrep lzfgrep)
+ list(APPEND XZMORE_LINKS lzmore)
+ list(APPEND XZLESS_LINKS lzless)
+ endif()
+
+ set(xz "xz")
+
+ foreach(S xzdiff xzgrep xzmore xzless)
+ configure_file("src/scripts/${S}.in" "${S}"
+ @ONLY
+ NEWLINE_STYLE LF)
+
+ install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/${S}"
+ DESTINATION "${CMAKE_INSTALL_BINDIR}"
+ COMPONENT scripts)
+ endforeach()
+
+ # file(CHMOD ...) would need CMake 3.19 so use execute_process instead.
+ # Using +x is fine even if umask was 077. If execute bit is set at all
+ # then "make install" will set it for group and other access bits too.
+ execute_process(COMMAND chmod +x xzdiff xzgrep xzmore xzless
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+
+ unset(xz)
+ unset(POSIX_SHELL)
+ unset(enable_path_for_scripts)
+
+ my_install_symlinks(scripts "${CMAKE_INSTALL_BINDIR}" xzdiff ""
+ "${XZDIFF_LINKS}")
+
+ my_install_symlinks(scripts "${CMAKE_INSTALL_BINDIR}" xzgrep ""
+ "${XZGREP_LINKS}")
+
+ my_install_symlinks(scripts "${CMAKE_INSTALL_BINDIR}" xzmore ""
+ "${XZMORE_LINKS}")
+
+ my_install_symlinks(scripts "${CMAKE_INSTALL_BINDIR}" xzless ""
+ "${XZLESS_LINKS}")
+
+ my_install_man(scripts src/scripts/xzdiff.1 "${XZDIFF_LINKS}")
+ my_install_man(scripts src/scripts/xzgrep.1 "${XZGREP_LINKS}")
+ my_install_man(scripts src/scripts/xzmore.1 "${XZMORE_LINKS}")
+ my_install_man(scripts src/scripts/xzless.1 "${XZLESS_LINKS}")
+endif()
+
+
+#############################################################################
# Tests
#############################################################################