This is an automated email from the ASF dual-hosted git repository.

szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit 0e59e2cdb828a3a428bdc242d6cf6b8944865f3d
Author: Gabor Gyimesi <[email protected]>
AuthorDate: Tue Jul 16 16:01:22 2024 +0000

    MINIFICPP-2269 Upgrade LibLZMA/XZ utils to version 5.6.2
    
    Closes #1823
    
    Signed-off-by: Marton Szasz <[email protected]>
---
 cmake/BundledLibLZMA.cmake            |  99 -----
 cmake/LibLZMA.cmake                   |  45 +++
 cmake/liblzma/dummy/FindLibLZMA.cmake |  17 +-
 extensions/libarchive/CMakeLists.txt  |   3 +-
 thirdparty/liblzma/liblzma.patch      | 693 ++++++++++++++++++++++++++++------
 5 files changed, 621 insertions(+), 236 deletions(-)

diff --git a/cmake/BundledLibLZMA.cmake b/cmake/BundledLibLZMA.cmake
deleted file mode 100644
index 4e58c534f..000000000
--- a/cmake/BundledLibLZMA.cmake
+++ /dev/null
@@ -1,99 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-function(use_bundled_liblzma SOURCE_DIR BINARY_DIR)
-    message("Using bundled liblzma")
-
-    # Define patch step
-    if (WIN32)
-        set(PC "${Patch_EXECUTABLE}" -p1 -i 
"${SOURCE_DIR}/thirdparty/liblzma/liblzma.patch")
-    endif()
-
-    # Define byproduct
-    if (WIN32)
-        set(BYPRODUCT "lib/lzma.lib")
-    else()
-        set(BYPRODUCT "lib/liblzma.a")
-    endif()
-
-    # Set build options
-    set(LIBLZMA_BIN_DIR "${BINARY_DIR}/thirdparty/liblzma-install" CACHE 
STRING "" FORCE)
-
-    if (WIN32)
-        set(LIBLZMA_CMAKE_ARGS ${PASSTHROUGH_CMAKE_ARGS}
-                "-DCMAKE_INSTALL_PREFIX=${LIBLZMA_BIN_DIR}")
-    endif()
-
-    # Build project
-    set(LIBLZMA_URL https://distfiles.gentoo.org/distfiles/22/xz-5.2.5.tar.gz 
https://tukaani.org/xz/xz-5.2.5.tar.gz)
-    set(LIBLZMA_URL_HASH 
"SHA256=f6f4910fd033078738bd82bfba4f49219d03b17eb0794eb91efbae419f4aba10")
-
-    if (WIN32)
-        ExternalProject_Add(
-                liblzma-external
-                URL ${LIBLZMA_URL}
-                URL_HASH ${LIBLZMA_URL_HASH}
-                SOURCE_DIR "${BINARY_DIR}/thirdparty/liblzma-src"
-                LIST_SEPARATOR % # This is needed for passing 
semicolon-separated lists
-                CMAKE_ARGS ${LIBLZMA_CMAKE_ARGS}
-                PATCH_COMMAND ${PC}
-                BUILD_BYPRODUCTS "${LIBLZMA_BIN_DIR}/${BYPRODUCT}"
-                EXCLUDE_FROM_ALL TRUE
-        )
-    else()
-        set(CONFIGURE_COMMAND ./configure "CFLAGS=${PASSTHROUGH_CMAKE_C_FLAGS} 
-fPIC" "CXXFLAGS=${PASSTHROUGH_CMAKE_CXX_FLAGS} -fPIC" --disable-xz 
--disable-xzdec --disable-lzmadec --disable-lzmainfo --disable-lzma-links 
--disable-scripts --disable-doc --enable-shared=no 
"--prefix=${LIBLZMA_BIN_DIR}")
-        if(PORTABLE)
-            list(APPEND CONFIGURE_COMMAND "--disable-assembler")
-        endif()
-
-        ExternalProject_Add(
-                liblzma-external
-                URL ${LIBLZMA_URL}
-                URL_HASH ${LIBLZMA_URL_HASH}
-                BUILD_IN_SOURCE true
-                SOURCE_DIR "${BINARY_DIR}/thirdparty/liblzma-src"
-                BUILD_COMMAND make
-                CMAKE_COMMAND ""
-                UPDATE_COMMAND ""
-                INSTALL_COMMAND make install
-                BUILD_BYPRODUCTS "${LIBLZMA_BIN_DIR}/${BYPRODUCT}"
-                CONFIGURE_COMMAND ""
-                PATCH_COMMAND ${CONFIGURE_COMMAND}
-                STEP_TARGETS build
-                EXCLUDE_FROM_ALL TRUE
-        )
-    endif()
-
-    # Set variables
-    set(LIBLZMA_FOUND "YES" CACHE STRING "" FORCE)
-    set(LIBLZMA_INCLUDE_DIRS "${LIBLZMA_BIN_DIR}/include" CACHE STRING "" 
FORCE)
-    set(LIBLZMA_LIBRARIES "${LIBLZMA_BIN_DIR}/${BYPRODUCT}" CACHE STRING "" 
FORCE)
-
-    # Set exported variables for FindPackage.cmake
-    set(PASSTHROUGH_VARIABLES ${PASSTHROUGH_VARIABLES} 
"-DEXPORTED_LIBLZMA_INCLUDE_DIRS=${LIBLZMA_INCLUDE_DIRS}" CACHE STRING "" FORCE)
-    set(PASSTHROUGH_VARIABLES ${PASSTHROUGH_VARIABLES} 
"-DEXPORTED_LIBLZMA_LIBRARIES=${LIBLZMA_LIBRARIES}" CACHE STRING "" FORCE)
-
-    # Create imported targets
-    file(MAKE_DIRECTORY ${LIBLZMA_INCLUDE_DIRS})
-
-    add_library(LibLZMA::LibLZMA STATIC IMPORTED)
-    set_target_properties(LibLZMA::LibLZMA PROPERTIES IMPORTED_LOCATION 
"${LIBLZMA_LIBRARIES}")
-    add_dependencies(LibLZMA::LibLZMA liblzma-external)
-    set_property(TARGET LibLZMA::LibLZMA APPEND PROPERTY 
INTERFACE_INCLUDE_DIRECTORIES "${LIBLZMA_INCLUDE_DIRS}")
-endfunction(use_bundled_liblzma)
diff --git a/cmake/LibLZMA.cmake b/cmake/LibLZMA.cmake
new file mode 100644
index 000000000..1cd66d84c
--- /dev/null
+++ b/cmake/LibLZMA.cmake
@@ -0,0 +1,45 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+include(FetchContent)
+
+set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
+
+set(PATCH_FILE "${CMAKE_SOURCE_DIR}/thirdparty/liblzma/liblzma.patch")
+set(PC ${Bash_EXECUTABLE}  -c "set -x &&\
+        (\\\"${Patch_EXECUTABLE}\\\" -p1 -R -s -f --dry-run -i 
\\\"${PATCH_FILE}\\\" || \\\"${Patch_EXECUTABLE}\\\" -p1 -N -i 
\\\"${PATCH_FILE}\\\")")
+
+FetchContent_Declare(liblzma
+        URL 
https://github.com/tukaani-project/xz/releases/download/v5.6.2/xz-5.6.2.tar.gz
+        URL_HASH 
SHA256=8bfd20c0e1d86f0402f2497cfa71c6ab62d4cd35fd704276e3140bfb71414519
+        PATCH_COMMAND "${PC}")
+
+FetchContent_MakeAvailable(liblzma)
+
+add_library(LibLZMA::LibLZMA ALIAS liblzma)
+
+# Set exported variables for FindPackage.cmake
+
+set(LIBLZMA_INCLUDE_DIR "${liblzma_SOURCE_DIR}/src/liblzma/api" CACHE STRING 
"" FORCE)
+if (WIN32)
+    set(LIBLZMA_LIBRARY "${liblzma_BINARY_DIR}/liblzma.lib" CACHE STRING "" 
FORCE)
+else()
+    set(LIBLZMA_LIBRARY "${liblzma_BINARY_DIR}/liblzma.a" CACHE STRING "" 
FORCE)
+endif()
+
+set(PASSTHROUGH_VARIABLES ${PASSTHROUGH_VARIABLES} 
"-DEXPORTED_LIBLZMA_INCLUDE_DIR=${LIBLZMA_INCLUDE_DIR}" CACHE STRING "" FORCE)
+set(PASSTHROUGH_VARIABLES ${PASSTHROUGH_VARIABLES} 
"-DEXPORTED_LIBLZMA_LIBRARY=${LIBLZMA_LIBRARY}" CACHE STRING "" FORCE)
diff --git a/cmake/liblzma/dummy/FindLibLZMA.cmake 
b/cmake/liblzma/dummy/FindLibLZMA.cmake
index ef7c69b61..c298caab4 100644
--- a/cmake/liblzma/dummy/FindLibLZMA.cmake
+++ b/cmake/liblzma/dummy/FindLibLZMA.cmake
@@ -15,19 +15,10 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# Dummy zlib find for when we use bundled version
 if(NOT LIBLZMA_FOUND)
     set(LIBLZMA_FOUND "YES" CACHE STRING "" FORCE)
-    set(LIBLZMA_INCLUDE_DIR "${EXPORTED_LIBLZMA_INCLUDE_DIRS}" CACHE STRING "" 
FORCE)
-    set(LIBLZMA_INCLUDE_DIRS "${EXPORTED_LIBLZMA_INCLUDE_DIRS}" CACHE STRING 
"" FORCE)
-    set(LIBLZMA_LIBRARIES "${EXPORTED_LIBLZMA_LIBRARIES}" CACHE STRING "" 
FORCE)
-endif()
-
-if(NOT TARGET LibLZMA::LibLZMA)
-    add_library(LibLZMA::LibLZMA STATIC IMPORTED)
-    set_target_properties(LibLZMA::LibLZMA PROPERTIES
-            INTERFACE_INCLUDE_DIRECTORIES "${LIBLZMA_INCLUDE_DIRS}")
-    set_target_properties(LibLZMA::LibLZMA PROPERTIES
-            IMPORTED_LINK_INTERFACE_LANGUAGES "C"
-            IMPORTED_LOCATION "${LIBLZMA_LIBRARIES}")
+    set(LIBLZMA_INCLUDE_DIR "${EXPORTED_LIBLZMA_INCLUDE_DIR}" CACHE STRING "" 
FORCE)
+    set(LIBLZMA_INCLUDE_DIRS "${EXPORTED_LIBLZMA_INCLUDE_DIR}" CACHE STRING "" 
FORCE)
+    set(LIBLZMA_LIBRARIES "${EXPORTED_LIBLZMA_LIBRARY}" CACHE STRING "" FORCE)
+    set(LIBLZMA_LIBRARIES "${EXPORTED_LIBLZMA_LIBRARY}" CACHE STRING "" FORCE)
 endif()
diff --git a/extensions/libarchive/CMakeLists.txt 
b/extensions/libarchive/CMakeLists.txt
index 57b81d08d..bf7b2a7f5 100644
--- a/extensions/libarchive/CMakeLists.txt
+++ b/extensions/libarchive/CMakeLists.txt
@@ -22,8 +22,7 @@ if (NOT ENABLE_LIBARCHIVE)
 endif()
 
 if (ENABLE_LZMA)
-    include(BundledLibLZMA)
-    use_bundled_liblzma(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
+    include(LibLZMA)
     list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/liblzma/dummy")
 endif()
 
diff --git a/thirdparty/liblzma/liblzma.patch b/thirdparty/liblzma/liblzma.patch
index 3b8ac7705..307a75975 100644
--- a/thirdparty/liblzma/liblzma.patch
+++ b/thirdparty/liblzma/liblzma.patch
@@ -1,122 +1,571 @@
-We can't run the configure script on Windows, and the only thing lzma provides
-for Windows are msbuild files which do not integrate well into our CMake build 
system,
-so we create a Windows-specific CMakeLists.txt for the project.
-
-diff -rupN orig/CMakeLists.txt patched/CMakeLists.txt
---- orig/CMakeLists.txt        1970-01-01 01:00:00.000000000 +0100
-+++ patched/CMakeLists.txt     2020-03-31 21:52:39.000000000 +0200
-@@ -0,0 +1,114 @@
-+cmake_minimum_required(VERSION 3.7)
-+
-+project(liblzma)
-+
-+set(SOURCES src/common/tuklib_cpucores.c
-+            src/common/tuklib_physmem.c
-+            src/liblzma/check/check.c
-+            src/liblzma/check/crc32_fast.c
-+            src/liblzma/check/crc32_table.c
-+            src/liblzma/check/crc64_fast.c
-+            src/liblzma/check/crc64_table.c
-+            src/liblzma/check/sha256.c
-+            src/liblzma/common/alone_decoder.c
-+            src/liblzma/common/alone_encoder.c
-+            src/liblzma/common/auto_decoder.c
-+            src/liblzma/common/block_buffer_decoder.c
-+            src/liblzma/common/block_buffer_encoder.c
-+            src/liblzma/common/block_decoder.c
-+            src/liblzma/common/block_encoder.c
-+            src/liblzma/common/block_header_decoder.c
-+            src/liblzma/common/block_header_encoder.c
-+            src/liblzma/common/block_util.c
-+            src/liblzma/common/common.c
-+            src/liblzma/common/easy_buffer_encoder.c
-+            src/liblzma/common/easy_decoder_memusage.c
-+            src/liblzma/common/easy_encoder.c
-+            src/liblzma/common/easy_encoder_memusage.c
-+            src/liblzma/common/easy_preset.c
-+            src/liblzma/common/filter_buffer_decoder.c
-+            src/liblzma/common/filter_buffer_encoder.c
-+            src/liblzma/common/filter_common.c
-+            src/liblzma/common/filter_decoder.c
-+            src/liblzma/common/filter_encoder.c
-+            src/liblzma/common/filter_flags_decoder.c
-+            src/liblzma/common/filter_flags_encoder.c
-+            src/liblzma/common/hardware_cputhreads.c
-+            src/liblzma/common/hardware_physmem.c
-+            src/liblzma/common/index.c
-+            src/liblzma/common/index_decoder.c
-+            src/liblzma/common/index_encoder.c
-+            src/liblzma/common/index_hash.c
-+            src/liblzma/common/outqueue.c
-+            src/liblzma/common/stream_buffer_decoder.c
-+            src/liblzma/common/stream_buffer_encoder.c
-+            src/liblzma/common/stream_decoder.c
-+            src/liblzma/common/stream_encoder.c
-+            src/liblzma/common/stream_encoder_mt.c
-+            src/liblzma/common/stream_flags_common.c
-+            src/liblzma/common/stream_flags_decoder.c
-+            src/liblzma/common/stream_flags_encoder.c
-+            src/liblzma/common/vli_decoder.c
-+            src/liblzma/common/vli_encoder.c
-+            src/liblzma/common/vli_size.c
-+            src/liblzma/delta/delta_common.c
-+            src/liblzma/delta/delta_decoder.c
-+            src/liblzma/delta/delta_encoder.c
-+            src/liblzma/lzma/fastpos_table.c
-+            src/liblzma/lzma/lzma2_decoder.c
-+            src/liblzma/lzma/lzma2_encoder.c
-+            src/liblzma/lzma/lzma_decoder.c
-+            src/liblzma/lzma/lzma_encoder.c
-+            src/liblzma/lzma/lzma_encoder_optimum_fast.c
-+            src/liblzma/lzma/lzma_encoder_optimum_normal.c
-+            src/liblzma/lzma/lzma_encoder_presets.c
-+            src/liblzma/lz/lz_decoder.c
-+            src/liblzma/lz/lz_encoder.c
-+            src/liblzma/lz/lz_encoder_mf.c
-+            src/liblzma/rangecoder/price_table.c
-+            src/liblzma/simple/arm.c
-+            src/liblzma/simple/armthumb.c
-+            src/liblzma/simple/ia64.c
-+            src/liblzma/simple/powerpc.c
-+            src/liblzma/simple/simple_coder.c
-+            src/liblzma/simple/simple_decoder.c
-+            src/liblzma/simple/simple_encoder.c
-+            src/liblzma/simple/sparc.c
-+            src/liblzma/simple/x86.c)
-+
-+if(WIN32)
-+  configure_file(windows/vs2017/config.h config.h COPYONLY)
-+endif()
-+
-+add_library(lzma STATIC ${SOURCES})
-+
-+set_property(TARGET lzma PROPERTY POSITION_INDEPENDENT_CODE ON)
-+
-+target_include_directories(lzma
-+                            PRIVATE
-+                              ${CMAKE_BINARY_DIR}
-+                              src/liblzma/common
-+                              src/common
-+                              src/liblzma/api
-+                              src/liblzma/check
-+                              src/liblzma/delta
-+                              src/liblzma/lz
-+                              src/liblzma/lzma
-+                              src/liblzma/rangecoder
-+                              src/liblzma/simple)
-+
-+if(WIN32)
-+  target_compile_definitions(lzma
-+                              PRIVATE
-+                                WIN32
-+                                HAVE_CONFIG_H
-+                                NDEBUG
-+                                _LIB)
-+endif()
-+
-+install(TARGETS lzma
-+    ARCHIVE DESTINATION lib
-+)
-+
-+install(DIRECTORY src/liblzma/api/ DESTINATION include
-+          FILES_MATCHING PATTERN "*.h")
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 59ecf010..c5d62b3e 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -1483,566 +1483,3 @@ function(my_install_man COMPONENT SRC_FILE LINK_NAMES)
+         endforeach()
+     endif()
+ endfunction()
+-
+-
+-#############################################################################
+-# libgnu (getopt_long)
+-#############################################################################
+-
+-# This mirrors how the Autotools build system handles the getopt_long
+-# replacement, calling the object library libgnu since the replacement
+-# version comes from Gnulib.
+-add_library(libgnu OBJECT)
+-
+-# CMake requires that even an object library must have at least once source
+-# file. So we give it a header file that results in no output files.
+-#
+-# NOTE: Using a file outside the lib directory makes it possible to
+-# delete lib/*.h and lib/*.c and still keep the build working if
+-# getopt_long replacement isn't needed. It's convenient if one wishes
+-# to be certain that no GNU LGPL code gets included in the binaries.
+-target_sources(libgnu PRIVATE src/common/sysdefs.h)
+-
+-# The Ninja Generator requires setting the linker language since it cannot
+-# guess the programming language of just a header file. Setting this
+-# property avoids needing an empty .c file or an non-empty unnecessary .c
+-# file.
+-set_target_properties(libgnu PROPERTIES LINKER_LANGUAGE C)
+-
+-# Create /lib directory in the build directory and add it to the include path.
+-file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
+-target_include_directories(libgnu PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/lib")
+-
+-# Include /lib from the source directory. It does no harm even if none of
+-# the Gnulib replacements are used.
+-target_include_directories(libgnu PUBLIC lib)
+-
+-# The command line tools need getopt_long in order to parse arguments. If
+-# the system does not have a getopt_long implementation we can use the one
+-# from Gnulib instead.
+-check_symbol_exists(getopt_long getopt.h HAVE_GETOPT_LONG)
+-
+-if(NOT HAVE_GETOPT_LONG)
+-    # Set the __GETOPT_PREFIX definition to "rpl_" (replacement) to avoid
+-    # name conflicts with libc symbols. The same prefix is set if using
+-    # the Autotools build (m4/getopt.m4).
+-    target_compile_definitions(libgnu PUBLIC "__GETOPT_PREFIX=rpl_")
+-
+-    # Create a custom copy command to copy the getopt header to the build
+-    # directory and re-copy it if it is updated. (Gnulib does it this way
+-    # because it allows choosing which .in.h files to actually use in the
+-    # build. We need just getopt.h so this is a bit overcomplicated for
+-    # a single header file only.)
+-    add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/lib/getopt.h"
+-        COMMAND "${CMAKE_COMMAND}" -E copy
+-            "${CMAKE_CURRENT_SOURCE_DIR}/lib/getopt.in.h"
+-            "${CMAKE_CURRENT_BINARY_DIR}/lib/getopt.h"
+-        MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/lib/getopt.in.h"
+-        VERBATIM)
+-
+-    target_sources(libgnu PRIVATE
+-        lib/getopt1.c
+-        lib/getopt.c
+-        lib/getopt_int.h
+-        lib/getopt-cdefs.h
+-        lib/getopt-core.h
+-        lib/getopt-ext.h
+-        lib/getopt-pfx-core.h
+-        lib/getopt-pfx-ext.h
+-        "${CMAKE_CURRENT_BINARY_DIR}/lib/getopt.h"
+-    )
+-endif()
+-
+-
+-#############################################################################
+-# xzdec and lzmadec
+-#############################################################################
+-
+-if(HAVE_DECODERS AND (NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900))
+-    foreach(XZDEC xzdec lzmadec)
+-        add_executable("${XZDEC}"
+-            src/common/sysdefs.h
+-            src/common/tuklib_common.h
+-            src/common/tuklib_config.h
+-            src/common/tuklib_exit.c
+-            src/common/tuklib_exit.h
+-            src/common/tuklib_gettext.h
+-            src/common/tuklib_progname.c
+-            src/common/tuklib_progname.h
+-            src/xzdec/xzdec.c
+-        )
+-
+-        target_include_directories("${XZDEC}" PRIVATE
+-            src/common
+-            src/liblzma/api
+-        )
+-
+-        target_link_libraries("${XZDEC}" PRIVATE liblzma libgnu)
+-
+-        if(WIN32)
+-            # Add the Windows resource file for xzdec.exe or lzmadec.exe.
+-            target_sources("${XZDEC}" PRIVATE src/xzdec/xzdec_w32res.rc)
+-            set_target_properties("${XZDEC}" PROPERTIES
+-                LINK_DEPENDS 
"${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
+-            )
+-        endif()
+-
+-        if(SANDBOX_COMPILE_DEFINITION)
+-            target_compile_definitions("${XZDEC}" PRIVATE
+-                                    "${SANDBOX_COMPILE_DEFINITION}")
+-        endif()
+-
+-        tuklib_progname("${XZDEC}")
+-
+-        install(TARGETS "${XZDEC}"
+-                RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+-                        COMPONENT "${XZDEC}_Runtime")
+-    endforeach()
+-
+-    # This is the only build-time difference with lzmadec.
+-    target_compile_definitions(lzmadec PRIVATE "LZMADEC")
+-
+-    if(UNIX)
+-        # NOTE: This puts the lzmadec.1 symlinks into xzdec_Documentation.
+-        # This isn't great but doing them separately with translated
+-        # man pages would require extra code. So this has to suffice for now.
+-        my_install_man(xzdec_Documentation src/xzdec/xzdec.1 lzmadec)
+-    endif()
+-endif()
+-
+-
+-#############################################################################
+-# lzmainfo
+-#############################################################################
+-
+-if(HAVE_DECODERS AND (NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900))
+-    add_executable(lzmainfo
+-        src/common/sysdefs.h
+-        src/common/tuklib_common.h
+-        src/common/tuklib_config.h
+-        src/common/tuklib_exit.c
+-        src/common/tuklib_exit.h
+-        src/common/tuklib_gettext.h
+-        src/common/tuklib_progname.c
+-        src/common/tuklib_progname.h
+-        src/lzmainfo/lzmainfo.c
+-    )
+-
+-    target_include_directories(lzmainfo PRIVATE
+-        src/common
+-        src/liblzma/api
+-    )
+-
+-    target_link_libraries(lzmainfo PRIVATE liblzma libgnu)
+-
+-    if(WIN32)
+-        # Add the Windows resource file for lzmainfo.exe.
+-        target_sources(lzmainfo PRIVATE src/lzmainfo/lzmainfo_w32res.rc)
+-        set_target_properties(lzmainfo PROPERTIES
+-            LINK_DEPENDS 
"${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
+-        )
+-    endif()
+-
+-    tuklib_progname(lzmainfo)
+-
+-    # NOTE: The translations are in the "xz" domain and the .mo files are
+-    # installed as part of the "xz" target.
+-    if(ENABLE_NLS)
+-        target_link_libraries(lzmainfo PRIVATE Intl::Intl)
+-
+-        target_compile_definitions(lzmainfo PRIVATE
+-                ENABLE_NLS
+-                PACKAGE="${TRANSLATION_DOMAIN}"
+-                LOCALEDIR="${LOCALEDIR_DEFINITION}"
+-        )
+-    endif()
+-
+-    install(TARGETS lzmainfo
+-            RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+-                    COMPONENT lzmainfo_Runtime)
+-
+-    if(UNIX)
+-        my_install_man(lzmainfo_Documentation src/lzmainfo/lzmainfo.1 "")
+-    endif()
+-endif()
+-
+-
+-#############################################################################
+-# xz
+-#############################################################################
+-
+-if(NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900)
+-    add_executable(xz
+-        src/common/mythread.h
+-        src/common/sysdefs.h
+-        src/common/tuklib_common.h
+-        src/common/tuklib_config.h
+-        src/common/tuklib_exit.c
+-        src/common/tuklib_exit.h
+-        src/common/tuklib_gettext.h
+-        src/common/tuklib_integer.h
+-        src/common/tuklib_mbstr.h
+-        src/common/tuklib_mbstr_fw.c
+-        src/common/tuklib_mbstr_width.c
+-        src/common/tuklib_open_stdxxx.c
+-        src/common/tuklib_open_stdxxx.h
+-        src/common/tuklib_progname.c
+-        src/common/tuklib_progname.h
+-        src/xz/args.c
+-        src/xz/args.h
+-        src/xz/coder.c
+-        src/xz/coder.h
+-        src/xz/file_io.c
+-        src/xz/file_io.h
+-        src/xz/hardware.c
+-        src/xz/hardware.h
+-        src/xz/main.c
+-        src/xz/main.h
+-        src/xz/message.c
+-        src/xz/message.h
+-        src/xz/mytime.c
+-        src/xz/mytime.h
+-        src/xz/options.c
+-        src/xz/options.h
+-        src/xz/private.h
+-        src/xz/sandbox.c
+-        src/xz/sandbox.h
+-        src/xz/signals.c
+-        src/xz/signals.h
+-        src/xz/suffix.c
+-        src/xz/suffix.h
+-        src/xz/util.c
+-        src/xz/util.h
+-    )
+-
+-    target_include_directories(xz PRIVATE
+-        src/common
+-        src/liblzma/api
+-    )
+-
+-    if(HAVE_DECODERS)
+-        target_sources(xz PRIVATE
+-            src/xz/list.c
+-            src/xz/list.h
+-        )
+-    endif()
+-
+-    target_link_libraries(xz PRIVATE liblzma libgnu)
+-
+-    target_compile_definitions(xz PRIVATE ASSUME_RAM=128)
+-
+-    if(WIN32)
+-        # Add the Windows resource file for xz.exe.
+-        target_sources(xz PRIVATE src/xz/xz_w32res.rc)
+-        set_target_properties(xz PROPERTIES
+-            LINK_DEPENDS 
"${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
+-        )
+-    endif()
+-
+-    if(SANDBOX_COMPILE_DEFINITION)
+-        target_compile_definitions(xz PRIVATE "${SANDBOX_COMPILE_DEFINITION}")
+-    endif()
+-
+-    tuklib_progname(xz)
+-    tuklib_mbstr(xz)
+-
+-    check_symbol_exists(optreset getopt.h HAVE_OPTRESET)
+-    tuklib_add_definition_if(xz HAVE_OPTRESET)
+-
+-    check_symbol_exists(posix_fadvise fcntl.h HAVE_POSIX_FADVISE)
+-    tuklib_add_definition_if(xz HAVE_POSIX_FADVISE)
+-
+-    # How to get file time:
+-    check_struct_has_member("struct stat" st_atim.tv_nsec
+-                            "sys/types.h;sys/stat.h"
+-                            HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
+-    if(HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
+-        tuklib_add_definitions(xz HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
+-    else()
+-        check_struct_has_member("struct stat" st_atimespec.tv_nsec
+-                                "sys/types.h;sys/stat.h"
+-                                HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
+-        if(HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
+-            tuklib_add_definitions(xz HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
+-        else()
+-            check_struct_has_member("struct stat" st_atimensec
+-                                    "sys/types.h;sys/stat.h"
+-                                    HAVE_STRUCT_STAT_ST_ATIMENSEC)
+-            tuklib_add_definition_if(xz HAVE_STRUCT_STAT_ST_ATIMENSEC)
+-        endif()
+-    endif()
+-
+-    # How to set file time:
+-    check_symbol_exists(futimens "sys/types.h;sys/stat.h" HAVE_FUTIMENS)
+-    if(HAVE_FUTIMENS)
+-        tuklib_add_definitions(xz HAVE_FUTIMENS)
+-    else()
+-        check_symbol_exists(futimes "sys/time.h" HAVE_FUTIMES)
+-        if(HAVE_FUTIMES)
+-            tuklib_add_definitions(xz HAVE_FUTIMES)
+-        else()
+-            check_symbol_exists(futimesat "sys/time.h" HAVE_FUTIMESAT)
+-            if(HAVE_FUTIMESAT)
+-                tuklib_add_definitions(xz HAVE_FUTIMESAT)
+-            else()
+-                check_symbol_exists(utimes "sys/time.h" HAVE_UTIMES)
+-                if(HAVE_UTIMES)
+-                    tuklib_add_definitions(xz HAVE_UTIMES)
+-                else()
+-                    check_symbol_exists(_futime "sys/utime.h" HAVE__FUTIME)
+-                    if(HAVE__FUTIME)
+-                        tuklib_add_definitions(xz HAVE__FUTIME)
+-                    else()
+-                        check_symbol_exists(utime "utime.h" HAVE_UTIME)
+-                        tuklib_add_definition_if(xz HAVE_UTIME)
+-                    endif()
+-                endif()
+-            endif()
+-        endif()
+-    endif()
+-
+-    if(ENABLE_NLS)
+-        target_link_libraries(xz PRIVATE Intl::Intl)
+-
+-        target_compile_definitions(xz PRIVATE
+-                ENABLE_NLS
+-                PACKAGE="${TRANSLATION_DOMAIN}"
+-                LOCALEDIR="${LOCALEDIR_DEFINITION}"
+-        )
+-
+-        file(STRINGS po/LINGUAS LINGUAS)
+-
+-        # Where to find .gmo files. If msgfmt is available, the .po files
+-        # will be converted as part of the build. Otherwise we will use
+-        # the pre-generated .gmo files which are included in XZ Utils
+-        # tarballs by Autotools.
+-        set(GMO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/po")
+-
+-        if(GETTEXT_FOUND)
+-            # NOTE: gettext_process_po_files' INSTALL_DESTINATION is
+-            # incompatible with how Autotools requires the .po files to
+-            # be named. CMake would require each .po file to be named with
+-            # the translation domain and thus each .po file would need its
+-            # own language-specific directory (like "po/fi/xz.po"). On top
+-            # of this, INSTALL_DESTINATION doesn't allow specifying COMPONENT
+-            # and thus the .mo files go into "Unspecified" component. So we
+-            # can use gettext_process_po_files to convert the .po files but
+-            # installation needs to be done with our own code.
+-            #
+-            # Also, the .gmo files will go to root of the build directory
+-            # instead of neatly into a subdirectory. This is hardcoded in
+-            # CMake's FindGettext.cmake.
+-            foreach(LANG IN LISTS LINGUAS)
+-                gettext_process_po_files("${LANG}" ALL
+-                        PO_FILES "${CMAKE_CURRENT_SOURCE_DIR}/po/${LANG}.po")
+-            endforeach()
+-
+-            set(GMO_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+-        endif()
+-
+-        foreach(LANG IN LISTS LINGUAS)
+-            install(
+-                FILES "${GMO_DIR}/${LANG}.gmo"
+-                DESTINATION "${CMAKE_INSTALL_LOCALEDIR}/${LANG}/LC_MESSAGES"
+-                RENAME "${TRANSLATION_DOMAIN}.mo"
+-                COMPONENT xz_Runtime)
+-        endforeach()
+-    endif()
+-
+-    # This command must be before the symlink creation to keep things working
+-    # on Cygwin and MSYS2 in all cases.
+-    #
+-    #   - Cygwin can encode symlinks in multiple ways. This can be
+-    #     controlled via the environment variable "CYGWIN". If it contains
+-    #     "winsymlinks:nativestrict" then symlink creation will fail if
+-    #     the link target doesn't exist. This mode isn't the default though.
+-    #     See: https://cygwin.com/faq.html#faq.api.symlinks
+-    #
+-    #   - MSYS2 supports the same winsymlinks option in the environment
+-    #     variable "MSYS" (not "MSYS2). The default in MSYS2 is to make
+-    #     a copy of the file instead of any kind of symlink. Thus the link
+-    #     target must exist or the creation of the "symlink" (copy) will fail.
+-    #
+-    # Our installation order must be such that when a symbolic link is created
+-    # its target must already exists. There is no race condition for parallel
+-    # builds because the generated cmake_install.cmake executes serially.
+-    install(TARGETS xz
+-            RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+-                    COMPONENT xz_Runtime)
+-
+-    if(UNIX)
+-        option(CREATE_XZ_SYMLINKS "Create unxz and xzcat symlinks" ON)
+-        option(CREATE_LZMA_SYMLINKS "Create lzma, unlzma, and lzcat symlinks"
+-               ON)
+-        set(XZ_LINKS)
+-
+-        if(CREATE_XZ_SYMLINKS)
+-            list(APPEND XZ_LINKS "unxz" "xzcat")
+-        endif()
+-
+-        if(CREATE_LZMA_SYMLINKS)
+-            list(APPEND XZ_LINKS "lzma" "unlzma" "lzcat")
+-        endif()
+-
+-        # On Cygwin, don't add the .exe suffix to the symlinks.
+-        #
+-        # FIXME? Does this make sense on MSYS & MSYS2 where "ln -s"
+-        # by default makes copies? Inside MSYS & MSYS2 it is possible
+-        # to execute files without the .exe suffix but not outside
+-        # (like in Command Prompt). Omitting the suffix matches
+-        # what configure.ac has done for many years though.
+-        my_install_symlinks(xz_Runtime "${CMAKE_INSTALL_BINDIR}"
+-                            "xz${CMAKE_EXECUTABLE_SUFFIX}" "" "${XZ_LINKS}")
+-
+-        # Install the man pages and (optionally) their symlinks
+-        # and translations.
+-        my_install_man(xz_Documentation src/xz/xz.1 "${XZ_LINKS}")
+-    endif()
+-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_Runtime)
+-    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_Runtime "${CMAKE_INSTALL_BINDIR}" xzdiff ""
+-                        "${XZDIFF_LINKS}")
+-
+-    my_install_symlinks(scripts_Runtime "${CMAKE_INSTALL_BINDIR}" xzgrep ""
+-                        "${XZGREP_LINKS}")
+-
+-    my_install_symlinks(scripts_Runtime "${CMAKE_INSTALL_BINDIR}" xzmore ""
+-                        "${XZMORE_LINKS}")
+-
+-    my_install_symlinks(scripts_Runtime "${CMAKE_INSTALL_BINDIR}" xzless ""
+-                        "${XZLESS_LINKS}")
+-
+-    my_install_man(scripts_Documentation src/scripts/xzdiff.1 
"${XZDIFF_LINKS}")
+-    my_install_man(scripts_Documentation src/scripts/xzgrep.1 
"${XZGREP_LINKS}")
+-    my_install_man(scripts_Documentation src/scripts/xzmore.1 
"${XZMORE_LINKS}")
+-    my_install_man(scripts_Documentation src/scripts/xzless.1 
"${XZLESS_LINKS}")
+-endif()
+-
+-
+-#############################################################################
+-# Documentation
+-#############################################################################
+-
+-if(UNIX)
+-    option(ENABLE_DOXYGEN "Use Doxygen to generate liblzma API docs" OFF)
+-
+-    if (ENABLE_DOXYGEN)
+-        file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doc")
+-
+-        add_custom_command(
+-            VERBATIM
+-            COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/doxygen/update-doxygen"
+-            ARGS "api"
+-                 "${CMAKE_CURRENT_SOURCE_DIR}"
+-                 "${CMAKE_CURRENT_BINARY_DIR}/doc"
+-            OUTPUT doc/api/index.html
+-            DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/doxygen/update-doxygen"
+-                    "${CMAKE_CURRENT_SOURCE_DIR}/doxygen/Doxyfile"
+-                    ${LIBLZMA_API_HEADERS}
+-        )
+-
+-        add_custom_target(
+-            liblzma-doc-api ALL
+-            DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/doc/api/index.html"
+-        )
+-
+-        install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doc/api"
+-                DESTINATION "${CMAKE_INSTALL_DOCDIR}"
+-                COMPONENT liblzma_Documentation)
+-    endif()
+-endif()
+-
+-install(DIRECTORY doc/examples
+-        DESTINATION "${CMAKE_INSTALL_DOCDIR}"
+-        COMPONENT liblzma_Documentation)
+-
+-# GPLv2 applies to the scripts. If GNU getopt_long is used then
+-# LGPLv2.1 applies to the command line tools but, using the
+-# section 3 of LGPLv2.1, GNU getopt_long can be handled as GPLv2 too.
+-# Thus GPLv2 should be enough here.
+-install(FILES AUTHORS
+-              COPYING
+-              COPYING.0BSD
+-              COPYING.GPLv2
+-              NEWS
+-              README
+-              THANKS
+-              doc/faq.txt
+-              doc/history.txt
+-              doc/lzma-file-format.txt
+-              doc/xz-file-format.txt
+-        DESTINATION "${CMAKE_INSTALL_DOCDIR}"
+-        COMPONENT Documentation)
+-
+-
+-#############################################################################
+-# Tests
+-#############################################################################
+-
+-# Tests are in a separate file so that it's possible to delete the whole
+-# "tests" directory and still have a working build, just without the tests.
+-include(tests/tests.cmake OPTIONAL)


Reply via email to