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