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.4.0)
10 option(WITH_DOC "Build documentation." ON)
11 option(USE_NLS "Localisation support." ON)
13 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake")
15 # Work around bug in GNUInstallDirs
16 if (EXISTS "/etc/debian_version")
17 set(CMAKE_INSTALL_LIBEXECDIR "lib")
22 include(CheckIncludeFiles)
23 include(CheckFunctionExists)
24 include(CheckStructHasMember)
25 include(GNUInstallDirs)
26 include(TestBigEndian)
28 find_package(PkgConfig)
29 find_package(LFS REQUIRED)
31 # Add large file support
32 add_compile_options(${LFS_COMPILE_OPTIONS})
33 add_definitions(${LFS_DEFINITIONS})
34 link_libraries(${LFS_LIBRARIES})
37 set(CMAKE_CXX_STANDARD 11)
38 set(CMAKE_CXX_STANDARD_REQUIRED ON)
39 set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
41 add_optional_compile_options(Wall)
42 add_optional_compile_options(Wextra)
43 add_optional_compile_options(Wcast-align)
44 add_optional_compile_options(Wlogical-op)
45 add_optional_compile_options(Wredundant-decls)
46 add_optional_compile_options(Wmissing-declarations)
47 add_optional_compile_options(Wunsafe-loop-optimizations)
48 add_optional_compile_options(Wctor-dtor-privacy)
49 add_optional_compile_options(Wdisabled-optimization)
50 add_optional_compile_options(Winit-self)
51 add_optional_compile_options(Wmissing-include-dirs)
52 add_optional_compile_options(Wnoexcept)
53 add_optional_compile_options(Wsign-promo)
54 add_optional_compile_options(Wundef)
56 # apt-ftparchive dependencies
57 find_package(BerkeleyDB REQUIRED)
58 if (BERKELEY_DB_FOUND)
63 # apt-transport-https dependencies
64 find_package(CURL REQUIRED)
69 # (De)Compressor libraries
70 find_package(ZLIB REQUIRED)
81 pkg_check_modules(LZMA liblzma)
86 pkg_check_modules(LZ4 liblz4)
91 # Mount()ing and stat()ing and friends
93 check_function_exists(statvfs HAVE_STATVFS)
95 check_symbol_exists(statfs sys/vfs.h HAVE_VFS_H)
96 check_symbol_exists(statfs sys/mount.h HAVE_MOUNT_H)
97 if (NOT HAVE_VFS_H AND NOT HAVE_MOUNT_H)
98 message(FATAL_ERROR "Can find neither statvfs() nor statfs()")
100 configure_file(CMake/statvfs.h.in ${PROJECT_BINARY_DIR}/include/statvfs.h COPYONLY)
103 CHECK_STRUCT_HAS_MEMBER("struct statfs" f_type sys/vfs.h HAVE_STRUCT_STATFS_F_TYPE)
106 check_function_exists(getresuid HAVE_GETRESUID)
107 check_function_exists(getresgid HAVE_GETRESGID)
108 check_function_exists(setresuid HAVE_SETRESUID)
109 check_function_exists(setresgid HAVE_SETRESGID)
110 check_function_exists(ptsname_r HAVE_PTSNAME_R)
111 check_function_exists(timegm HAVE_TIMEGM)
112 test_big_endian(WORDS_BIGENDIAN)
115 add_definitions(-D_WITH_GETLINE=1)
117 if (CMAKE_USE_PTHREADS_INIT)
121 CHECK_INCLUDE_FILES(machine/endian.h HAVE_MACHINE_ENDIAN_H)
122 CHECK_INCLUDE_FILES(sys/endian.h HAVE_SYS_ENDIAN_H)
123 CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H)
124 if (NOT HAVE_ENDIAN_H)
125 if (HAVE_MACHINE_ENDIAN_H OR HAVE_SYS_ENDIAN_H)
126 configure_file(CMake/endian.h.in ${PROJECT_BINARY_DIR}/include/endian.h)
128 message(FATAL_ERROR "Cannot find endian.h")
133 include(CheckTypeSize)
134 set(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
135 check_type_size("sig_t" SIG_T LANGUAGE "CXX")
136 check_type_size("sighandler_t" SIGHANDLER_T LANGUAGE "CXX")
137 set(CMAKE_EXTRA_INCLUDE_FILES)
138 if (NOT HAVE_SIGHANDLER_T)
140 add_definitions(-Dsighandler_t=sig_t)
142 message(FATAL_ERROR "Platform defines neither sig_t nor sighandler_t")
146 # Configure some variables like package, version and architecture.
147 set(PACKAGE ${PROJECT_NAME})
148 set(PACKAGE_MAIL "APT Development Team <deity@lists.debian.org>")
149 set(PACKAGE_VERSION "1.3~rc2")
151 if (NOT DEFINED COMMON_ARCH)
152 execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH
153 OUTPUT_VARIABLE COMMON_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
156 # Configure our configuration headers (config.h and apti18n.h)
157 configure_file(CMake/config.h.in ${PROJECT_BINARY_DIR}/include/config.h)
158 configure_file(CMake/apti18n.h.in ${PROJECT_BINARY_DIR}/include/apti18n.h)
160 # Generic header locations
161 include_directories(${PROJECT_BINARY_DIR}/include)
163 # Add our subdirectories
164 add_subdirectory(vendor)
165 add_subdirectory(apt-pkg)
166 add_subdirectory(apt-private)
167 add_subdirectory(apt-inst)
168 add_subdirectory(cmdline)
169 add_subdirectory(completions)
170 add_subdirectory(doc)
171 add_subdirectory(dselect)
172 add_subdirectory(ftparchive)
173 add_subdirectory(methods)
174 add_subdirectory(test)
179 # Link update-po4a into the update-po target
180 add_dependencies(update-po update-po4a)
183 # Create our directories.
184 install_empty_directories(
185 ${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt/apt.conf.d
186 ${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt/preferences.d
187 ${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt/sources.list.d
188 ${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt/trusted.gpg.d
189 ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/apt/archives/partial
190 ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt/lists/partial
191 ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt/mirrors/partial
192 ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt/periodic
193 ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/apt