summaryrefslogtreecommitdiff
path: root/CMake
diff options
context:
space:
mode:
Diffstat (limited to 'CMake')
-rw-r--r--CMake/Documentation.cmake285
-rw-r--r--CMake/FindBerkeleyDB.cmake48
-rw-r--r--CMake/Misc.cmake88
-rw-r--r--CMake/Translations.cmake178
-rw-r--r--CMake/apti18n.h.in30
-rw-r--r--CMake/config.h.in57
-rwxr-xr-xCMake/run_if_exists.sh16
-rw-r--r--CMake/statvfs.h.in13
-rw-r--r--CMake/vendor_substitute.cmake8
9 files changed, 723 insertions, 0 deletions
diff --git a/CMake/Documentation.cmake b/CMake/Documentation.cmake
new file mode 100644
index 000000000..9e7135ea4
--- /dev/null
+++ b/CMake/Documentation.cmake
@@ -0,0 +1,285 @@
+# 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.
+
+
+# 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}")
+ po4a_components(document _ section ext "${full_document}")
+
+ # Calculate target file name
+ set(dest "${language}/${document}.${language}")
+ if(section)
+ set(dest "${dest}.${section}")
+ 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}-doc'
+ --package-version='${PACKAGE_VERSION}'
+ --msgid-bugs-address='${PACKAGE_MAIL}'
+ --translate-only ${dest}.${ext}
+ --srcdir ${CMAKE_CURRENT_SOURCE_DIR}
+ --destdir ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/po4a.conf
+ COMMAND ${CMAKE_COMMAND} -E touch ${stamp}
+ COMMENT "Generating ${dest}.${ext} (or dropping it)"
+ DEPENDS ${full_document} ${deps} po/${language}.po
+ )
+ # Return result
+ set(${stamp_out} ${stamp} PARENT_SCOPE)
+ set(${out} ${CMAKE_CURRENT_BINARY_DIR}/${dest}.${ext} 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_SOURCE_DIR}/manpage-style.xsl")
+
+ 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_SOURCE_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_SOURCE_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(multiValueArgs INSTALL DOCUMENTS LINGUAS 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})
+ 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}
+ ${formats})
+
+ list(APPEND stamps ${xslt_stamp})
+ endforeach()
+ xsltproc_one(STAMP_OUT xslt_stamp
+ STAMP ${document}
+ FULL_DOCUMENT ${document}
+ INSTALL ${DOC_INSTALL}
+ ${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 noline,wrap
+ --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/FindBerkeleyDB.cmake b/CMake/FindBerkeleyDB.cmake
new file mode 100644
index 000000000..44cfd3ddb
--- /dev/null
+++ b/CMake/FindBerkeleyDB.cmake
@@ -0,0 +1,48 @@
+# - Try to find Berkeley DB
+# Once done this will define
+#
+# BERKELEY_DB_FOUND - system has Berkeley DB
+# BERKELEY_DB_INCLUDE_DIRS - the Berkeley DB include directory
+# BERKELEY_DB_LIBRARIES - Link these to use Berkeley DB
+# BERKELEY_DB_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.
+
+
+find_path(BERKELEY_DB_INCLUDE_DIRS db.h
+ /usr/include/db5
+ /usr/local/include/db5
+ /usr/include/db4
+ /usr/local/include/db4
+)
+
+find_library(BERKELEY_DB_LIBRARIES NAMES db )
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Berkeley "Could not find Berkeley DB >= 4.1" BERKELEY_DB_INCLUDE_DIRS BERKELEY_DB_LIBRARIES)
+# show the BERKELEY_DB_INCLUDE_DIRS and BERKELEY_DB_LIBRARIES variables only in the advanced view
+mark_as_advanced(BERKELEY_DB_INCLUDE_DIRS BERKELEY_DB_LIBRARIES)
diff --git a/CMake/Misc.cmake b/CMake/Misc.cmake
new file mode 100644
index 000000000..79587b068
--- /dev/null
+++ b/CMake/Misc.cmake
@@ -0,0 +1,88 @@
+include(CheckCXXCompilerFlag)
+
+# Flatten our header structure
+function(flatify target headers)
+ foreach(header ${headers})
+ get_filename_component(tgt ${header} NAME)
+ configure_file(${header} ${target}/${tgt} @ONLY)
+ 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
+ )
+
+ # Woud 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_slaves destination master)
+ set(slaves "")
+ foreach(slave ${ARGN})
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${slave}
+ COMMAND ${CMAKE_COMMAND} -E create_symlink ${master} ${CMAKE_CURRENT_BINARY_DIR}/${slave})
+ list(APPEND slaves ${CMAKE_CURRENT_BINARY_DIR}/${slave})
+ endforeach()
+
+ STRING(REPLACE "/" "-" master "${master}")
+ add_custom_target(${master}-slaves ALL DEPENDS ${slaves})
+ install(FILES ${slaves} DESTINATION ${destination})
+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()
diff --git a/CMake/Translations.cmake b/CMake/Translations.cmake
new file mode 100644
index 000000000..509e4e378
--- /dev/null
+++ b/CMake/Translations.cmake
@@ -0,0 +1,178 @@
+# 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(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})
+ 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.
+ add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot
+ BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
+ 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 msgcomm --more-than=0 --omit-header --sort-by-file
+ ${sh_pot}
+ ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
+ --output=${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp0
+ 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(master_name ${output} NAME_WE)
+ add_custom_target(nls-${master_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 --update --backup=none ${translation} ${output}
+ DEPENDS nls-${master_name}
+ )
+ add_dependencies(update-po update-po-${langcode})
+ endforeach()
+ add_dependencies(update-po nls-${master_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 000000000..9c843b037
--- /dev/null
+++ b/CMake/apti18n.h.in
@@ -0,0 +1,30 @@
+// -*- mode: cpp; mode: fold -*-
+// $Id: apti18n.h.in,v 1.6 2003/01/11 07:18:18 jgg Exp $
+/* Internationalization macros for apt. This header should be included last
+ in each C file. */
+
+// 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
+# define setlocale(a, b)
+# define textdomain(a)
+# define bindtextdomain(a, b)
+# define _(x) x
+# define P_(msg,plural,n) (n == 1 ? msg : plural)
+# define N_(x) x
+# define dgettext(d, m) m
+#endif
diff --git a/CMake/config.h.in b/CMake/config.h.in
new file mode 100644
index 000000000..e929646fa
--- /dev/null
+++ b/CMake/config.h.in
@@ -0,0 +1,57 @@
+/* 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
+
+/* 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 enabled pthread support */
+#cmakedefine HAVE_PTHREAD
+
+/* 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}"
+
+#define APT_8_CLEANER_HEADERS
+#define APT_9_CLEANER_HEADERS
+#define APT_10_CLEANER_HEADERS
+
+/* unrolling is faster combined with an optimizing compiler */
+#define SHA2_UNROLL_TRANSFORM
diff --git a/CMake/run_if_exists.sh b/CMake/run_if_exists.sh
new file mode 100755
index 000000000..97edd4c1a
--- /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 000000000..d0ec238ad
--- /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 000000000..71449c9e8
--- /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}")