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)
7 # Generic header locations
8 include_directories(${PROJECT_BINARY_DIR}/include)
13 option(WITH_DOC "Build documentation." ON)
14 option(USE_NLS "Localisation support." ON)
16 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake")
18 # Work around bug in GNUInstallDirs
19 if (EXISTS "/etc/debian_version")
20 set(CMAKE_INSTALL_LIBEXECDIR "lib")
25 include(CheckIncludeFiles)
26 include(CheckFunctionExists)
27 include(CheckStructHasMember)
28 include(GNUInstallDirs)
29 include(TestBigEndian)
31 find_package(LFS REQUIRED)
34 find_package(Intl REQUIRED)
35 link_libraries(${Intl_LIBRARIES})
36 include_directories(${Intl_INCLUDE_DIRS})
39 # Add large file support
40 add_compile_options(${LFS_COMPILE_OPTIONS})
41 add_definitions(${LFS_DEFINITIONS})
42 link_libraries(${LFS_LIBRARIES})
45 set(CMAKE_CXX_STANDARD 11)
46 set(CMAKE_CXX_STANDARD_REQUIRED ON)
47 set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
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)
64 # apt-ftparchive dependencies
65 find_package(BerkeleyDB REQUIRED)
66 if (BERKELEY_DB_FOUND)
71 # apt-transport-https dependencies
72 find_package(CURL REQUIRED)
77 # (De)Compressor libraries
78 find_package(ZLIB REQUIRED)
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()")
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)
113 CHECK_STRUCT_HAS_MEMBER("struct statfs" f_type sys/vfs.h HAVE_STRUCT_STATFS_F_TYPE)
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)
125 add_definitions(-D_WITH_GETLINE=1)
127 if (CMAKE_USE_PTHREADS_INIT)
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)
138 message(FATAL_ERROR "Cannot find endian.h")
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)
150 add_definitions(-Dsighandler_t=sig_t)
152 message(FATAL_ERROR "Platform defines neither sig_t nor sighandler_t")
157 check_function_exists(res_init HAVE_LIBC_RESOLV)
159 set(RESOLV_LIBRARIES)
161 set(RESOLV_LIBRARIES -lresolv)
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")
169 if (NOT DEFINED COMMON_ARCH)
170 execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH
171 OUTPUT_VARIABLE COMMON_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
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}")
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)
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)
203 # Link update-po4a into the update-po target
204 add_dependencies(update-po update-po4a)
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