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")
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")
23 # Work around bug in GNUInstallDirs
24 if (EXISTS "/etc/debian_version")
25 set(CMAKE_INSTALL_LIBEXECDIR "lib")
30 include(CheckIncludeFiles)
31 include(CheckFunctionExists)
32 include(CheckStructHasMember)
33 include(GNUInstallDirs)
34 include(TestBigEndian)
36 find_package(LFS REQUIRED)
37 find_package(Iconv REQUIRED)
40 find_package(Intl REQUIRED)
41 link_libraries(${Intl_LIBRARIES})
42 include_directories(${Intl_INCLUDE_DIRS})
45 # Add large file support
46 add_compile_options(${LFS_COMPILE_OPTIONS})
47 add_definitions(${LFS_DEFINITIONS})
48 link_libraries(${LFS_LIBRARIES})
51 set(CMAKE_CXX_STANDARD 11)
52 set(CMAKE_CXX_STANDARD_REQUIRED ON)
53 set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
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)
70 # apt-ftparchive dependencies
71 find_package(BerkeleyDB REQUIRED)
72 if (BERKELEY_DB_FOUND)
77 # apt-transport-https dependencies
78 find_package(CURL REQUIRED)
83 # (De)Compressor libraries
84 find_package(ZLIB REQUIRED)
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()")
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)
119 CHECK_STRUCT_HAS_MEMBER("struct statfs" f_type sys/vfs.h HAVE_STRUCT_STATFS_F_TYPE)
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)
131 add_definitions(-D_WITH_GETLINE=1)
133 if (CMAKE_USE_PTHREADS_INIT)
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)
144 message(FATAL_ERROR "Cannot find endian.h")
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)
156 add_definitions(-Dsighandler_t=sig_t)
158 message(FATAL_ERROR "Platform defines neither sig_t nor sighandler_t")
163 check_function_exists(res_init HAVE_LIBC_RESOLV)
165 set(RESOLV_LIBRARIES)
167 set(RESOLV_LIBRARIES -lresolv)
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~rc4")
175 if (NOT DEFINED COMMON_ARCH)
176 execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH
177 OUTPUT_VARIABLE COMMON_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
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}")
184 set(ROOT_GROUP "${ROOT_GROUP}" CACHE STRING "Group of root (e.g.: wheel or root)")
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}")
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)
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)
215 # Link update-po4a into the update-po target
216 add_dependencies(update-po update-po4a)
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