summaryrefslogtreecommitdiffstats
path: root/CMake
diff options
context:
space:
mode:
Diffstat (limited to 'CMake')
-rw-r--r--CMake/Documentation.cmake329
-rw-r--r--CMake/FindBerkeley.cmake59
-rw-r--r--CMake/FindGCRYPT.cmake25
-rw-r--r--CMake/FindIconv.cmake20
-rw-r--r--CMake/FindLFS.cmake148
-rw-r--r--CMake/FindLZ4.cmake25
-rw-r--r--CMake/FindLZMA.cmake25
-rw-r--r--CMake/FindSECCOMP.cmake25
-rw-r--r--CMake/FindSystemd.cmake24
-rw-r--r--CMake/FindUdev.cmake25
-rw-r--r--CMake/FindXXHASH.cmake25
-rw-r--r--CMake/FindZSTD.cmake25
-rw-r--r--CMake/Misc.cmake101
-rw-r--r--CMake/Translations.cmake185
-rw-r--r--CMake/apti18n.h.in34
-rw-r--r--CMake/config.h.in84
-rw-r--r--CMake/endian.h.in9
-rwxr-xr-xCMake/run_if_exists.sh16
-rw-r--r--CMake/statvfs.h.in13
-rw-r--r--CMake/vendor_substitute.cmake8
20 files changed, 1205 insertions, 0 deletions
diff --git a/CMake/Documentation.cmake b/CMake/Documentation.cmake
new file mode 100644
index 0000000..f3eb4c5
--- /dev/null
+++ b/CMake/Documentation.cmake
@@ -0,0 +1,329 @@
+# po4a/docbook documentation support for CMake
+# - see documentation of add_docbook()
+#
+# Copyright (C) 2016 Julian Andres Klode <jak@debian.org>.
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+
+find_path(DOCBOOK_XSL manpages/docbook.xsl
+ # Debian
+ /usr/share/xml/docbook/stylesheet/docbook-xsl
+ /usr/share/xml/docbook/stylesheet/nwalsh
+ # OpenSUSE
+ /usr/share/xml/docbook/stylesheet/nwalsh/current
+ # Arch
+ /usr/share/xml/docbook/xsl-stylesheets
+ # Fedora
+ /usr/share/sgml/docbook/xsl-stylesheets
+ # Fink
+ ${CMAKE_INSTALL_PREFIX}/share/xml/xsl/docbook-xsl
+ # FreeBSD
+ ${CMAKE_INSTALL_PREFIX}/share/xsl/docbook/
+ NO_DEFAULT_PATH)
+
+if(NOT DOCBOOK_XSL)
+ message(FATAL_ERROR "Could not find docbook xsl")
+endif()
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docbook-text-style.xsl.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/docbook-text-style.xsl)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docbook-html-style.xsl.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/docbook-html-style.xsl)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/manpage-style.xsl.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/manpage-style.xsl)
+
+
+# Split up a string of the form DOCUMENT[.DOCUMENT][.LANGUAGE][.SECTION].EXTENSION
+#
+# There might be up to two parts in the document name. The language must be
+# a two char language code like de, or a 5 char code of the form de_DE.
+function(po4a_components doc lang sec ext translated_full_document)
+ get_filename_component(name ${translated_full_document} NAME)
+ string(REPLACE "." ";" name "${name}") # Make it a list
+
+ list(GET name 0 _doc) # First element is always the document
+ list(GET name 1 _lang) # Second *might* be a language
+ list(GET name -2 _sec) # Second-last *might* be a section
+ list(GET name -1 _ext) # Last element is always the file type
+
+ # If the language code is neither a file type, nor a section, nor a language
+ # assume it is part of the file name and use the next component as the lang.
+ if(_lang AND NOT _lang MATCHES "^(xml|dbk|[0-9]|[a-z][a-z]|[a-z][a-z]_[A-Z][A-Z])$")
+ set(_doc "${_doc}.${_lang}")
+ list(GET name 2 _lang)
+ endif()
+ # If no language is present, we get a section; both not present => type
+ if(_lang MATCHES "xml|dbk|[0-9]")
+ set(_lang "")
+ endif()
+ if(NOT _sec MATCHES "^[0-9]$") # A (manpage) section must be a number
+ set(_sec "")
+ endif()
+
+ set(${doc} ${_doc} PARENT_SCOPE)
+ set(${lang} ${_lang} PARENT_SCOPE)
+ set(${sec} ${_sec} PARENT_SCOPE)
+ set(${ext} ${_ext} PARENT_SCOPE)
+endfunction()
+
+
+# Process one document
+function(po4a_one stamp_out out full_document language deps)
+ path_join(full_path "${CMAKE_CURRENT_SOURCE_DIR}" "${full_document}")
+ if (full_document MATCHES "\.ent$")
+ set(dest "${language}/${full_document}")
+ set(full_dest "${dest}")
+ else()
+ po4a_components(document _ section ext "${full_document}")
+
+ # Calculate target file name
+ set(dest "${language}/${document}.${language}")
+ if(section)
+ set(dest "${dest}.${section}")
+ endif()
+ set(full_dest "${dest}.${ext}")
+ endif()
+
+ # po4a might drop files not translated enough, so build a stamp file
+ set(stamp ${CMAKE_CURRENT_BINARY_DIR}/${dest}.po4a-stamp)
+ add_custom_command(
+ OUTPUT ${stamp}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${language}
+ COMMAND po4a --previous --no-backups
+ --package-name='${PROJECT_NAME}-doc'
+ --package-version='${PACKAGE_VERSION}'
+ --msgid-bugs-address='${PACKAGE_MAIL}'
+ --translate-only ${full_dest}
+ --srcdir ${CMAKE_CURRENT_SOURCE_DIR}
+ --destdir ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/po4a.conf
+ COMMAND ${CMAKE_COMMAND} -E touch ${stamp}
+ COMMENT "Generating ${full_dest} (or dropping it)"
+ DEPENDS ${full_document} ${deps} po/${language}.po
+ )
+ # Return result
+ set(${stamp_out} ${stamp} PARENT_SCOPE)
+ set(${out} ${CMAKE_CURRENT_BINARY_DIR}/${full_dest} PARENT_SCOPE)
+endfunction()
+
+function(xsltproc_one)
+ set(generated "")
+ set(options HTML TEXT MANPAGE)
+ set(oneValueArgs STAMP STAMP_OUT FULL_DOCUMENT)
+ set(multiValueArgs INSTALL DEPENDS)
+ cmake_parse_arguments(DOC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ po4a_components(document language section ext "${DOC_FULL_DOCUMENT}")
+
+ # Default parameters
+ set(params
+ --nonet
+ --xinclude
+ --stringparam chunk.quietly yes
+ --stringparam man.output.quietly yes
+ --path ${PROJECT_SOURCE_DIR}/vendor/${CURRENT_VENDOR}/
+ --path ${CMAKE_CURRENT_SOURCE_DIR}/
+ )
+
+ # Parameters if localized
+ if(language)
+ list(APPEND params -stringparam l10n.gentext.default.language ${language})
+ endif()
+
+ path_join(full_input_path ${CMAKE_CURRENT_SOURCE_DIR} ${DOC_FULL_DOCUMENT})
+
+ if (DOC_MANPAGE)
+ if (language)
+ set(manpage_output "${CMAKE_CURRENT_BINARY_DIR}/${language}/${document}.${section}")
+ else()
+ set(manpage_output "${CMAKE_CURRENT_BINARY_DIR}/${document}.${section}")
+ endif()
+ set(manpage_stylesheet "${CMAKE_CURRENT_BINARY_DIR}/manpage-style.xsl")
+ set(manpage_params)
+
+ install(FILES ${manpage_output}
+ DESTINATION ${CMAKE_INSTALL_MANDIR}/${language}/man${section}
+ OPTIONAL)
+ endif()
+ if (DOC_HTML)
+ if (language)
+ set(html_output "${CMAKE_CURRENT_BINARY_DIR}/${language}/${document}.${language}.html")
+ else()
+ set(html_output "${CMAKE_CURRENT_BINARY_DIR}/${document}.html")
+ endif()
+ set(html_params --stringparam base.dir ${html_output})
+ set(html_stylesheet "${CMAKE_CURRENT_BINARY_DIR}/docbook-html-style.xsl")
+ install(DIRECTORY ${html_output}
+ DESTINATION ${DOC_INSTALL}
+ OPTIONAL)
+
+ endif()
+ if (DOC_TEXT)
+ if (language)
+ set(text_output "${CMAKE_CURRENT_BINARY_DIR}/${language}/${document}.${language}.text")
+ else()
+ set(text_output "${CMAKE_CURRENT_BINARY_DIR}/${document}.text")
+ endif()
+ set(text_params --stringparam base.dir ${text_output})
+ set(text_stylesheet "${CMAKE_CURRENT_BINARY_DIR}/docbook-text-style.xsl")
+
+ file(RELATIVE_PATH text_output_relative ${CMAKE_CURRENT_BINARY_DIR} ${text_output})
+
+ add_custom_command(OUTPUT ${text_output}.w3m-stamp
+ COMMAND ${PROJECT_SOURCE_DIR}/CMake/run_if_exists.sh
+ --stdout ${text_output}
+ ${text_output}.html
+ env LC_ALL=C.UTF-8 w3m -cols 78 -dump
+ -o display_charset=UTF-8
+ -no-graph -T text/html ${text_output}.html
+ COMMAND ${CMAKE_COMMAND} -E touch ${text_output}.w3m-stamp
+ COMMENT "Generating ${text_output_relative} (if not dropped by po4a)"
+ DEPENDS "${text_output}.html.xsltproc-stamp"
+ )
+ list(APPEND generated ${text_output}.w3m-stamp)
+
+ install(FILES ${text_output}
+ DESTINATION ${DOC_INSTALL}
+ OPTIONAL)
+ set(text_output "${text_output}.html")
+ endif()
+
+ foreach(type in manpage html text)
+ if (NOT ${type}_output)
+ continue()
+ endif()
+
+ set(output ${${type}_output})
+ set(stylesheet ${${type}_stylesheet})
+ set(type_params ${${type}_params})
+ file(RELATIVE_PATH output_relative ${CMAKE_CURRENT_BINARY_DIR} ${output})
+
+ add_custom_command(OUTPUT ${output}.xsltproc-stamp
+ COMMAND ${PROJECT_SOURCE_DIR}/CMake/run_if_exists.sh
+ ${full_input_path}
+ xsltproc ${params} ${type_params} -o ${output}
+ ${stylesheet}
+ ${full_input_path}
+ COMMAND ${CMAKE_COMMAND} -E touch ${output}.xsltproc-stamp
+ COMMENT "Generating ${output_relative} (if not dropped by po4a)"
+ DEPENDS ${DOC_STAMP} ${DOC_DEPENDS})
+
+ list(APPEND generated ${output}.xsltproc-stamp)
+ endforeach()
+
+ set(${DOC_STAMP_OUT} ${generated} PARENT_SCOPE)
+endfunction()
+
+
+# add_docbook(Name [ALL] [HTML] [TEXT] [MANPAGE]
+# [INSTALL install dir]
+# [DEPENDS depend ...]
+# [DOCUMENTS documents ...]
+# [LINGUAS lingua ...])
+#
+# Generate a target called name with all the documents being converted to
+# the chosen output formats and translated to the chosen languages using po4a.
+#
+# For the translation support, the po4a.conf must be written so that
+# translations for a document guide.xml are written to LANG/guide.LANG.xml,
+# and for a manual page man.5.xml to a file called LANG/man.LANG.5.xml.
+#
+# The guide and manual page names may also contain a second component separated
+# by a dot, it must however not be a valid language code.
+#
+# Note that po4a might chose not to generate a translated manual page for a
+# given language if the translation rate is not high enough. We deal with this
+# by creating stamp files.
+function(add_docbook target)
+ set(generated "")
+ set(options HTML TEXT MANPAGE ALL)
+ set(oneValueArgs)
+ set(multiValueArgs INSTALL DOCUMENTS LINGUAS TRANSLATED_ENTITIES DEPENDS)
+ cmake_parse_arguments(DOC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if (DOC_HTML)
+ list(APPEND formats HTML)
+ endif()
+ if (DOC_TEXT)
+ list(APPEND formats TEXT)
+ endif()
+ if (DOC_MANPAGE)
+ list(APPEND formats MANPAGE)
+ endif()
+
+ foreach(document ${DOC_DOCUMENTS})
+ foreach(lang ${DOC_LINGUAS})
+ set(DOC_TRANSLATED_DEPENDS ${DOC_DEPENDS})
+ foreach(entity ${DOC_TRANSLATED_ENTITIES})
+ po4a_one(po4a_stamp po4a_out ${entity} "${lang}" "")
+ list(APPEND DOC_TRANSLATED_DEPENDS ${po4a_stamp})
+ endforeach()
+
+ po4a_one(po4a_stamp po4a_out ${document} "${lang}" "${DOC_DEPENDS}")
+ xsltproc_one(STAMP_OUT xslt_stamp
+ STAMP ${po4a_stamp}
+ FULL_DOCUMENT ${po4a_out}
+ INSTALL ${DOC_INSTALL}
+ DEPENDS "${DOC_TRANSLATED_DEPENDS}"
+ ${formats})
+
+ list(APPEND stamps ${xslt_stamp})
+ endforeach()
+ xsltproc_one(STAMP_OUT xslt_stamp
+ STAMP ${document}
+ FULL_DOCUMENT ${document}
+ INSTALL ${DOC_INSTALL}
+ DEPENDS "${DOC_DEPENDS}"
+ ${formats})
+
+ list(APPEND stamps ${xslt_stamp})
+ endforeach()
+
+ if (DOC_ALL)
+ add_custom_target(${target} ALL DEPENDS ${stamps})
+ else()
+ add_custom_target(${target} DEPENDS ${stamps})
+ endif()
+endfunction()
+
+# Add an update-po4a target
+function(add_update_po4a target pot header)
+ set(WRITE_HEADER "")
+
+ if (header)
+ set(WRITE_HEADER
+ COMMAND sed -n "/^\#$/,$p" ${pot} > ${pot}.headerfree
+ COMMAND cat ${header} ${pot}.headerfree > ${pot}
+ COMMAND rm ${pot}.headerfree
+ )
+ endif()
+ add_custom_target(${target}
+ COMMAND po4a --previous --no-backups --force --no-translations
+ --msgmerge-opt --add-location=file
+ --porefs file
+ --package-name=${PROJECT_NAME}-doc --package-version=${PACKAGE_VERSION}
+ --msgid-bugs-address=${PACKAGE_MAIL} po4a.conf
+ ${WRITE_HEADER}
+ VERBATIM
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+endfunction()
diff --git a/CMake/FindBerkeley.cmake b/CMake/FindBerkeley.cmake
new file mode 100644
index 0000000..a6215d7
--- /dev/null
+++ b/CMake/FindBerkeley.cmake
@@ -0,0 +1,59 @@
+# - Try to find Berkeley DB
+# Once done this will define
+#
+# BERKELEY_FOUND - system has Berkeley DB
+# BERKELEY_INCLUDE_DIRS - the Berkeley DB include directory
+# BERKELEY_LIBRARIES - Link these to use Berkeley DB
+# BERKELEY_DEFINITIONS - Compiler switches required for using Berkeley DB
+
+# Copyright (c) 2006, Alexander Dymo, <adymo@kdevelop.org>
+# Copyright (c) 2016, Julian Andres Klode <jak@debian.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+# We need NO_DEFAULT_PATH here, otherwise CMake helpfully picks up the wrong
+# db.h on BSD systems instead of the Berkeley DB one.
+find_path(BERKELEY_INCLUDE_DIRS db.h
+ ${CMAKE_INSTALL_FULL_INCLUDEDIR}/db5
+ /usr/local/include/db5
+ /usr/include/db5
+
+ ${CMAKE_INSTALL_FULL_INCLUDEDIR}/db4
+ /usr/local/include/db4
+ /usr/include/db4
+
+ ${CMAKE_INSTALL_FULL_INCLUDEDIR}
+ /usr/local/include
+ /usr/include
+
+ NO_DEFAULT_PATH
+)
+
+find_library(BERKELEY_LIBRARIES NAMES db db-5)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Berkeley "Could not find Berkeley DB >= 4.1" BERKELEY_INCLUDE_DIRS BERKELEY_LIBRARIES)
+# show the BERKELEY_INCLUDE_DIRS and BERKELEY_LIBRARIES variables only in the advanced view
+mark_as_advanced(BERKELEY_INCLUDE_DIRS BERKELEY_LIBRARIES)
diff --git a/CMake/FindGCRYPT.cmake b/CMake/FindGCRYPT.cmake
new file mode 100644
index 0000000..56bfc9f
--- /dev/null
+++ b/CMake/FindGCRYPT.cmake
@@ -0,0 +1,25 @@
+# - Try to find GCRYPT
+# Once done, this will define
+#
+# GCRYPT_FOUND - system has GCRYPT
+# GCRYPT_INCLUDE_DIRS - the GCRYPT include directories
+# GCRYPT_LIBRARIES - the GCRYPT library
+find_package(PkgConfig)
+
+pkg_check_modules(GCRYPT_PKGCONF libgcrypt)
+
+find_path(GCRYPT_INCLUDE_DIRS
+ NAMES gcrypt.h
+ PATHS ${GCRYPT_PKGCONF_INCLUDE_DIRS}
+)
+
+
+find_library(GCRYPT_LIBRARIES
+ NAMES gcrypt
+ PATHS ${GCRYPT_PKGCONF_LIBRARY_DIRS}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(GCRYPT DEFAULT_MSG GCRYPT_INCLUDE_DIRS GCRYPT_LIBRARIES)
+
+mark_as_advanced(GCRYPT_INCLUDE_DIRS GCRYPT_LIBRARIES)
diff --git a/CMake/FindIconv.cmake b/CMake/FindIconv.cmake
new file mode 100644
index 0000000..67046d9
--- /dev/null
+++ b/CMake/FindIconv.cmake
@@ -0,0 +1,20 @@
+find_path(ICONV_INCLUDE_DIR NAMES iconv.h)
+
+find_library(ICONV_LIBRARY NAMES iconv)
+if (ICONV_LIBRARY)
+ set(ICONV_SYMBOL_FOUND "${ICONV_LIBRARY}")
+else()
+ check_function_exists(iconv_open ICONV_SYMBOL_FOUND)
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Iconv DEFAULT_MESSAGE ICONV_INCLUDE_DIR ICONV_SYMBOL_FOUND)
+
+if(ICONV_LIBRARY)
+ set(ICONV_LIBRARIES "${ICONV_LIBRARY}")
+else()
+ set(ICONV_LIBRARIES)
+endif()
+set(ICONV_INCLUDE_DIRS "${ICONV_INCLUDE_DIR}")
+
+mark_as_advanced(ICONV_LIBRARY ICONV_INCLUDE_DIR)
diff --git a/CMake/FindLFS.cmake b/CMake/FindLFS.cmake
new file mode 100644
index 0000000..e1fcf96
--- /dev/null
+++ b/CMake/FindLFS.cmake
@@ -0,0 +1,148 @@
+# CMake support for large files
+#
+# Copyright (C) 2016 Julian Andres Klode <jak@debian.org>.
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+# This defines the following variables
+#
+# LFS_DEFINITIONS - List of definitions to pass to add_definitions()
+# LFS_COMPILE_OPTIONS - List of definitions to pass to add_compile_options()
+# LFS_LIBRARIES - List of libraries and linker flags
+# LFS_FOUND - If there is Large files support
+#
+
+include(CheckCXXSourceCompiles)
+include(FindPackageHandleStandardArgs)
+
+# Test program to check for LFS. Requires that off_t has at least 8 byte large
+set(_lfs_test_source
+ "
+ #include <sys/types.h>
+ typedef char my_static_assert[sizeof(off_t) >= 8 ? 1 : -1];
+ int main(void) { return 0; }
+ "
+)
+
+# Check if the given options are needed
+#
+# This appends to the variables _lfs_cppflags, _lfs_cflags, and _lfs_ldflags,
+# it also sets LFS_FOUND to 1 if it works.
+function(_lfs_check_compiler_option var options definitions libraries)
+ set(CMAKE_REQUIRED_QUIET 1)
+ set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} ${options})
+ set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} ${definitions})
+ set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_DEFINITIONS} ${libraries})
+
+ message(STATUS "Looking for LFS support using ${options} ${definitions} ${libraries}")
+ check_cxx_source_compiles("${_lfs_test_source}" ${var})
+
+ if(${var})
+ message(STATUS "Looking for LFS support using ${options} ${definitions} ${libraries} - found")
+ set(_lfs_cppflags ${_lfs_cppflags} ${definitions} PARENT_SCOPE)
+ set(_lfs_cflags ${_lfs_cflags} ${options} PARENT_SCOPE)
+ set(_lfs_ldflags ${_lfs_ldflags} ${libraries} PARENT_SCOPE)
+ set(LFS_FOUND TRUE PARENT_SCOPE)
+ else()
+ message(STATUS "Looking for LFS support using ${options} ${definitions} ${libraries} - not found")
+ endif()
+endfunction()
+
+# Check for the availability of LFS.
+# The cases handled are:
+#
+# * Native LFS
+# * Output of getconf LFS_CFLAGS; getconf LFS_LIBS; getconf LFS_LDFLAGS
+# * Preprocessor flag -D_FILE_OFFSET_BITS=64
+# * Preprocessor flag -D_LARGE_FILES
+#
+function(_lfs_check)
+ set(_lfs_cflags)
+ set(_lfs_cppflags)
+ set(_lfs_ldflags)
+ set(_lfs_libs)
+ set(CMAKE_REQUIRED_QUIET 1)
+ message(STATUS "Looking for native LFS support")
+ check_cxx_source_compiles("${_lfs_test_source}" lfs_native)
+ if (lfs_native)
+ message(STATUS "Looking for native LFS support - found")
+ set(LFS_FOUND TRUE)
+ else()
+ message(STATUS "Looking for native LFS support - not found")
+ endif()
+
+ if (NOT LFS_FOUND)
+ # Check using getconf. If getconf fails, don't worry, the check in
+ # _lfs_check_compiler_option will fail as well.
+ execute_process(COMMAND getconf LFS_CFLAGS
+ OUTPUT_VARIABLE _lfs_cflags_raw
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_QUIET)
+ execute_process(COMMAND getconf LFS_LIBS
+ OUTPUT_VARIABLE _lfs_libs_tmp
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_QUIET)
+ execute_process(COMMAND getconf LFS_LDFLAGS
+ OUTPUT_VARIABLE _lfs_ldflags_tmp
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_QUIET)
+
+ separate_arguments(_lfs_cflags_raw)
+ separate_arguments(_lfs_ldflags_tmp)
+ separate_arguments(_lfs_libs_tmp)
+
+ # Move -D flags to the place they are supposed to be
+ foreach(flag ${_lfs_cflags_raw})
+ if (flag MATCHES "-D.*")
+ list(APPEND _lfs_cppflags_tmp ${flag})
+ else()
+ list(APPEND _lfs_cflags_tmp ${flag})
+ endif()
+ endforeach()
+
+ # Check if the flags we received (if any) produce working LFS support
+ _lfs_check_compiler_option(lfs_getconf_works
+ "${_lfs_cflags_tmp}"
+ "${_lfs_cppflags_tmp}"
+ "${_lfs_libs_tmp};${_lfs_ldflags_tmp}")
+ endif()
+
+ if(NOT LFS_FOUND) # IRIX stuff
+ _lfs_check_compiler_option(lfs_need_n32 "-n32" "" "")
+ endif()
+ if(NOT LFS_FOUND) # Linux and friends
+ _lfs_check_compiler_option(lfs_need_file_offset_bits "" "-D_FILE_OFFSET_BITS=64" "")
+ endif()
+ if(NOT LFS_FOUND) # AIX
+ _lfs_check_compiler_option(lfs_need_large_files "" "-D_LARGE_FILES=1" "")
+ endif()
+
+ set(LFS_DEFINITIONS ${_lfs_cppflags} CACHE STRING "Extra definitions for large file support")
+ set(LFS_COMPILE_OPTIONS ${_lfs_cflags} CACHE STRING "Extra definitions for large file support")
+ set(LFS_LIBRARIES ${_lfs_libs} ${_lfs_ldflags} CACHE STRING "Extra definitions for large file support")
+ set(LFS_FOUND ${LFS_FOUND} CACHE INTERNAL "Found LFS")
+endfunction()
+
+if (NOT LFS_FOUND)
+ _lfs_check()
+endif()
+
+find_package_handle_standard_args(LFS "Could not find LFS. Set LFS_DEFINITIONS, LFS_COMPILE_OPTIONS, LFS_LIBRARIES." LFS_FOUND)
diff --git a/CMake/FindLZ4.cmake b/CMake/FindLZ4.cmake
new file mode 100644
index 0000000..597f520
--- /dev/null
+++ b/CMake/FindLZ4.cmake
@@ -0,0 +1,25 @@
+# - Try to find LZ4
+# Once done, this will define
+#
+# LZ4_FOUND - system has LZ4
+# LZ4_INCLUDE_DIRS - the LZ4 include directories
+# LZ4_LIBRARIES - the LZ4 library
+find_package(PkgConfig)
+
+pkg_check_modules(LZ4_PKGCONF liblz4)
+
+find_path(LZ4_INCLUDE_DIRS
+ NAMES lz4frame.h
+ PATHS ${LZ4_PKGCONF_INCLUDE_DIRS}
+)
+
+
+find_library(LZ4_LIBRARIES
+ NAMES lz4
+ PATHS ${LZ4_PKGCONF_LIBRARY_DIRS}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LZ4 DEFAULT_MSG LZ4_INCLUDE_DIRS LZ4_LIBRARIES)
+
+mark_as_advanced(LZ4_INCLUDE_DIRS LZ4_LIBRARIES)
diff --git a/CMake/FindLZMA.cmake b/CMake/FindLZMA.cmake
new file mode 100644
index 0000000..6abc4fa
--- /dev/null
+++ b/CMake/FindLZMA.cmake
@@ -0,0 +1,25 @@
+# - Try to find LZMA
+# Once done, this will define
+#
+# LZMA_FOUND - system has LZMA
+# LZMA_INCLUDE_DIRS - the LZMA include directories
+# LZMA_LIBRARIES - the LZMA library
+find_package(PkgConfig)
+
+pkg_check_modules(LZMA_PKGCONF liblzma)
+
+find_path(LZMA_INCLUDE_DIRS
+ NAMES lzma.h
+ PATHS ${LZMA_PKGCONF_INCLUDE_DIRS}
+)
+
+
+find_library(LZMA_LIBRARIES
+ NAMES lzma
+ PATHS ${LZMA_PKGCONF_LIBRARY_DIRS}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LZMA DEFAULT_MSG LZMA_INCLUDE_DIRS LZMA_LIBRARIES)
+
+mark_as_advanced(LZMA_INCLUDE_DIRS LZMA_LIBRARIES)
diff --git a/CMake/FindSECCOMP.cmake b/CMake/FindSECCOMP.cmake
new file mode 100644
index 0000000..5cfd13a
--- /dev/null
+++ b/CMake/FindSECCOMP.cmake
@@ -0,0 +1,25 @@
+# - Try to find SECCOMP
+# Once done, this will define
+#
+# SECCOMP_FOUND - system has SECCOMP
+# SECCOMP_INCLUDE_DIRS - the SECCOMP include directories
+# SECCOMP_LIBRARIES - the SECCOMP library
+find_package(PkgConfig)
+
+pkg_check_modules(SECCOMP_PKGCONF libseccomp)
+
+find_path(SECCOMP_INCLUDE_DIRS
+ NAMES seccomp.h
+ PATHS ${SECCOMP_PKGCONF_INCLUDE_DIRS}
+)
+
+
+find_library(SECCOMP_LIBRARIES
+ NAMES seccomp
+ PATHS ${SECCOMP_PKGCONF_LIBRARY_DIRS}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(SECCOMP DEFAULT_MSG SECCOMP_INCLUDE_DIRS SECCOMP_LIBRARIES)
+
+mark_as_advanced(SECCOMP_INCLUDE_DIRS SECCOMP_LIBRARIES)
diff --git a/CMake/FindSystemd.cmake b/CMake/FindSystemd.cmake
new file mode 100644
index 0000000..1c7a7de
--- /dev/null
+++ b/CMake/FindSystemd.cmake
@@ -0,0 +1,24 @@
+# - Try to find SYSTEMD
+# Once done, this will define
+#
+# SYSTEMD_FOUND - system has SYSTEMD
+# SYSTEMD_INCLUDE_DIRS - the SYSTEMD include directories
+# SYSTEMD_LIBRARIES - the SYSTEMD library
+find_package(PkgConfig)
+
+pkg_check_modules(SYSTEMD_PKGCONF libsystemd)
+
+find_path(SYSTEMD_INCLUDE_DIRS
+ NAMES systemd/sd-bus.h
+ PATHS ${SYSTEMD_PKGCONF_INCLUDE_DIRS}
+)
+
+find_library(SYSTEMD_LIBRARIES
+ NAMES systemd
+ PATHS ${SYSTEMD_PKGCONF_LIBRARY_DIRS}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Systemd DEFAULT_MSG SYSTEMD_INCLUDE_DIRS SYSTEMD_LIBRARIES)
+
+mark_as_advanced(SYSTEMD_INCLUDE_DIRS SYSTEMD_LIBRARIES)
diff --git a/CMake/FindUdev.cmake b/CMake/FindUdev.cmake
new file mode 100644
index 0000000..e416c43
--- /dev/null
+++ b/CMake/FindUdev.cmake
@@ -0,0 +1,25 @@
+# - Try to find UDEV
+# Once done, this will define
+#
+# UDEV_FOUND - system has UDEV
+# UDEV_INCLUDE_DIRS - the UDEV include directories
+# UDEV_LIBRARIES - the UDEV library
+find_package(PkgConfig)
+
+pkg_check_modules(UDEV_PKGCONF libudev)
+
+find_path(UDEV_INCLUDE_DIRS
+ NAMES libudev.h
+ PATHS ${UDEV_PKGCONF_INCLUDE_DIRS}
+)
+
+
+find_library(UDEV_LIBRARIES
+ NAMES udev
+ PATHS ${UDEV_PKGCONF_LIBRARY_DIRS}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Udev DEFAULT_MSG UDEV_INCLUDE_DIRS UDEV_LIBRARIES)
+
+mark_as_advanced(UDEV_INCLUDE_DIRS UDEV_LIBRARIES)
diff --git a/CMake/FindXXHASH.cmake b/CMake/FindXXHASH.cmake
new file mode 100644
index 0000000..46d6fbd
--- /dev/null
+++ b/CMake/FindXXHASH.cmake
@@ -0,0 +1,25 @@
+# - Try to find XXHASH
+# Once done, this will define
+#
+# XXHASH_FOUND - system has XXHASH
+# XXHASH_INCLUDE_DIRS - the XXHASH include directories
+# XXHASH_LIBRARIES - the XXHASH library
+find_package(PkgConfig)
+
+pkg_check_modules(XXHASH_PKGCONF libxxhash)
+
+find_path(XXHASH_INCLUDE_DIRS
+ NAMES xxhash.h
+ PATHS ${XXHASH_PKGCONF_INCLUDE_DIRS}
+)
+
+
+find_library(XXHASH_LIBRARIES
+ NAMES xxhash
+ PATHS ${XXHASH_PKGCONF_LIBRARY_DIRS}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(XXHASH DEFAULT_MSG XXHASH_INCLUDE_DIRS XXHASH_LIBRARIES)
+
+mark_as_advanced(XXHASH_INCLUDE_DIRS XXHASH_LIBRARIES)
diff --git a/CMake/FindZSTD.cmake b/CMake/FindZSTD.cmake
new file mode 100644
index 0000000..6811804
--- /dev/null
+++ b/CMake/FindZSTD.cmake
@@ -0,0 +1,25 @@
+# - Try to find ZSTD
+# Once done, this will define
+#
+# ZSTD_FOUND - system has ZSTD
+# ZSTD_INCLUDE_DIRS - the ZSTD include directories
+# ZSTD_LIBRARIES - the ZSTD library
+find_package(PkgConfig)
+
+pkg_check_modules(ZSTD_PKGCONF libzstd)
+
+find_path(ZSTD_INCLUDE_DIRS
+ NAMES zstd.h
+ PATHS ${ZSTD_PKGCONF_INCLUDE_DIRS}
+)
+
+
+find_library(ZSTD_LIBRARIES
+ NAMES zstd
+ PATHS ${ZSTD_PKGCONF_LIBRARY_DIRS}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(ZSTD DEFAULT_MSG ZSTD_INCLUDE_DIRS ZSTD_LIBRARIES)
+
+mark_as_advanced(ZSTD_INCLUDE_DIRS ZSTD_LIBRARIES)
diff --git a/CMake/Misc.cmake b/CMake/Misc.cmake
new file mode 100644
index 0000000..8cb18b6
--- /dev/null
+++ b/CMake/Misc.cmake
@@ -0,0 +1,101 @@
+include(CheckCXXCompilerFlag)
+
+# Flatten our header structure
+function(flatify target headers)
+ foreach(header ${headers})
+ get_filename_component(tgt ${header} NAME)
+ configure_file(${header} ${target}/${tgt} COPYONLY)
+ endforeach(header ${headers})
+endfunction()
+
+
+function(add_optional_compile_options flags)
+ foreach(flag ${flags})
+ check_cxx_compiler_flag(-${flag} have-compiler-flag:-${flag})
+ if (have-compiler-flag:-${flag})
+ add_compile_options("-${flag}")
+ endif()
+ endforeach()
+endfunction()
+
+# Substitute vendor references in a file
+function(add_vendor_file)
+ set(options)
+ set(oneValueArgs OUTPUT INPUT MODE)
+ set(multiValueArgs VARIABLES)
+ cmake_parse_arguments(AVF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ set(in ${CMAKE_CURRENT_SOURCE_DIR}/${AVF_INPUT})
+ set(out ${CMAKE_CURRENT_BINARY_DIR}/${AVF_OUTPUT})
+
+ add_custom_command(
+ OUTPUT ${out}
+ COMMAND ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
+ "-DVARS=${AVF_VARIABLES}"
+ -DCURRENT_VENDOR=${CURRENT_VENDOR}
+ -DIN=${in}
+ -DOUT=${out}
+ -P ${PROJECT_SOURCE_DIR}/CMake/vendor_substitute.cmake
+ COMMAND chmod ${AVF_MODE} ${out}
+ DEPENDS ${in}
+ ${PROJECT_SOURCE_DIR}/doc/apt-verbatim.ent
+ ${PROJECT_SOURCE_DIR}/vendor/${CURRENT_VENDOR}/apt-vendor.ent
+ ${PROJECT_SOURCE_DIR}/vendor/getinfo
+ ${PROJECT_SOURCE_DIR}/CMake/vendor_substitute.cmake
+ VERBATIM
+ )
+
+ # Would like to use ${AVF_OUTPUT} as target name, but then ninja gets
+ # cycles.
+ add_custom_target(vendor-${AVF_OUTPUT} ALL DEPENDS ${out})
+endfunction()
+
+# Add symbolic links to a file
+function(add_links directory target)
+ set(link_names "")
+ foreach(link_name ${ARGN})
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${link_name}
+ COMMAND ${CMAKE_COMMAND} -E create_symlink ${target} ${CMAKE_CURRENT_BINARY_DIR}/${link_name})
+ list(APPEND link_names ${CMAKE_CURRENT_BINARY_DIR}/${link_name})
+ endforeach()
+
+ STRING(REPLACE "/" "-" target "${target}")
+ add_custom_target(${target}-link_names ALL DEPENDS ${link_names})
+ install(FILES ${link_names} DESTINATION ${directory})
+endfunction()
+
+# Generates a simple version script versioning everything with current SOVERSION
+function(add_version_script target)
+ get_target_property(soversion ${target} SOVERSION)
+ set(script "${CMAKE_CURRENT_BINARY_DIR}/${target}.versionscript")
+ string(REPLACE "-" "" name "${target}_${soversion}")
+ string(TOUPPER "${name}" name)
+ add_custom_command(OUTPUT "${script}"
+ COMMAND echo "${name} {global: *; };" > "${script}"
+ VERBATIM )
+ add_custom_target(${target}-versionscript DEPENDS "${script}")
+ target_link_libraries(${target} PRIVATE -Wl,-version-script="${script}")
+ add_dependencies(${target} ${target}-versionscript)
+endfunction()
+
+function(path_join out path1 path2)
+ string(SUBSTRING ${path2} 0 1 init_char)
+ if ("${init_char}" STREQUAL "/")
+ set(${out} "${path2}" PARENT_SCOPE)
+ else()
+ set(${out} "${path1}/${path2}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+# install_empty_directories(path ...)
+#
+# Creates empty directories in the install destination dir. Paths may be
+# absolute or relative; in the latter case, the value of CMAKE_INSTALL_PREFIX
+# is prepended.
+function(install_empty_directories)
+ foreach(path ${ARGN})
+ path_join(full_path "${CMAKE_INSTALL_PREFIX}" "${path}")
+ INSTALL(CODE "MESSAGE(STATUS \"Creating directory: \$ENV{DESTDIR}${full_path}\")"
+ CODE "FILE(MAKE_DIRECTORY \$ENV{DESTDIR}${full_path})")
+ endforeach()
+endfunction()
diff --git a/CMake/Translations.cmake b/CMake/Translations.cmake
new file mode 100644
index 0000000..2492510
--- /dev/null
+++ b/CMake/Translations.cmake
@@ -0,0 +1,185 @@
+# translations.cmake - Translations using APT's translation system.
+# Copyright (C) 2009, 2016 Julian Andres Klode <jak@debian.org>
+
+function(apt_add_translation_domain)
+ set(options)
+ set(oneValueArgs DOMAIN)
+ set(multiValueArgs TARGETS SCRIPTS EXCLUDE_LANGUAGES)
+ cmake_parse_arguments(NLS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+ # Build the list of source files of the target
+ set(files "")
+ set(abs_files "")
+ set(scripts "")
+ set(abs_scripts "")
+ set(mofiles)
+ set(targets ${NLS_TARGETS})
+ set(domain ${NLS_DOMAIN})
+ set(xgettext_params
+ --add-comments
+ --foreign
+ --package-name=${PROJECT_NAME}
+ --package-version=${PACKAGE_VERSION}
+ --msgid-bugs-address=${PACKAGE_MAIL}
+ )
+ foreach(source ${NLS_SCRIPTS})
+ path_join(file "${CMAKE_CURRENT_SOURCE_DIR}" "${source}")
+ file(RELATIVE_PATH relfile ${PROJECT_SOURCE_DIR} ${file})
+ list(APPEND scripts ${relfile})
+ list(APPEND abs_scripts ${file})
+ endforeach()
+ foreach(target ${targets})
+ get_target_property(source_dir ${target} SOURCE_DIR)
+ get_target_property(sources ${target} SOURCES)
+ foreach(source ${sources})
+ if (source MATCHES TARGET_OBJECTS)
+ continue()
+ endif()
+ path_join(file "${source_dir}" "${source}")
+ file(RELATIVE_PATH relfile ${PROJECT_SOURCE_DIR} ${file})
+ set(files ${files} ${relfile})
+ set(abs_files ${abs_files} ${file})
+ endforeach()
+
+ target_compile_definitions(${target} PRIVATE -DAPT_DOMAIN="${domain}")
+ endforeach()
+
+ if("${scripts}" STREQUAL "")
+ set(sh_pot "/dev/null")
+ else()
+ set(sh_pot ${CMAKE_CURRENT_BINARY_DIR}/${domain}.sh.pot)
+ # Create the template for this specific sub-domain
+ add_custom_command (OUTPUT ${sh_pot}
+ COMMAND xgettext ${xgettext_params} -L Shell
+ -o ${sh_pot} ${scripts}
+ DEPENDS ${abs_scripts}
+ VERBATIM
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ )
+ endif()
+
+
+ add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
+ COMMAND xgettext ${xgettext_params} -k_ -kN_
+ --keyword=P_:1,2
+ -o ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot ${files}
+ DEPENDS ${abs_files}
+ VERBATIM
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ )
+
+ # We are building a ${domain}.pot with a header for launchpad, but we also
+ # build a ${domain.pot}-tmp as a byproduct. The msgfmt command than depend
+ # on the byproduct while their target depends on the output, so that msgfmt
+ # does not have to be rerun if nothing in the template changed.
+ #
+ # Make sure the .pot-tmp has no line numbers, to avoid useless rebuilding
+ # of .mo files.
+ add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot
+ BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
+ COMMAND msgcomm --more-than=0 --omit-header --sort-by-file --add-location=file
+ ${sh_pot}
+ ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
+ --output=${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp0
+ COMMAND msgcomm --more-than=0 --sort-by-file
+ ${sh_pot}
+ ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
+ --output=${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot
+ COMMAND cmake -E copy_if_different
+ ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp0
+ ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
+ DEPENDS ${sh_pot}
+ ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
+ WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+ )
+
+ # We need a target to depend on otherwise, the msgmerge might not get called
+ # with the make generator
+ add_custom_target(nls-${domain}-template DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot)
+
+ # Build .mo files
+ file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
+ list(SORT translations)
+ foreach(file ${translations})
+ get_filename_component(langcode ${file} NAME_WE)
+ if ("${langcode}" IN_LIST NLS_EXCLUDE_LANGUAGES)
+ continue()
+ endif()
+ set(outdir ${CMAKE_CURRENT_BINARY_DIR}/locale/${langcode}/LC_MESSAGES)
+ file(MAKE_DIRECTORY ${outdir})
+ # Command to merge and compile the messages. As explained in the custom
+ # command for msgcomm, this depends on byproduct to avoid reruns
+ add_custom_command(OUTPUT ${outdir}/${domain}.po
+ COMMAND msgmerge -qo ${outdir}/${domain}.po ${file} ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
+ DEPENDS ${file} ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
+ )
+ add_custom_command(OUTPUT ${outdir}/${domain}.mo
+ COMMAND msgfmt --statistics -o ${outdir}/${domain}.mo ${outdir}/${domain}.po
+ DEPENDS ${outdir}/${domain}.po
+ )
+
+ set(mofiles ${mofiles} ${outdir}/${domain}.mo)
+ install(FILES ${outdir}/${domain}.mo
+ DESTINATION "${CMAKE_INSTALL_LOCALEDIR}/${langcode}/LC_MESSAGES")
+ endforeach(file ${translations})
+
+ add_custom_target(nls-${domain} ALL DEPENDS ${mofiles} nls-${domain}-template)
+endfunction()
+
+# Usage: apt_add_update_po(output domain [domain ...])
+function(apt_add_update_po)
+ set(options)
+ set(oneValueArgs TEMPLATE)
+ set(multiValueArgs DOMAINS EXCLUDE_LANGUAGES)
+ cmake_parse_arguments(NLS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+ set(output ${CMAKE_CURRENT_SOURCE_DIR}/${NLS_TEMPLATE}.pot)
+ foreach(domain ${NLS_DOMAINS})
+ list(APPEND potfiles ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot)
+ endforeach()
+
+ get_filename_component(primary_name ${output} NAME_WE)
+ add_custom_target(nls-${primary_name}
+ COMMAND msgcomm --sort-by-file --add-location=file
+ --more-than=0 --output=${output}
+ ${potfiles}
+ DEPENDS ${potfiles})
+
+ file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
+ if (NOT TARGET update-po)
+ add_custom_target(update-po)
+ endif()
+ foreach(translation ${translations})
+ get_filename_component(langcode ${translation} NAME_WE)
+ if ("${langcode}" IN_LIST NLS_EXCLUDE_LANGUAGES)
+ continue()
+ endif()
+ add_custom_target(update-po-${langcode}
+ COMMAND msgmerge -q --previous --update --backup=none ${translation} ${output}
+ DEPENDS nls-${primary_name}
+ )
+ add_dependencies(update-po update-po-${langcode})
+ endforeach()
+ add_dependencies(update-po nls-${primary_name})
+endfunction()
+
+function(apt_add_po_statistics excluded)
+ add_custom_target(statistics)
+ file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
+ foreach(translation ${translations})
+ get_filename_component(langcode ${translation} NAME_WE)
+ if ("${langcode}" IN_LIST excluded)
+ add_custom_command(
+ TARGET statistics PRE_BUILD
+ COMMAND printf "%-6s " "${langcode}:"
+ COMMAND echo "ignored"
+ VERBATIM
+ )
+ continue()
+ endif()
+ add_custom_command(
+ TARGET statistics PRE_BUILD
+ COMMAND printf "%-6s " "${langcode}:"
+ COMMAND msgfmt --statistics -o /dev/null ${translation}
+ VERBATIM
+ )
+ endforeach()
+endfunction()
diff --git a/CMake/apti18n.h.in b/CMake/apti18n.h.in
new file mode 100644
index 0000000..de9c849
--- /dev/null
+++ b/CMake/apti18n.h.in
@@ -0,0 +1,34 @@
+// -*- mode: cpp; mode: fold -*-
+/* Internationalization macros for apt. This header should be included last
+ in each C file. */
+
+#ifndef APT_I18N_H
+#define APT_I18N_H
+
+// Set by autoconf
+#cmakedefine USE_NLS
+
+#ifdef USE_NLS
+// apt will use the gettext implementation of the C library
+#include <libintl.h>
+#include <locale.h>
+# ifdef APT_DOMAIN
+# define _(x) dgettext(APT_DOMAIN,x)
+# define P_(msg,plural,n) dngettext(APT_DOMAIN,msg,plural,n)
+# else
+# define _(x) gettext(x)
+# define P_(msg,plural,n) ngettext(msg,plural,n)
+# endif
+# define N_(x) x
+#else
+// apt will not use any gettext
+extern "C" inline char* setlocale(int, const char*) throw() { return nullptr; }
+extern "C" inline char* textdomain(const char*) throw() { return nullptr; }
+extern "C" inline char* bindtextdomain(const char*, const char*) throw() { return nullptr; }
+extern "C" inline char* dgettext(const char*, const char* msg) throw() { return const_cast<char*>(msg); }
+# define _(x) x
+# define P_(msg,plural,n) (n == 1 ? msg : plural)
+# define N_(x) x
+#endif
+
+#endif
diff --git a/CMake/config.h.in b/CMake/config.h.in
new file mode 100644
index 0000000..65f983f
--- /dev/null
+++ b/CMake/config.h.in
@@ -0,0 +1,84 @@
+/* Define if your processor stores words with the most significant
+ byte first (like Motorola and SPARC, unlike Intel and VAX). */
+#cmakedefine WORDS_BIGENDIAN
+
+/* Define if we have the timegm() function */
+#cmakedefine HAVE_TIMEGM
+
+/* Define if we have the zlib library for gzip */
+#cmakedefine HAVE_ZLIB
+
+/* Define if we have the bz2 library for bzip2 */
+#cmakedefine HAVE_BZ2
+
+/* Define if we have the lzma library for lzma/xz */
+#cmakedefine HAVE_LZMA
+
+/* Define if we have the lz4 library for lz4 */
+#cmakedefine HAVE_LZ4
+
+/* Define if we have the zstd library for zst */
+#cmakedefine HAVE_ZSTD
+
+/* Define if we have the systemd library */
+#cmakedefine HAVE_SYSTEMD
+
+/* Define if we have the udev library */
+#cmakedefine HAVE_UDEV
+
+/* Define if we have the seccomp library */
+#cmakedefine HAVE_SECCOMP
+
+/* These two are used by the statvfs shim for glibc2.0 and bsd */
+/* Define if we have sys/vfs.h */
+#cmakedefine HAVE_VFS_H
+#cmakedefine HAVE_STRUCT_STATFS_F_TYPE
+
+/* Define if we have sys/mount.h */
+#cmakedefine HAVE_MOUNT_H
+
+/* Define if we have sys/endian.h */
+#cmakedefine HAVE_SYS_ENDIAN_H
+
+/* Define if we have machine/endian.h */
+#cmakedefine HAVE_MACHINE_ENDIAN_H
+
+/* Check for getresuid() function and similar ones */
+#cmakedefine HAVE_GETRESUID
+#cmakedefine HAVE_GETRESGID
+#cmakedefine HAVE_SETRESUID
+#cmakedefine HAVE_SETRESGID
+
+/* Check for ptsname_r() */
+#cmakedefine HAVE_PTSNAME_R
+
+/* Define the arch name string */
+#define COMMON_ARCH "${COMMON_ARCH}"
+
+/* The package name string */
+#define PACKAGE "${PACKAGE}"
+
+/* The version number string */
+#define PACKAGE_VERSION "${PACKAGE_VERSION}"
+
+/* The mail address to reach upstream */
+#define PACKAGE_MAIL "${PACKAGE_MAIL}"
+
+/* Guard for code that should only be emitted when compiling apt */
+#define APT_COMPILING_APT
+
+/* Various directories */
+#cmakedefine CMAKE_INSTALL_FULL_BINDIR "${CMAKE_INSTALL_FULL_BINDIR}"
+#cmakedefine STATE_DIR "${STATE_DIR}"
+#cmakedefine CACHE_DIR "${CACHE_DIR}"
+#cmakedefine LOG_DIR "${LOG_DIR}"
+#cmakedefine CONF_DIR "${CONF_DIR}"
+#cmakedefine LIBEXEC_DIR "${LIBEXEC_DIR}"
+#cmakedefine BIN_DIR "${BIN_DIR}"
+#cmakedefine DPKG_DATADIR "${DPKG_DATADIR}"
+
+/* Group of the root user */
+#cmakedefine ROOT_GROUP "${ROOT_GROUP}"
+
+/* Whether to check for and require merged usr if a usrmerge package is available. */
+#cmakedefine REQUIRE_MERGED_USR
diff --git a/CMake/endian.h.in b/CMake/endian.h.in
new file mode 100644
index 0000000..1d9198c
--- /dev/null
+++ b/CMake/endian.h.in
@@ -0,0 +1,9 @@
+#include <config.h>
+
+#ifdef HAVE_MACHINE_ENDIAN_H
+#include <machine/endian.h>
+#endif
+#ifdef HAVE_SYS_ENDIAN_H
+#include <sys/types.h>
+#include <sys/endian.h>
+#endif
diff --git a/CMake/run_if_exists.sh b/CMake/run_if_exists.sh
new file mode 100755
index 0000000..97edd4c
--- /dev/null
+++ b/CMake/run_if_exists.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+# Small helper for running a command
+out=""
+if [ "$1" = "--stdout" ]; then
+ out="$2"
+ shift 2
+fi
+
+if [ -e "$1" ]; then
+ shift
+ if [ "$out" ]; then
+ exec "$@" > $out
+ else
+ exec "$@"
+ fi
+fi
diff --git a/CMake/statvfs.h.in b/CMake/statvfs.h.in
new file mode 100644
index 0000000..d0ec238
--- /dev/null
+++ b/CMake/statvfs.h.in
@@ -0,0 +1,13 @@
+/* Compatibility for systems with out Single Unix Spec statvfs */
+#include <config.h>
+
+#ifdef HAVE_VFS_H
+#include <sys/vfs.h>
+#endif
+
+#ifdef HAVE_MOUNT_H
+#include <sys/param.h>
+#include <sys/mount.h>
+#endif
+
+#define statvfs statfs
diff --git a/CMake/vendor_substitute.cmake b/CMake/vendor_substitute.cmake
new file mode 100644
index 0000000..71449c9
--- /dev/null
+++ b/CMake/vendor_substitute.cmake
@@ -0,0 +1,8 @@
+file(READ ${IN} input)
+foreach(variable ${VARS})
+ execute_process(COMMAND ${PROJECT_SOURCE_DIR}/vendor/getinfo
+ --vendor ${CURRENT_VENDOR} ${variable}
+ OUTPUT_VARIABLE value OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REPLACE "&${variable};" "${value}" input "${input}")
+endforeach()
+file(WRITE ${OUT} "${input}")