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)
32 find_package(Iconv REQUIRED)
35 find_package(Intl REQUIRED)
36 link_libraries(${Intl_LIBRARIES})
37 include_directories(${Intl_INCLUDE_DIRS})
40 # Add large file support
41 add_compile_options(${LFS_COMPILE_OPTIONS})
42 add_definitions(${LFS_DEFINITIONS})
43 link_libraries(${LFS_LIBRARIES})
46 set(CMAKE_CXX_STANDARD 11)
47 set(CMAKE_CXX_STANDARD_REQUIRED ON)
48 set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
50 add_optional_compile_options(Wall)
51 add_optional_compile_options(Wextra)
52 add_optional_compile_options(Wcast-align)
53 add_optional_compile_options(Wlogical-op)
54 add_optional_compile_options(Wredundant-decls)
55 add_optional_compile_options(Wmissing-declarations)
56 add_optional_compile_options(Wunsafe-loop-optimizations)
57 add_optional_compile_options(Wctor-dtor-privacy)
58 add_optional_compile_options(Wdisabled-optimization)
59 add_optional_compile_options(Winit-self)
60 add_optional_compile_options(Wmissing-include-dirs)
61 add_optional_compile_options(Wnoexcept)
62 add_optional_compile_options(Wsign-promo)
63 add_optional_compile_options(Wundef)
65 # apt-ftparchive dependencies
66 find_package(BerkeleyDB REQUIRED)
67 if (BERKELEY_DB_FOUND)
72 # apt-transport-https dependencies
73 find_package(CURL REQUIRED)
78 # (De)Compressor libraries
79 find_package(ZLIB REQUIRED)
101 # Mount()ing and stat()ing and friends
102 check_symbol_exists(statfs sys/vfs.h HAVE_VFS_H)
103 check_include_files(sys/params.h HAVE_PARAMS_H)
104 check_symbol_exists(statfs sys/mount.h HAVE_MOUNT_H)
105 if (NOT HAVE_VFS_H AND NOT HAVE_MOUNT_H)
106 message(FATAL_ERROR "Can find neither statvfs() nor statfs()")
109 check_function_exists(statvfs HAVE_STATVFS)
110 if (NOT HAVE_STATVFS)
111 configure_file(CMake/statvfs.h.in ${PROJECT_BINARY_DIR}/include/statvfs.h COPYONLY)
114 CHECK_STRUCT_HAS_MEMBER("struct statfs" f_type sys/vfs.h HAVE_STRUCT_STATFS_F_TYPE)
117 check_function_exists(getresuid HAVE_GETRESUID)
118 check_function_exists(getresgid HAVE_GETRESGID)
119 check_function_exists(setresuid HAVE_SETRESUID)
120 check_function_exists(setresgid HAVE_SETRESGID)
121 check_function_exists(ptsname_r HAVE_PTSNAME_R)
122 check_function_exists(timegm HAVE_TIMEGM)
123 test_big_endian(WORDS_BIGENDIAN)
126 add_definitions(-D_WITH_GETLINE=1)
128 if (CMAKE_USE_PTHREADS_INIT)
132 CHECK_INCLUDE_FILES(machine/endian.h HAVE_MACHINE_ENDIAN_H)
133 CHECK_INCLUDE_FILES(sys/endian.h HAVE_SYS_ENDIAN_H)
134 CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H)
135 if (NOT HAVE_ENDIAN_H)
136 if (HAVE_MACHINE_ENDIAN_H OR HAVE_SYS_ENDIAN_H)
137 configure_file(CMake/endian.h.in ${PROJECT_BINARY_DIR}/include/endian.h)
139 message(FATAL_ERROR "Cannot find endian.h")
144 include(CheckTypeSize)
145 set(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
146 check_type_size("sig_t" SIG_T LANGUAGE "CXX")
147 check_type_size("sighandler_t" SIGHANDLER_T LANGUAGE "CXX")
148 set(CMAKE_EXTRA_INCLUDE_FILES)
149 if (NOT HAVE_SIGHANDLER_T)
151 add_definitions(-Dsighandler_t=sig_t)
153 message(FATAL_ERROR "Platform defines neither sig_t nor sighandler_t")
158 check_function_exists(res_init HAVE_LIBC_RESOLV)
160 set(RESOLV_LIBRARIES)
162 set(RESOLV_LIBRARIES -lresolv)
165 # Configure some variables like package, version and architecture.
166 set(PACKAGE ${PROJECT_NAME})
167 set(PACKAGE_MAIL "APT Development Team <deity@lists.debian.org>")
168 set(PACKAGE_VERSION "1.3~rc2")
170 if (NOT DEFINED COMMON_ARCH)
171 execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH
172 OUTPUT_VARIABLE COMMON_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
174 if (NOT DEFINED ROOT_GROUP)
175 execute_process(COMMAND id -gn root
176 OUTPUT_VARIABLE ROOT_GROUP OUTPUT_STRIP_TRAILING_WHITESPACE)
177 message(STATUS "Found root group: ${ROOT_GROUP}")
179 set(ROOT_GROUP "${ROOT_GROUP}" CACHE STRING "Group of root (e.g.: wheel or root)")
181 # Set various directories
182 set(STATE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt" CACHE PATH "Your /var/lib/apt")
183 set(CACHE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/apt" CACHE PATH "Your /var/cache/apt")
184 set(LOG_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/apt" CACHE PATH "Your /var/log/apt")
185 set(CONF_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt" CACHE PATH "Your /etc/apt")
186 set(LIBEXEC_DIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/apt" CACHE PATH "Your /usr/libexec/apt")
187 set(BIN_DIR "${CMAKE_INSTALL_FULL_BINDIR}")
190 # Configure our configuration headers (config.h and apti18n.h)
191 configure_file(CMake/config.h.in ${PROJECT_BINARY_DIR}/include/config.h)
192 configure_file(CMake/apti18n.h.in ${PROJECT_BINARY_DIR}/include/apti18n.h)
194 # Add our subdirectories
195 add_subdirectory(vendor)
196 add_subdirectory(apt-pkg)
197 add_subdirectory(apt-private)
198 add_subdirectory(apt-inst)
199 add_subdirectory(cmdline)
200 add_subdirectory(completions)
201 add_subdirectory(doc)
202 add_subdirectory(dselect)
203 add_subdirectory(ftparchive)
204 add_subdirectory(methods)
205 add_subdirectory(test)
210 # Link update-po4a into the update-po target
211 add_dependencies(update-po update-po4a)
214 # Create our directories.
215 install_empty_directories(
216 ${CONF_DIR}/apt.conf.d
217 ${CONF_DIR}/preferences.d
218 ${CONF_DIR}/sources.list.d
219 ${CONF_DIR}/trusted.gpg.d
220 ${CACHE_DIR}/archives/partial
221 ${STATE_DIR}/lists/partial
222 ${STATE_DIR}/mirrors/partial
223 ${STATE_DIR}/periodic