]>
Commit | Line | Data |
---|---|---|
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. | |
3 | ||
4 | # set minimum version | |
5 | project(apt) | |
6 | cmake_minimum_required(VERSION 3.4.0) | |
7 | # Generic header locations | |
8 | include_directories(${PROJECT_BINARY_DIR}/include) | |
9 | ||
10 | ||
11 | enable_testing() | |
12 | ||
13 | option(WITH_DOC "Build documentation." ON) | |
14 | option(USE_NLS "Localisation support." ON) | |
15 | ||
16 | set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake") | |
17 | ||
18 | # Add coverage target | |
19 | set(CMAKE_CXX_FLAGS_COVERAGE "-g -fprofile-arcs -ftest-coverage") | |
20 | set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "-lgcov") | |
21 | set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "-lgcov") | |
22 | ||
23 | # Work around bug in GNUInstallDirs | |
24 | if (EXISTS "/etc/debian_version") | |
25 | set(CMAKE_INSTALL_LIBEXECDIR "lib") | |
26 | endif() | |
27 | ||
28 | # Include stuff | |
29 | include(Misc) | |
30 | include(CheckIncludeFiles) | |
31 | include(CheckFunctionExists) | |
32 | include(CheckStructHasMember) | |
33 | include(GNUInstallDirs) | |
34 | include(TestBigEndian) | |
35 | find_package(Threads) | |
36 | find_package(LFS REQUIRED) | |
37 | find_package(Iconv REQUIRED) | |
38 | ||
39 | if(USE_NLS) | |
40 | find_package(Intl REQUIRED) | |
41 | link_libraries(${Intl_LIBRARIES}) | |
42 | include_directories(${Intl_INCLUDE_DIRS}) | |
43 | endif() | |
44 | ||
45 | # Add large file support | |
46 | add_compile_options(${LFS_COMPILE_OPTIONS}) | |
47 | add_definitions(${LFS_DEFINITIONS}) | |
48 | link_libraries(${LFS_LIBRARIES}) | |
49 | ||
50 | # Set compiler flags | |
51 | set(CMAKE_CXX_STANDARD 11) | |
52 | set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
53 | set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) | |
54 | ||
55 | add_optional_compile_options(Wall) | |
56 | add_optional_compile_options(Wextra) | |
57 | add_optional_compile_options(Wcast-align) | |
58 | add_optional_compile_options(Wlogical-op) | |
59 | add_optional_compile_options(Wredundant-decls) | |
60 | add_optional_compile_options(Wmissing-declarations) | |
61 | add_optional_compile_options(Wunsafe-loop-optimizations) | |
62 | add_optional_compile_options(Wctor-dtor-privacy) | |
63 | add_optional_compile_options(Wdisabled-optimization) | |
64 | add_optional_compile_options(Winit-self) | |
65 | add_optional_compile_options(Wmissing-include-dirs) | |
66 | add_optional_compile_options(Wnoexcept) | |
67 | add_optional_compile_options(Wsign-promo) | |
68 | add_optional_compile_options(Wundef) | |
69 | ||
70 | # apt-ftparchive dependencies | |
71 | find_package(BerkeleyDB REQUIRED) | |
72 | if (BERKELEY_DB_FOUND) | |
73 | set(HAVE_BDB 1) | |
74 | endif() | |
75 | ||
76 | ||
77 | # apt-transport-https dependencies | |
78 | find_package(CURL REQUIRED) | |
79 | if (CURL_FOUND) | |
80 | set(HAVE_CURL 1) | |
81 | endif() | |
82 | ||
83 | # (De)Compressor libraries | |
84 | find_package(ZLIB REQUIRED) | |
85 | if (ZLIB_FOUND) | |
86 | set(HAVE_ZLIB 1) | |
87 | endif() | |
88 | ||
89 | ||
90 | find_package(BZip2) | |
91 | if (BZIP2_FOUND) | |
92 | set(HAVE_BZ2 1) | |
93 | endif() | |
94 | ||
95 | find_package(LZMA) | |
96 | if (LZMA_FOUND) | |
97 | set(HAVE_LZMA 1) | |
98 | endif() | |
99 | ||
100 | ||
101 | find_package(LZ4) | |
102 | if (LZ4_FOUND) | |
103 | set(HAVE_LZ4 1) | |
104 | endif() | |
105 | ||
106 | # Mount()ing and stat()ing and friends | |
107 | check_symbol_exists(statfs sys/vfs.h HAVE_VFS_H) | |
108 | check_include_files(sys/params.h HAVE_PARAMS_H) | |
109 | check_symbol_exists(statfs sys/mount.h HAVE_MOUNT_H) | |
110 | if (NOT HAVE_VFS_H AND NOT HAVE_MOUNT_H) | |
111 | message(FATAL_ERROR "Can find neither statvfs() nor statfs()") | |
112 | endif() | |
113 | ||
114 | check_function_exists(statvfs HAVE_STATVFS) | |
115 | if (NOT HAVE_STATVFS) | |
116 | configure_file(CMake/statvfs.h.in ${PROJECT_BINARY_DIR}/include/statvfs.h COPYONLY) | |
117 | endif() | |
118 | ||
119 | CHECK_STRUCT_HAS_MEMBER("struct statfs" f_type sys/vfs.h HAVE_STRUCT_STATFS_F_TYPE) | |
120 | ||
121 | # Other checks | |
122 | check_function_exists(getresuid HAVE_GETRESUID) | |
123 | check_function_exists(getresgid HAVE_GETRESGID) | |
124 | check_function_exists(setresuid HAVE_SETRESUID) | |
125 | check_function_exists(setresgid HAVE_SETRESGID) | |
126 | check_function_exists(ptsname_r HAVE_PTSNAME_R) | |
127 | check_function_exists(timegm HAVE_TIMEGM) | |
128 | test_big_endian(WORDS_BIGENDIAN) | |
129 | ||
130 | # FreeBSD | |
131 | add_definitions(-D_WITH_GETLINE=1) | |
132 | ||
133 | if (CMAKE_USE_PTHREADS_INIT) | |
134 | set(HAVE_PTHREAD 1) | |
135 | endif() | |
136 | ||
137 | CHECK_INCLUDE_FILES(machine/endian.h HAVE_MACHINE_ENDIAN_H) | |
138 | CHECK_INCLUDE_FILES(sys/endian.h HAVE_SYS_ENDIAN_H) | |
139 | CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H) | |
140 | if (NOT HAVE_ENDIAN_H) | |
141 | if (HAVE_MACHINE_ENDIAN_H OR HAVE_SYS_ENDIAN_H) | |
142 | configure_file(CMake/endian.h.in ${PROJECT_BINARY_DIR}/include/endian.h) | |
143 | else() | |
144 | message(FATAL_ERROR "Cannot find endian.h") | |
145 | endif() | |
146 | endif() | |
147 | ||
148 | ||
149 | include(CheckTypeSize) | |
150 | set(CMAKE_EXTRA_INCLUDE_FILES "signal.h") | |
151 | check_type_size("sig_t" SIG_T LANGUAGE "CXX") | |
152 | check_type_size("sighandler_t" SIGHANDLER_T LANGUAGE "CXX") | |
153 | set(CMAKE_EXTRA_INCLUDE_FILES) | |
154 | if (NOT HAVE_SIGHANDLER_T) | |
155 | if (HAVE_SIG_T) | |
156 | add_definitions(-Dsighandler_t=sig_t) | |
157 | else() | |
158 | message(FATAL_ERROR "Platform defines neither sig_t nor sighandler_t") | |
159 | endif() | |
160 | endif() | |
161 | ||
162 | # Handle resolving | |
163 | check_function_exists(res_init HAVE_LIBC_RESOLV) | |
164 | if(HAVE_LIBC_RESOLV) | |
165 | set(RESOLV_LIBRARIES) | |
166 | else() | |
167 | set(RESOLV_LIBRARIES -lresolv) | |
168 | endif() | |
169 | ||
170 | # Configure some variables like package, version and architecture. | |
171 | set(PACKAGE ${PROJECT_NAME}) | |
172 | set(PACKAGE_MAIL "APT Development Team <deity@lists.debian.org>") | |
173 | set(PACKAGE_VERSION "1.3.1") | |
174 | ||
175 | if (NOT DEFINED COMMON_ARCH) | |
176 | execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH | |
177 | OUTPUT_VARIABLE COMMON_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE) | |
178 | endif() | |
179 | if (NOT DEFINED ROOT_GROUP) | |
180 | execute_process(COMMAND id -gn root | |
181 | OUTPUT_VARIABLE ROOT_GROUP OUTPUT_STRIP_TRAILING_WHITESPACE) | |
182 | message(STATUS "Found root group: ${ROOT_GROUP}") | |
183 | endif() | |
184 | set(ROOT_GROUP "${ROOT_GROUP}" CACHE STRING "Group of root (e.g.: wheel or root)") | |
185 | ||
186 | # Set various directories | |
187 | set(STATE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt" CACHE PATH "Your /var/lib/apt") | |
188 | set(CACHE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/apt" CACHE PATH "Your /var/cache/apt") | |
189 | set(LOG_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/apt" CACHE PATH "Your /var/log/apt") | |
190 | set(CONF_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt" CACHE PATH "Your /etc/apt") | |
191 | set(LIBEXEC_DIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/apt" CACHE PATH "Your /usr/libexec/apt") | |
192 | set(BIN_DIR "${CMAKE_INSTALL_FULL_BINDIR}") | |
193 | ||
194 | ||
195 | # Configure our configuration headers (config.h and apti18n.h) | |
196 | configure_file(CMake/config.h.in ${PROJECT_BINARY_DIR}/include/config.h) | |
197 | configure_file(CMake/apti18n.h.in ${PROJECT_BINARY_DIR}/include/apti18n.h) | |
198 | ||
199 | # Add our subdirectories | |
200 | add_subdirectory(vendor) | |
201 | add_subdirectory(apt-pkg) | |
202 | add_subdirectory(apt-private) | |
203 | add_subdirectory(apt-inst) | |
204 | add_subdirectory(cmdline) | |
205 | add_subdirectory(completions) | |
206 | add_subdirectory(doc) | |
207 | add_subdirectory(dselect) | |
208 | add_subdirectory(ftparchive) | |
209 | add_subdirectory(methods) | |
210 | add_subdirectory(test) | |
211 | ||
212 | if (USE_NLS) | |
213 | add_subdirectory(po) | |
214 | ||
215 | # Link update-po4a into the update-po target | |
216 | add_dependencies(update-po update-po4a) | |
217 | endif() | |
218 | ||
219 | # Create our directories. | |
220 | install_empty_directories( | |
221 | ${CONF_DIR}/apt.conf.d | |
222 | ${CONF_DIR}/preferences.d | |
223 | ${CONF_DIR}/sources.list.d | |
224 | ${CONF_DIR}/trusted.gpg.d | |
225 | ${CACHE_DIR}/archives/partial | |
226 | ${STATE_DIR}/lists/partial | |
227 | ${STATE_DIR}/mirrors/partial | |
228 | ${STATE_DIR}/periodic | |
229 | ${LOG_DIR} | |
230 | ) |