From b51d67f4a95f41ae3a64973acc0e44b9f078512f Mon Sep 17 00:00:00 2001 From: Radek Zikmund Date: Mon, 23 Feb 2026 17:50:00 +0100 Subject: [PATCH] CMake: Guard script configure_file() calls with ENABLE_SCRIPTS The configure_file() calls for xzdiff, xzgrep, xzmore, and xzless were running unconditionally within the if(UNIX) block, even when ENABLE_SCRIPTS was OFF. This would cause a build failure if the src/scripts/*.in files were not present. Deleting those files can simplify license compliance when the scripts aren't needed. Move the foreach loop and related code inside if(ENABLE_SCRIPTS) guard so that configure_file() is only called when scripts are actually needed. This is mostly whitespace changes to adjust the indentation. Co-authored-by: Lasse Collin Closes: https://github.com/tukaani-project/xz/pull/210 --- CMakeLists.txt | 66 ++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d8d9a53..d853b166 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2380,51 +2380,49 @@ xzdiff, xzgrep, xzmore, xzless, and their symlinks" ON) set(XZ_POSIX_SHELL "${POSIX_SHELL_DEFAULT}" CACHE STRING "Shell to use for scripts (xzgrep and others)") - # Guess the extra path to add from XZ_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 "${XZ_POSIX_SHELL}" DIRECTORY) + if(ENABLE_SCRIPTS) + # Guess the extra path to add from XZ_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 "${XZ_POSIX_SHELL}" DIRECTORY) - if(NOT POSIX_SHELL_DIR MATCHES "^/bin$|^/usr/bin$") - set(enable_path_for_scripts "PATH=${POSIX_SHELL_DIR}:\$PATH") - endif() + if(NOT POSIX_SHELL_DIR MATCHES "^/bin$|^/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) + set(XZDIFF_LINKS xzcmp) + set(XZGREP_LINKS xzegrep xzfgrep) + set(XZMORE_LINKS) + set(XZLESS_LINKS) - if(XZ_TOOL_SYMLINKS_LZMA) - list(APPEND XZDIFF_LINKS lzdiff lzcmp) - list(APPEND XZGREP_LINKS lzgrep lzegrep lzfgrep) - list(APPEND XZMORE_LINKS lzmore) - list(APPEND XZLESS_LINKS lzless) - endif() + if(XZ_TOOL_SYMLINKS_LZMA) + 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") - set(POSIX_SHELL "${XZ_POSIX_SHELL}") + set(xz "xz") + set(POSIX_SHELL "${XZ_POSIX_SHELL}") - foreach(S xzdiff xzgrep xzmore xzless) - configure_file("src/scripts/${S}.in" "${S}" - @ONLY - NEWLINE_STYLE LF - FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE - GROUP_READ GROUP_EXECUTE - WORLD_READ WORLD_EXECUTE) + foreach(S xzdiff xzgrep xzmore xzless) + configure_file("src/scripts/${S}.in" "${S}" + @ONLY + NEWLINE_STYLE LF + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE) - if(ENABLE_SCRIPTS) install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/${S}" DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT scripts_Runtime) - endif() - endforeach() + endforeach() - unset(xz) - unset(POSIX_SHELL) - unset(enable_path_for_scripts) + unset(xz) + unset(POSIX_SHELL) + unset(enable_path_for_scripts) - if(ENABLE_SCRIPTS) my_install_symlinks(scripts_Runtime "${CMAKE_INSTALL_BINDIR}" xzdiff "" "${XZDIFF_LINKS}")