blob: 307a75975db48d3c119a036e0b8ccb608faa5600 [file] [log] [blame]
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)