1 # Copyright (C) 2009, 2016 Julian Andres Klode <jak@debian.org>.
2 # Licensed under the same terms as APT; i.e. GPL 2 or later.
6 cmake_minimum_required(VERSION 3.3.0)
8 option(WITH_DOC "Build documentation." OFF)
9 option(USE_NLS "Localisation support." ON)
11 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake")
13 # Work around bug in GNUInstallDirs
14 if (EXISTS "/etc/debian_version")
15 set(CMAKE_INSTALL_LIBEXECDIR "lib")
21 include(CheckIncludeFiles)
22 include(CheckFunctionExists)
23 include(CheckStructHasMember)
24 include(GNUInstallDirs)
25 include(TestBigEndian)
27 find_package(PkgConfig)
30 set(CMAKE_CXX_STANDARD 11)
31 set(CMAKE_CXX_STANDARD_REQUIRED ON)
32 set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
34 add_optional_compile_options(Wall)
35 add_optional_compile_options(Wextra)
36 add_optional_compile_options(Wcast-align)
37 add_optional_compile_options(Wlogical-op)
38 add_optional_compile_options(Wredundant-decls)
39 add_optional_compile_options(Wmissing-declarations)
40 add_optional_compile_options(Wunsafe-loop-optimizations)
41 add_optional_compile_options(Wctor-dtor-privacy)
42 add_optional_compile_options(Wdisabled-optimization)
43 add_optional_compile_options(Winit-self)
44 add_optional_compile_options(Wmissing-include-dirs)
45 add_optional_compile_options(Wnoexcept)
46 add_optional_compile_options(Wsign-promo)
47 add_optional_compile_options(Wundef)
49 # apt-ftparchive dependencies
50 find_package(BerkeleyDB REQUIRED)
51 if (BERKELEY_DB_FOUND)
56 # apt-transport-https dependencies
57 find_package(CURL REQUIRED)
62 # (De)Compressor libraries
63 find_package(ZLIB REQUIRED)
74 pkg_check_modules(LZMA liblzma)
79 pkg_check_modules(LZ4 liblz4)
84 # Mount()ing and stat()ing and friends
86 check_function_exists(statvfs HAVE_STATVFS)
88 check_symbol_exists(statfs sys/vfs.h HAVE_VFS_H)
89 check_symbol_exists(statfs sys/mount.h HAVE_MOUNT_H)
90 if (NOT HAVE_VFS_H AND NOT HAVE_MOUNT_H)
91 message(FATAL_ERROR "Can find neither statvfs() nor statfs()")
93 configure_file(buildlib/statvfs.h.in ${PROJECT_BINARY_DIR}/include/statvfs.h @ONLY)
96 CHECK_STRUCT_HAS_MEMBER("struct statfs" f_type sys/vfs.h HAVE_STRUCT_STATFS_F_TYPE)
99 check_function_exists(getresuid HAVE_GETRESUID)
100 check_function_exists(getresgid HAVE_GETRESGID)
101 check_function_exists(setresuid HAVE_SETRESUID)
102 check_function_exists(setresgid HAVE_SETRESGID)
103 check_function_exists(timegm HAVE_TIMEGM)
104 test_big_endian(WORDS_BIGENDIAN)
106 if (CMAKE_USE_PTHREADS_INIT)
110 # Configure some variables like package, version and architecture.
113 execute_process(COMMAND dpkg-parsechangelog -SVersion -l${PROJECT_SOURCE_DIR}/debian/changelog
114 OUTPUT_VARIABLE PACKAGE_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
115 execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH
116 OUTPUT_VARIABLE COMMON_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
118 # Configure our configuration headers (config.h and apti18n.h)
119 configure_file(CMake/config.h.in ${PROJECT_BINARY_DIR}/include/config.h)
120 configure_file(CMake/apti18n.h.in ${PROJECT_BINARY_DIR}/include/apti18n.h)
122 # Generic header locations
123 include_directories(${PROJECT_BINARY_DIR}/include)
125 # Add our subdirectories
126 add_subdirectory(vendor)
127 add_subdirectory(apt-pkg)
128 add_subdirectory(apt-private)
129 add_subdirectory(apt-inst)
130 add_subdirectory(cmdline)
131 add_subdirectory(doc)
132 add_subdirectory(dselect)
133 add_subdirectory(ftparchive)
134 add_subdirectory(methods)
136 add_subdirectory(test)