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